Contract_id relation with Asset_id

If I have the contract_id of the contract that minted a particular asset (associated with an Asset ID), how can I verify whether that specific contract_id minted the given Asset ID?

This issue could be resolved if there was a method to derive the contract_id of the minter contract directly from the Asset ID.

Could you please guide me on how to achieve this?

P.S.: I need the contract_id to call the SRC20 ABI functions.

#[storage(read, write), payable]
    fn list_nft(nft_contract_id: ContractId, asset_id: AssetId, price: u64, quantity: u64, standard: NFTStandard) {
        let sender = msg_sender().unwrap();
        let amount = msg_amount();
        let asset = msg_asset_id();

        require(asset == asset_id && amount == quantity, "Asset or Amount is invalid");
        require(price > 0, "Price is invalid");

        let nft_b256: b256 = nft_contract_id.into();
        let nft_contract = abi(SRC20, nft_b256);
        let decimals = match nft_contract.decimals(asset_id) {
            Some(d) => d,
            None => {
                require(false, "Contract ID is not valid");
                0 
            },
        };

        require(decimals == 0, "Not valid NFT or Semi Fungible Asset");

        match standard {
            NFTStandard::NFT => require(quantity == 1, "Not valid NFT"),
            _ => {},
        }
  • How can I validate that the nft_contract_id is the minter of a given asset_id?

the asset_id is a hash of the contractID and subID, with the way hashs work, where x * y = xy, you can’t get x or y, with just xy, but to validate you can do so given, the subID of the asset_id and the contractID and check if it returns the assetId, if it doesn’t equal to the assetID, then it’s not from that contract. hope this helps

Yes, I can implement that. However, users are unable to provide the Sub ID directly, as it’s not visible in their wallet — they can only see the Asset ID. Is there any way to retrieve the Sub ID? Thanks for your help!

A SHA-256 hash is used to derive the AssetId from the ContractId and SubId. though, directly retrieving the ContractId from an AssetId is difficult because it requires reversing a hash function, which is computationally impractical.

Instead, you can usually track the mapping between ContractId and AssetId during the contract deployment or asset creation process. If you have this mapping saved somewhere, you can use it to find the ContractId for a specific AssetId.

We are working on a POC for a library that should get name/symbol from AssetIds, and furthermore how we should go about converting AssetId into ContractId.

1 Like

Thank you! I really appreciate your help.