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
Return Value
Returns a BigNumber
representing the number of NFTs owned by the connected wallet.
BigNumber;
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
tokenId
The token ID of the NFT to burn.
Must be a string
, number
, or BigNumber
.
const txResult = await contract.erc721.burn(
"{{token_id}}",
);
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
The mintRequest
object you provide to the generate
function outlines what the signature can be used for.
The to
, and metadata
fields are required, while the rest are optional.
to (required)
The wallet address that can use this signature to mint tokens.
This is to prevent another wallet from intercepting the signature and using it to mint tokens for themselves.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
});
metadata (required)
The metadata of the NFT to mint.
Can either be a string
URL that points to valid metadata that conforms to the metadata standards,
or an object that conforms to the same standards.
If you provide an object, the metadata is uploaded and pinned to IPFS before the NFT(s) are minted.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
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 (optional)
The address of the currency to pay for minting the tokens (use the price
field to specify the price).
Defaults to NATIVE_TOKEN_ADDRESS
(the native currency of the network, e.g. Ether on Ethereum).
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
currencyAddress: "{{currency_contract_address}}",
});
price (optional)
If you want the user to pay for minting the tokens, you can specify the price per token.
Defaults to 0
(free minting).
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
price: "{{price}}", // The user will have to pay `price * quantity` for minting the tokens
});
mintStartTime (optional)
The time from which the signature can be used to mint tokens.
Defaults to Date.now()
(now).
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
mintStartTime: new Date(), // The user can mint the tokens from this time
});
mintEndTime (optional)
The time until which the signature can be used to mint tokens.
Defaults to new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 10),
(10 years from now).
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
mintEndTime: new Date(Date.now() + 60 * 60 * 24 * 1000), // The user can mint the tokens until this time
});
primarySaleRecipient (optional)
If a price
is specified, the funds will be sent to the primarySaleRecipient
address.
Defaults to the primarySaleRecipient
address of the contract.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
price: "{{price}}",
primarySaleRecipient: "{{wallet_address}}", // The funds will be sent to this address
});
royaltyBps (optional)
The percentage fee you want to charge for secondary sales.
Defaults to the royaltyBps
of the contract.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
price: "{{price}}",
royaltyBps: 500, // A 5% royalty fee.
});
royaltyRecipient (optional)
The address that will receive the royalty fees from secondary sales.
Defaults to the royaltyRecipient
address of the contract.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
price: "{{price}}",
royaltyBps: 500, // A 5% royalty fee.
royaltyRecipient: "{{wallet_address}}", // The royalty fees will be sent to this address
});
quantity (optional)
The number of tokens this signature can be used to mint.
const signature = await contract.erc721.signature.generate({
quantity: "{{quantity}}",
to: "{{wallet_address}}",
metadata: {
// ... Your NFT metadata
},
});
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
tokenId
The token ID of the NFT to get the metadata for.
Must be a BigNumber
, number
, or string
.
const nft = await contract.erc721.get(
"{{token_id}}",
);
Return Value
Returns an NFT
object containing the NFT metadata.
{
metadata: {
id: string;
uri: string; // The raw URI of the metadata
owner: string;
name?: string | number | undefined;
description?: string | null | undefined;
image?: string | null | undefined; // If the image is hosted on IPFS, the URL is https://gateway.ipfscdn.io/ipfs/<hash>
external_url?: string | null | undefined;
animation_url?: string | null | undefined;
background_color?: string | undefined;
properties?: {
[x: string]: unknown;
} | {
[x: string]: unknown;
}[] | undefined;
};
type: "ERC721";
}
get - Contract Metadata
Get the metadata of a smart contract.
const metadata = await contract.metadata.get();
Configuration
Return Value
While the actual return type is any
, you can expect an object containing
properties that follow the
contract level metadata standards, outlined below:
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}
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
Return Value
An object containing role names as keys and an array of wallet addresses as the value.
<Record<any, string[]>>
get - Platform Fee
Get the platform fee recipient and basis points.
const feeInfo = await contract.platformFee.get();
Configuration
Return Value
Returns an object containing the platform fee recipient and basis points.
{
platform_fee_basis_points: number;
platform_fee_recipient: string;
}
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
queryParams (optional)
Provide an optional object to configure the query. Useful for paginating the results.
const queryParams = {
// The number of NFTs to return
count: 100, // Default is 100
// The index to start from
start: 0, // Default is 0
};
const nfts = await contract.erc721.getAll(queryParams);
Return Value
Returns an array of NFT
objects.
{
metadata: {
id: string;
uri: string; // The raw URI of the metadata
owner: string;
name?: string | number | undefined;
description?: string | null | undefined;
image?: string | null | undefined; // If the image is hosted on IPFS, the URL is https://gateway.ipfscdn.io/ipfs/<hash>
external_url?: string | null | undefined;
animation_url?: string | null | undefined;
background_color?: string | undefined;
properties?: {
[x: string]: unknown;
} | {
[x: string]: unknown;
}[] | undefined;
};
type: "ERC1155" | "ERC721";
}[]
getAllOwners
Get all wallet addresses that own an NFT in this contract.
const owners = await contract.erc721.getAllOwners();
Configuration
Return Value
Returns an array of objects containing a tokenId
and owner
address.
tokenId
is the ID of the NFT.owner
is the wallet address of the owner that owns the NFT.
{
tokenId: number;
owner: string;
}
[];
getDefaultRoyaltyInfo
Gets the royalty recipient and BPS (basis points) of the smart contract.
const royaltyInfo = await contract.royalties.getDefaultRoyaltyInfo();
Configuration
Return Value
Returns an object containing the royalty recipient address and BPS (basis points) of the smart contract.
{
seller_fee_basis_points: number;
fee_recipient: string;
}
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
address (optional)
The address of the wallet to get the NFTs of. If not provided, defaults to the connected wallet address.
const nfts = await contract.erc721.getOwned(
"{{wallet_address}}",
);
Return Value
Returns an array of NFT
objects.
{
metadata: {
id: string;
uri: string; // The raw URI of the metadata
owner: string;
name?: string | number | undefined;
description?: string | null | undefined;
image?: string | null | undefined; // If the image is hosted on IPFS, the URL is https://gateway.ipfscdn.io/ipfs/<hash>
external_url?: string | null | undefined;
animation_url?: string | null | undefined;
background_color?: string | undefined;
properties?: {
[x: string]: unknown;
} | {
[x: string]: unknown;
}[] | undefined;
};
type: "ERC1155" | "ERC721";
}[]
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
owner
The wallet address that owns the NFT.
Must be a string
.
const isApproved = await contract.erc721.isApproved(
"{{wallet_address}}",
"{{wallet_address}}",
);
operator
The wallet address of the operator to check (i.e. the wallet that does/does not have approval).
Must be a string
.
const isApproved = await contract.erc721.isApproved(
"{{wallet_address}}",
"{{wallet_address}}",
);
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
metadata
Either provide a string
that points to valid metadata object
or an object containing the metadata.
The image
property can be an IPFS URI, a URL, or a File
object.
If a file is provided for the image, it will also be uploaded and pinned to IPFS before minting.
Using a string:
// Option 1: Provide a string that points to valid metadata object
var metadata = "https://example.com/metadata.json";
Using an object:
// Option 2: Provide a metadata object, which will be uploaded and pinned to IPFS for you.
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
};
Provide the metadata to the mint
function:
// Either the string or the object can be provided to the mint function
const txResult = await contract.erc721.mint(metadata);
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
signature (required)
The signature created by the generate
function.
The typical pattern is the admin generates a signature, and the user uses it to mint the tokens, under the conditions specified in the signature.
Must be of type SignedPayload1155
.
// Use the signed payload to mint the tokens
const txResult = contract.erc721.signature.mint(
signature, // Signature generated by the `generate` function
);
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
metadatas
An array of strings that point to, or objects containing valid metadata properties.
See mint
for more details on the properties available.
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
signatures (required)
An array of signatures created by the generate
or generateBatch
functions.
Must be of type SignedPayload1155[]
.
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
receiver
The wallet address to mint the NFTs to.
Must be a string
.
const metadatas = [
// ...
];
const tx = await contract.erc721.mintBatchTo(
"{{wallet_address}}",
metadatas,
);
metadatas
An array of metadata objects for the NFTs you want to mint.
Must be an array
of object
s that conform to the metadata standards.
Alternatively, you can provide an array of string
s that point to valid metadata objects,
to override the default behavior of uploading and pinning the metadata to IPFS (shown below).
const metadatas = [
"https://example.com/metadata1.json",
"ipfs://my-ipfs-hash",
"https://some-other-url.com/metadata2.json",
];
const tx = await contract.erc721.mintBatchTo(
"{{wallet_address}}",
metadatas,
);
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
Return Value
Returns a BigNumber
representing the token ID of the next NFT that will be minted.
BigNumber;
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
metadata
Provide an object containing the metadata of your smart contract following the contract level metadata standards.
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}
set - Owner
Set the owner address of the contract.
const txResult = await contract.owner.set("{{wallet_address}}");
Configuration
owner
The wallet address of the new owner.
Must be a string
.
const txResult = await contract.owner.set(
"{{wallet_address}}",
);
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
roles
An object containing role names as keys and an array of wallet addresses as the value.
const txResult = await contract.roles.setAll(
{
admin: ["0x12", "0x123"], // Grant these two wallets the admin role
minter: ["0x1234"], // Grant this wallet the minter role
},
);
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",
});
Configuration
metadata
Provide an object containing the metadata of your smart contract following the contract level metadata standards.
New properties will be added, and existing properties will be overwritten. If you do not provide a new value for a previously set property, it will remain unchanged.
Below are the properties you can define on your smart contract.
{
name: string; // Name of your smart contract
description?: string; // Short description of your smart contract
image?: string; // Image of your smart contract (any URL, or IPFS URI)
symbol?: string; // Symbol of your smart contract (ticker, e.g. "ETH")
external_link?: string; // Link to view this smart contract on your website
seller_fee_basis_points?: number // The fee you charge on secondary sales, e.g. 100 = 1% seller fee.
fee_recipient?: string; // Wallet address that receives the seller fee
}