NFT Collection
Learn how to interact with your NFT Collection contract in the SDK.
Create an NFT Collection Contract
- React
- Javascript
- Python
- Go
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",
});
Python SDK support for deployNFTCollection is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for deployNFTCollection is coming soon.
Want this feature sooner? Let us know in Discord!
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
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
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("{{chainName}}");
const contract = sdk.getNFTCollection("{{contract_address}}");
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/thirdweb"
)
privateKey = "..."
sdk, err := thirdweb.NewThirdwebSDK("mumbai", &thirdweb.SDKOptions{
PrivateKey: privateKey,
})
contract, err := sdk.GetNFTCollection("{{contract_address}}")
Setting Royalty Fees
Configure royalties
- React
- Javascript
- Python
- Go
// 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..."
});
Python SDK support for royalties is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for royalties is coming soon.
Want this feature sooner? Let us know in Discord!
Minting NFTs
Mint One NFT
Mint a unique NFT
- React
- Javascript
- Python
- Go
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>
);
};
// 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
from thirdweb.types.nft import NFTMetadataInput
# Note that you can customize this metadata however you like
metadata = NFTMetadataInput.from_json({
"name": "Cool NFT",
"description": "This is a cool NFT",
"image": open("path/to/file.jpg", "rb"),
})
# You can pass in any address here to mint the NFT to
tx = contract.mint_to("{{wallet_address}}", metadata)
receipt = tx.receipt
token_id = tx.id
nft = tx.data()
image, err := os.Open("path/to/image.jpg")
defer image.Close()
metadata := &thirdweb.NFTMetadataInput{
Name: "Cool NFT",
Description: "This is a cool NFT",
Image: image,
}
tx, err := contract.MintTo("{{wallet_address}}", metadata)
Mint Many NFTs (Batch Mint)
Mint Many unique NFTs
- React
- Javascript
- Python
- Go
// 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
from thirdweb.types.nft import NFTMetadataInput
# You can customize this metadata however you like
metadatas = [
NFTMetadataInput.from_json({
"name": "Cool NFT",
"description": "This is a cool NFT",
"image": open("path/to/file.jpg", "rb"),
}),
NFTMetadataInput.from_json({
"name": "Cooler NFT",
"description": "This is a cooler NFT",
"image": open("path/to/file.jpg", "rb"),
}),
]
# You can pass in any address here to mint the NFT to
txs = contract.mint_batch_to("{{wallet_address}}", metadatas)
receipt = txs[0].receipt
first_token_id = txs[0].id
first_nft = txs[0].data()
metadatas := []*thirdweb.NFTMetadataInput{
&thirdweb.NFTMetadataInput{
Name: "Cool NFT",
Description: "This is a cool NFT",
}
&thirdweb.NFTMetadataInput{
Name: "Cool NFT 2",
Description: "This is also a cool NFT",
}
}
tx, err := contract.MintBatchTo("{{wallet_address}}", metadatas)
Viewing NFTs
One NFT
Get a single NFT Metadata
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: nft, isLoading, error } = useNFT(contract?.nft, <tokenId>);
const tokenId = 0;
const nft = await contract.nft.get(tokenId);
nft = contract.get(0)
print(nft)
nft, err := contract.Get(0)
All NFTs
Get All Minted NFTs
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: nfts, isLoading, error } = useNFTs(contract?.nft, { start: 0, count: 100 });
const nfts = await contract.getAll();
console.log(nfts);
nfts = contract.get_all()
print(nfts)
nfts, err := contract.GetAll()
ownerOne := nfts[0].Owner
nameOne := nfts[0].Metadata.Name
NFTs owned by a specific wallet
Get Owned NFTs
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: ownedNFTs, isLoading, error } = useOwnedNFTs(contract?.nft, <OwnerWalletAddress>);
// 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(owner)
name := nfts[0].Metadata.Name
Amount of tokens owned by a specific wallet
Get NFT Balance
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: ownerBalance, isLoading, error } = useNFTBalance(contract?.nft, <OwnerWalletAddress>);
const walletAddress = "{{wallet_address}}";
const balance = await contract.nft.balanceOf(walletAddress);
console.log(balance);
balance = contract.balance_of("{{wallet_address}}")
print(balance)
address := "{{wallet_address}}"
balance, err := contract.BalanceOf(address)
Transferring NFTs
Transfer a single NFT
- React
- Javascript
- Python
- Go
const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.nft.transfer(walletAddress, tokenId);
const walletAddress = "{{wallet_address}}";
const tokenId = 0;
await contract.nft.transfer(walletAddress, tokenId);
to = "{{wallet_address}}"
token_id = 0
receipt = contract.transfer(to, token_id)
to := "0x..."
tokenId := 0
tx, err := contract.Transfer(to, tokenId)