How to get assetid from a single SRC20 contract without knowing the subid?

How do we get an assetId from a different contract that uses a particular SRC20?

Contract A has token A and B. How do I get token A or token B? Similar to IERC20(tokena).balanceOf(ContractA).

Do we need to know their subId? When can we use the default subId?

It is confusing where in SRC6 Example it uses, new:

/// Returns the vault shares assetid for the given assets assetid and the vaults sub id
fn vault_assetid() -> AssetId {
    let share_asset_id = AssetId::new(ContractId::this(), PRE_CALCULATED_SHARE_VAULT_SUB_ID);
    share_asset_id
}

While in other pages of the documentation from is used to get assetId? In the case where the b256 value of an asset is already known, you may call the from() function with the b256 value.

let asset_id: AssetId = AssetId::from(0x0000000000000000000000000000000000000000000000000000000000000000);

Side Question:
Should we replace PRE_CALCULATED_SHARE_VAULT_SUB_ID with any SubID such as b256 = Bytes32::zeroed();?

1 Like

Hey @eesheng, you can use AssetId::new() when you know the contract ID and the sub-ID, and want to use those to calculate the Asset ID. If you already know the Asset ID, you can pass it to AssetId::from().

2 Likes

Hi @david I think this was overlooked. Do we need to take precautions about the SubID for Single Vault?
Should we replace PRE_CALCULATED_SHARE_VAULT_SUB_ID with any SubID such as b256 = Bytes32::zeroed(); ?