Skip to main content

NFT Collection

Learn how to interact with your NFT Collection contract in the SDK.

Create an NFT Collection Contract

const sdk = useSDK();

const contractAddress = await sdk.deployer.deployNFTCollection({
name: "My Collection",
primary_sale_recipient: "your-address",
});

Getting the contract in your application

To start using your NFT Collection contract inside your application, you need to use its contract address. You can get the contract address from the dashboard.

import { useNFTCollection } from '@thirdweb-dev/react'

export default function Component() {
const nftCollection = useNFTCollection("<YOUR-CONTRACT-ADDRESS>")

// Now you can use the nftCollection contract in the rest of the component
}

Setting Royalty Fees

Configure royalties
// royalties on the whole contract
contract.royalties.setDefaultRoyaltyInfo({
seller_fee_basis_points: 100, // 1%
fee_recipient: "0x..."
});
// override royalty for a particular token
contract.royalties.setTokenRoyaltyInfo(tokenId, {
seller_fee_basis_points: 500, // 5%
fee_recipient: "0x..."
});

Minting NFTs

Mint One NFT

Mint a unique NFT
const Component = () => {
const { contract } = useContract(<ContractAddress>);
const {
mutate: mintNft,
isLoading,
error,
} = useMintNFT(contract?.nft);

if (error) {
console.error("failed to mint nft", error);
}

return (
<button
disabled={isLoading}
onClick={() => mintNft({ name: "My awesome NFT!", to: "0x..." })}
>
Mint!
</button>
);
};
View in React SDK Documentation

Mint Many NFTs (Batch Mint)

Mint Many unique NFTs
// 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: fs.readFileSync("path/to/image.png"), // This can be an image url or file
}, {
name: "Cool NFT #2",
description: "This is a cool NFT",
image: fs.readFileSync("path/to/other/image.png"),
}];

const tx = await contract.mintBatchTo(walletAddress, metadatas);
const receipt = tx[0].receipt; // same transaction receipt for all minted NFTs
const firstTokenId = tx[0].id; // token id of the first minted NFT
const firstNFT = await tx[0].data(); // (optional) fetch details of the first minted NFT

Viewing NFTs

One NFT

Get a single NFT Metadata
const { contract } = useContract(<ContractAddress>);
const { data: nft, isLoading, error } = useNFT(contract?.nft, <tokenId>);
View in React SDK Documentation

All NFTs

Get All Minted NFTs
const { contract } = useContract(<ContractAddress>);
const { data: nfts, isLoading, error } = useNFTs(contract?.nft, { start: 0, count: 100 });
View in React SDK Documentation

NFTs owned by a specific wallet

Get Owned NFTs
const { contract } = useContract(<ContractAddress>);
const { data: ownedNFTs, isLoading, error } = useOwnedNFTs(contract?.nft, <OwnerWalletAddress>);
View in React SDK Documentation

Amount of tokens owned by a specific wallet

Get NFT Balance
const { contract } = useContract(<ContractAddress>);
const { data: ownerBalance, isLoading, error } = useNFTBalance(contract?.nft, <OwnerWalletAddress>);
View in React SDK Documentation

Transferring NFTs

Transfer a single NFT
const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.nft.transfer(walletAddress, tokenId);

Burning NFTs