NFT Collection
Learn how to interact with your NFT Collection contract in the SDK.
Create an NFT Collection Contract
- React
- Javascript
- Python
- Go
- Unity
const sdk = useSDK();
const contractAddress = await sdk.deployer.deployNFTCollection({
name: "My Collection",
primary_sale_recipient: "your-address",
});
const contractAddress = await sdk.deployer.deployNFTCollection({
name: "My Collection",
primary_sale_recipient: "your-address",
});
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
await sdk
.deployer
.DeployNFTCollection(new NFTContractDeployMetadata()
{ name = "My Collection", primary_sale_recipient = "0x..." });
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.
- React
- Javascript
- Python
- Go
- Unity
import { useContract } from '@thirdweb-dev/react'
export default function Component() {
const { contract, isLoading, error } = useContract("<YOUR-CONTRACT-ADDRESS>", "nft-collection")
// Now you can use the nftCollection contract in the rest of the component
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("{{chainName}}");
const contract = await sdk.getContract("{{contract_address}}", "nft-collection");
from thirdweb import ThirdwebSDK
# You can customize this to a supported network or your own RPC URL
network = "mumbai"
# Now we can create a new instance of the SDK
sdk = ThirdwebSDK(network)
# If you want to send transactions, you can instantiate the SDK with a private key instead:
# sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, network)
contract = sdk.get_nft_collection("{{contract_address}}")
import (
"github.com/thirdweb-dev/go-sdk/v2/thirdweb"
)
privateKey = "..."
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
contract, err := sdk.GetNFTCollection("{{contract_address}}")
Contract contract = sdk.GetContract("{{contract_address}}");
Setting Royalty Fees
- React
- Javascript
- Python
- Go
- Unity
// 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..."
});
// 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..."
});
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Minting NFTs
Mint One NFT
- React
- Javascript
- Python
- Go
- Unity
const Component = () => {
const { contract } = useContract("{{contract_address}}");
const {
mutate: mintNft,
isLoading,
error,
} = useMintNFT(contract);
if (error) {
console.error("failed to mint NFT", error);
}
return (
<button
disabled={isLoading}
onClick={() => mintNft({ name: "My awesome NFT!", to: "{{wallet_address}}" })}
>
Mint!
</button>
);
};
// 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",
image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
};
const tx = await contract.mintTo(walletAddress, metadata);
const receipt = tx.receipt; // the transaction receipt
const tokenId = tx.id; // the id of the NFT minted
const nft = await tx.data(); // (optional) fetch details of minted NFT
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
// Address of the wallet you want to mint the NFT to
var walletAddress = "{{wallet_address}}";
// Custom metadata of the NFT, note that you can fully customize this metadata with other properties.
var metadata = new NFTMetadata() {
name = "Cool NFT",
description = "This is a cool NFT",
image = "<image-url-here>"
};
var tx = await contract.ERC721.MintTo(walletAddress, metadata);
Mint Many NFTs (Batch Mint)
- React
- Javascript
- Python
- Go
- Unity
// 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
// 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
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Unity SDK Reference for more information.
Reach out on Discord for further assistance!
Viewing NFTs
One NFT
- React
- Javascript
- Python
- Go
- Unity
const tokenId = 0; // the tokenId to look up
const { data: nft, isLoading, error } = useNFT(contract, tokenId);
const tokenId = 0;
const nft = await contract.get(tokenId);
nft = contract.get(0)
print(nft)
nft, err := contract.Get(context.Background(), 0)
owner := nft.Owner
name := nft.Metadata.Name
var tokenId = "0";
var nft = await contract.ERC721.Get(tokenId);
All NFTs
- React
- Javascript
- Python
- Go
- Unity
const { data: nfts, isLoading, error } = useNFTs(contract, { start: 0, count: 100 });
const nfts = await contract.getAll();
console.log(nfts);
nfts = contract.get_all()
print(nfts)
nfts, err := contract.GetAll(context.Background())
ownerOne := nfts[0].Owner
nameOne := nfts[0].Metadata.Name
var nfts = await contract.ERC721.GetAll();
Debug.Log(nfts);
NFTs owned by a specific wallet
- React
- Javascript
- Python
- Go
- Unity
const { data: ownedNFTs, isLoading, error } = useOwnedNFTs(contract, "{{wallet_address}}");
// Address of the wallet to get the NFTs of
const address = "{{wallet_address}}";
const nfts = await contract.getOwned(address);
console.log(nfts);
nfts = contract.get_owned("{{wallet_address}}")
print(nfts)
owner := "{{wallet_address}}"
nfts, err := contract.GetOwned(context.Background(), owner)
name := nfts[0].Metadata.Name
// Address of the Wallet to get the NFTs of
var address = "{{wallet_address}}";
var nfts = await contract.ERC721.GetOwned(address);
Debug.Log(nfts);
Amount of tokens owned by a specific wallet
- React
- Javascript
- Python
- Go
- Unity
const { data: ownerBalance, isLoading, error } = useNFTBalance(contract, "{{wallet_address}}");
// for ERC1155 contracts, you can also pass a tokenId
const tokenId = 0;
const { data: ownerBalance, isLoading, error } = useNFTBalance(contract, "{{wallet_address}}", tokenId);
const walletAddress = "{{wallet_address}}";
const balance = await contract.balanceOf(walletAddress);
console.log(balance);
balance = contract.balance_of("{{wallet_address}}")
print(balance)
address := "{{wallet_address}}"
balance, err := contract.BalanceOf(context.Background(), address)
var walletAddress = "{{wallet_address}}";
var balance = await contract.ERC721.BalanceOf(walletAddress);
Debug.Log(balance);
Transferring NFTs
Burning NFTs
- React
- Javascript
- Python
- Go
- Unity
const result = await contract.burnToken(tokenId);
const result = await contract.burnToken(tokenId);
This feature is missing a code snippet or might not be supported yet.
Check the Python SDK Reference for more information.
Reach out on Discord for further assistance!
This feature is missing a code snippet or might not be supported yet.
Check the Go SDK Reference for more information.
Reach out on Discord for further assistance!
var tokenId = "0";
var result = await contract.ERC721.Burn(tokenId);