NFT Collection
When using the NFT Collection smart contract, there is no need to provide a contract type argument, as the functionality of the smart contract is all available through the extensions interface.
The extensions that the NFT collection contract supports are listed below.
- ERC721
- ERC721Burnable
- ERC721Supply
- ERC721Enumerable
- ERC721Mintable
- ERC721BatchMintable
- ERC721SignatureMint
- Royalty
- PlatformFee
- PrimarySale
- Permissions
- ContractMetadata
- Ownable
- Gasless
balance
Get the NFT balance of the connected wallet (number of NFTs in this contract owned by the connected wallet).
const balance = await contract.erc721.balance();
Configuration
balanceOf
Get a wallet’s NFT balance (number of NFTs in this contract owned by the wallet).
const walletAddress = "{{wallet_address}}";
const balance = await contract.erc721.balanceOf(walletAddress);
Configuration
burn
Burn an NFT from the connected wallet.
const txResult = await contract.erc721.burn("{{token_id}}");
Configuration
generate - Signature-based
Generate a signature that a wallet address can use to mint the specified number of NFTs.
This is typically an admin operation, where the owner of the contract generates a signature that allows another wallet to mint tokens.
const payload = {
to: "{{wallet_address}}", // (Required) Who will receive the tokens
metadata: {
name: "Cool NFT #1",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
// ... Any other metadata you want to include
},
currencyAddress: "{{currency_contract_address}}", // (Optional) the currency to pay with
price: 0.5, // (Optional) the price to pay for minting those tokens (in the currency above)
mintStartTime: new Date(), // (Optional) can mint anytime from now
mintEndTime: new Date(Date.now() + 60 * 60 * 24 * 1000), // (Optional) to 24h from now,
primarySaleRecipient: "0x...", // (Optional) custom sale recipient for this token mint
quantity: 100, // (Optional) The quantity of tokens to be minted
};
const signedPayload = contract.erc721.signature.generate(payload);
Configuration
generateBatch - Signature-based
Generate a batch of signatures at once.
This is the same as generate
but it allows you to generate multiple signatures at once.
const signatures = await contract.erc721.signature.generateBatch([
{
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
}
{
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
}
]);
Configuration
get
Get the metadata for an NFT in this contract using it’s token ID.
Metadata is fetched from the uri
property of the NFT.
If the metadata is hosted on IPFS, the metadata is fetched and made available as an object.
The object’s image
property will be a URL that is available through the thirdweb IPFS gateway.
const tokenId = 0;
const nft = await contract.erc721.get(tokenId);
Configuration
get - Contract Metadata
Get the metadata of a smart contract.
const metadata = await contract.metadata.get();
Configuration
get - Owner
Retrieve the wallet address of the owner of the smart contract.
const owner = await contract.owner.get();
Configuration
get - Permissions
Get a list of wallet addresses that are members of a given role.
const members = await contract.roles.get("{{role_name}}");
Configuration
getAll - Permissions
Retrieve all of the roles and associated wallets.
const allRoles = await contract.roles.getAll();
Configuration
get - Platform Fee
Get the platform fee recipient and basis points.
const feeInfo = await contract.platformFee.get();
Configuration
getAll
Get the metadata and current owner of all NFTs in the contract.
By default, returns the first 100
NFTs (in order of token ID). Use queryParams
to paginate the results.
const nfts = await contract.erc721.getAll();
Configuration
getAllOwners
Get all wallet addresses that own an NFT in this contract.
const owners = await contract.erc721.getAllOwners();
Configuration
getDefaultRoyaltyInfo
Gets the royalty recipient and BPS (basis points) of the smart contract.
const royaltyInfo = await contract.royalties.getDefaultRoyaltyInfo();
Configuration
getMintTransaction
Construct a mint transaction without executing it. This is useful for estimating the gas cost of a mint transaction, overriding transaction options and having fine grained control over the transaction execution.
const txResult = await contract.erc721.getMintTransaction(
"{{wallet_address}}", // Wallet address to mint to
{
name: "Cool NFT #1",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
// ... Any other metadata you want to include
},
);
Configuration
getOwned
Get the metadata of all NFTs a wallet owns from this contract.
// Address of the wallet to get the NFTs of
const address = "{{wallet_address}}"; // Optional - Defaults to the connected wallet
const nfts = await contract.erc721.getOwned(address);
Configuration
getOwnedTokenIds
Get the token IDs of all NFTs a wallet owns from this contract.
const ownedTokenIds = await contract.erc721.getOwnedTokenIds(
"{{wallet_address}}",
);
Configuration
getRecipient
Get the primary sale recipient.
const salesRecipient = await contract.sales.getRecipient();
Configuration
getTokenRoyaltyInfo
Gets the royalty recipient and BPS (basis points) of a particular token in the contract.
const royaltyInfo = await contract.royalties.getTokenRoyaltyInfo(
"{{token_id}}",
);
Configuration
grant - Permissions
Make a wallet a member of a given role.
const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration
isApproved
Get whether this wallet has approved transfers from the given operator.
This means that the operator can transfer NFTs on behalf of this wallet.
const isApproved = await contract.erc721.isApproved(
// Address of the wallet to check
"{{wallet_address}}",
// Address of the operator to check
"{{wallet_address}}",
);
Configuration
mint
Mint a new NFT to the connected wallet.
// Custom metadata of the NFT, note that you can fully customize this metadata with other properties.
const metadata = {
name: "Cool NFT #1",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
// ... Any other metadata you want to include
};
const txResult = await contract.erc721.mint(metadata);
Configuration
mint - Signature-based
Mint tokens from a previously generated signature (see generate
).
// Use the signed payload to mint the tokens
const txResult = contract.erc721.signature.mint(signature);
Configuration
mintBatch
Mint multiple NFTs in a single transaction to the connected wallet.
const txResult = await contract.erc721.mintBatch([
{
name: "Cool NFT #1",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
},
{
name: "Cool NFT #2",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
},
]);
Configuration
mintBatch - Signature-based
Use multiple signatures at once to mint tokens.
This is the same as mint
but it allows you to provide multiple signatures at once.
// Use the signed payloads to mint the tokens
const txResult = contract.erc721.signature.mintBatch(signatures);
Configuration
mintBatchTo
Mint multiple NFTs to a specified wallet address.
// Address of the wallet you want to mint the NFT to
const walletAddress = "{{wallet_address}}";
// Custom metadata of the NFTs you want to mint.
const metadatas = [
{
name: "Cool NFT #1",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
// ... Any other metadata you want to include
},
{
name: "Cool NFT #2",
description: "This is a cool NFT",
image: "https://example.com/image.png", // URL, IPFS URI, or File object
// ... Any other metadata you want to include
},
];
const tx = await contract.erc721.mintBatchTo(walletAddress, metadatas);
Configuration
mintTo
The same as mint
, but allows you to specify the address of the wallet that will receive the NFT rather than using
the connected wallet address.
// Address of the wallet you want to mint the NFT to
const walletAddress = "{{wallet_address}}";
// Custom metadata of the NFT, note that you can fully customize this metadata with other properties.
const metadata = {
name: "Cool NFT",
description: "This is a cool NFT",
};
const txResult = await contract.erc721.mintTo(walletAddress, metadata);
Configuration
nextTokenIdToMint
Returns the token ID of the next NFT that will be minted.
const nextTokenId = await contract.erc721.nextTokenIdToMint();
Configuration
ownerOf
Get the wallet address of the owner of an NFT.
const owner = await contract.erc721.ownerOf("{{token_id}}");
Configuration
revoke - Permissions
Revoke a given role from a wallet.
const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration
set - Contract Metadata
Overwrite the metadata of a contract, an object following the contract level metadata standards.
This operation ignores any existing metadata and replaces it with the new metadata provided.
const txResult = await contract.metadata.set({
name: "My Contract",
description: "My contract description",
});
Configuration
set - Owner
Set the owner address of the contract.
const txResult = await contract.owner.set("{{wallet_address}}");
Configuration
set - Platform Fee
Set the platform fee recipient and basis points.
const txResult = await contract.platformFees.set({
platform_fee_basis_points: 100,
platform_fee_recipient: "0x123",
});
Configuration
setAll - Permissions
Overwrite all roles with new members.
This overwrites all members, INCLUDING YOUR OWN WALLET ADDRESS!
This means you can permanently remove yourself as an admin, which is non-reversible.
Please use this method with caution.
const txResult = await contract.roles.setAll({
admin: ["0x12", "0x123"],
minter: ["0x1234"],
});
Configuration
setApprovalForAll
Give another address approval (or remove approval) to transfer any of your NFTs from this collection.
Proceed with caution. Only approve addresses you trust.
await contract.erc721.setApprovalForAll(
"{{wallet_address}}", // The wallet address to approve
true, // Whether to approve (true) or remove approval (false)
);
Configuration
setApprovalForToken
Give another address approval (or remove approval) to transfer a specific one of your NFTs from this collection.
Proceed with caution. Only approve addresses you trust.
// Approve the wallet address
await contract.erc721.setApprovalForToken(
"{{wallet_address}}", // The wallet address to approve
"{{token_id}}", // The token ID of the NFT to allow them to transfer
);
Configuration
setDefaultRoyaltyInfo
Set the royalty recipient and fee for the smart contract.
await contract.royalties.setDefaultRoyaltyInfo({
seller_fee_basis_points: 100, // 1% royalty fee
fee_recipient: "0x...", // the fee recipient
});
Configuration
setRecipient
Set the primary sale recipient.
await contract.sales.setRecipient("{{wallet_address}}");
Configuration
setTokenRoyaltyInfo
Set the royalty recipient and fee for a particular token in the contract.
await contract.royalties.setTokenRoyaltyInfo("{{token_id}}", {
seller_fee_basis_points: 100, // 1% royalty fee
fee_recipient: "0x...", // the fee recipient
});
Configuration
totalCirculatingSupply
Get the total number of NFTs that are currently in circulation.
i.e. the number of NFTs that have been minted and not burned.
const totalSupply = await contract.erc721.totalCirculatingSupply();
Configuration
totalCount
Get the total number of NFTs minted in this contract.
Unlike totalCirculatingSupply
, this includes NFTs that have been burned.
const totalSupply = await contract.erc721.totalCount();
Configuration
transfer
Transfer an NFT from the connected wallet to another wallet.
const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.erc721.transfer(walletAddress, tokenId);
Configuration
verify - Permissions
Check to see if a wallet has a set of roles.
Throws an error if the wallet does not have any of the given roles.
const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_address}}",
);
Configuration
verify - Signature-based
Verify that a payload is correctly signed.
This allows you to provide a payload, and prove that it was valid and was generated by a wallet with permission to generate signatures.
If a payload is not valid, the mint
/mintBatch
functions will fail,
but you can use this function to verify that the payload is valid before attempting to mint the tokens
if you want to show a more user-friendly error message.
// Provide the generated payload to verify that it is valid
const isValid = await contract.erc721.signature.verify(payload);
Configuration
update - Contract Metadata
Update the metadata of your smart contract.
const txResult = await contract.metadata.update({
name: "My Contract",
description: "My contract description",
});