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,
);
}
p.s
May 10, 2024, 12:41pm
2
Hey @shivamlync
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
p.s
May 10, 2024, 12:54pm
5
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.
p.s
May 10, 2024, 12:59pm
7
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
p.s
May 10, 2024, 1:36pm
10
You may find the nightly docs more helpful.
If you could share a link to your repository, I may be able to assist further
Just found the following post you might find useful!
It’s up to the developer!
If the contract only creates a single token, we expect the SubId will often be 0
For NFTs, the SubIds might be sequential
In the case of “vault” type tokens, the subId might be the AssetId of the underlying asset
ENS-style naming applications might use a namehash-type algorithm
You can even use asset sub-ids to represent contract state! Pass some state into the asset subId, and you can then reconstruct the assetId in a separate contract or predicate to prove state (I…
3 Likes