Back to Sway

Asset Sent

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

0.71.0764 B
Original Source

Asset Sent

The standard library provides a function msg_asset_id() which retrieves the ContractId of the asset being sent.

This can be used to determine which asset has been sent into the contract.

Example

To use msg_asset_id() we must import it from the standard library. We'll also import the base asset for comparison.

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

We can check which asset has been sent and perform different computation based on the type.

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