An Asset ID can be represented using the AssetId
type. It's definition matches the Sway standard library type being a Struct
wrapper around an inner Bits256
value.
// #import { AssetId };
const assetId : AssetId = {
value : Bits256,
};
Icon ClipboardText
The AssetId
type can be integrated with your contract calls. Consider the following contract that can compares and return an Asset ID:
contract;
abi EvmTest {
fn echo_asset_id () -> AssetId ;
fn echo_asset_id_comparison (asset_id : AssetId ) -> bool ;
}
const ASSET_ID : AssetId = AssetId {
value : 0x9ae5b658754e096e4d681c548daf46354495a437cc61492599e33fc64dcdc30c ,
};
impl EvmTest for Contract {
fn echo_asset_id () -> AssetId {
ASSET_ID
}
fn echo_asset_id_comparison (asset_id : AssetId ) -> bool {
asset_id == ASSET_ID
}
}
Icon ClipboardText
The AssetId
type can be used with the SDK and passed to the contract function as follows:
// #import { AssetId };
const assetId : AssetId = {
value : Bits256,
};
const { value } = await contract.functions. echo_asset_id_comparison (assetId). simulate ();
expect (value). toBeTruthy ();
Icon ClipboardText
And to validate the returned value:
// #import { AssetId };
const assetId : AssetId = {
value : Bits256,
};
const { value } = await contract.functions. echo_asset_id (). simulate ();
expect (value). toEqual (assetId);
Icon ClipboardText