Back to Sway

Amount of Asset Sent

docs/reference/src/documentation/operations/call-data/msg-asset-amount.md

0.71.0765 B
Original Source

Amount of Asset Sent

The standard library provides a function msg_amount() which retrieves the amount of asset sent without any concern for which asset is sent.

This can be used to set a price or manually track the amount sent by each user.

Example

To use msg_amount() we must import it from the standard library.

sway
{{#include ../../../code/operations/call_data/src/lib.sw:import_amount}}

We can check how much of any asset has been sent and if an incorrect amount has been sent then we may revert.

sway
{{#include ../../../code/operations/call_data/src/lib.sw:deposit_amount}}