Any suggestions what values to be used here?

  • In case of a nft deployed, while minting the nft what is the value of sub_id: SubId argument in the mint function.

Mint Function

 #[storage(read, write)]
    fn mint(recipient: Identity, sub_id: SubId, amount: u64) {
        require_not_paused();

        // Checks to ensure this is a valid mint.
        let asset = AssetId::new(contract_id(), sub_id);
        require(amount == 1, MintError::CannotMintMoreThanOneNFTWithSubId);
        require(
            storage
                .total_supply
                .get(asset)
                .try_read()
                .is_none(),
            MintError::NFTAlreadyMinted,
        );
        require(
            storage
                .total_assets
                .try_read()
                .unwrap_or(0) + amount <= MAX_SUPPLY,
            MintError::MaxNFTsMinted,
        );

        // Mint the NFT
        let _ = _mint(
            storage
                .total_assets,
            storage
                .total_supply,
            recipient,
            sub_id,
            amount,
        );
    }

Hey @shivamlync :wave:

For the sub_id , we expect a b256. For the TS-SDK specifically, we expect the b256 to be a string, so a little like below:

const value = await contract.functions.mint(
  identityInput,
  '0x0000000000000000000000000000000000000000000000000000000000000000', 
  100
)
.call();

What is sub_id? Can you explain. Also facing FuelError: The transaction reverted because a “require” statement has thrown an error.
this error

This worked for the first time, but it didn’t work the after that. I did use the same arguments as above

In an NFT contract, sub_id is the unique identifier that differentiates tokens.

The sub_id can be anything such as 0x00..00 , 0x00..01 , 0x00..02 , etc if you wanted a standard 10,000 mint NFT collection. Each of these NFTs would have their own AssetId.

Do you have a repository link you don’t mind sharing?

When I try to mint the second time, it throws this error

The transaction reverted because a "require" statement has throws an error.

How can I make it look like this

The sub_id can be anything such as 0x00..00 , 0x00..01 , 0x00..02 , etc if you wanted a standard 10,000 mint NFT collection. Each of these NFTs would have their own AssetId.

You will need a unique sub_id for each new mint:

import { getRandomB256 } from "fuels"

const subId = getRandomB256();
const value = await contract.functions.mint(
  identityInput,
  subId, 
  100
)
.call();
1 Like
 let asset = AssetId::new(contract_id(), sub_id);
        require(amount == 1, MintError::CannotMintMoreThanOneNFTWithSubId);
        require(
            storage
                .total_supply
                .get(asset)
                .try_read()
                .is_none(),
            MintError::NFTAlreadyMinted,
        );
        require(
            storage
                .total_assets
                .try_read()
                .unwrap_or(0) + amount <= 100_000,
            MintError::MaxNFTsMinted,
        );

Accoding to this total assets are 100k, so if I use same subId say 0x00000000000000 for all the accounts that mint it, then would it work or would throw the above error?

@p.s

Also can provide a documentation where subId is explain in detail.
@p.s

You may find the nightly docs more helpful.

If you could share a link to your repository, I may be able to assist further :slight_smile:


Just found the following post you might find useful!

3 Likes