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.
use std::{call_frames::msg_asset_id, constants::BASE_ASSET_ID};
We can check which asset has been sent and perform different computation based on the type.
fn deposit() {
if msg_asset_id() == BASE_ASSET_ID {
// code
} else {
// code
}
}