NFT Drops
Connect to your NFT Drop program by providing the on-chain address of the program:
- React
- Javascript
import { useProgram } from "@thirdweb-dev/react/solana"
export default function Component() {
const { program } = useProgram("{{program_address}}", "nft-drop")
...
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk/solana";
const sdk = ThirdwebSDK.fromNetwork("devnet");
sdk.wallet.connect(signer);
// Get the interface for your NFT Drop program
const program = await sdk.getProgram("{{program_address}}", "nft-drop");
Get All NFTs
- React
- Javascript
import { useProgram, useNFTs } from "@thirdweb-dev/react/solana";
export default function Component() {
const { program } = useProgram("{{program_address}}");
const { data: metadata, isLoading } = useNFTs(program);
return (
<pre>{JSON.stringify(metadata)}</pre>
)
}
// Get all the NFTs that have been minted on this contract
const nfts = await program.getAll();
console.log(nfts[0].metadata.name);
Get NFT Balance
- React
- Javascript
// The address of the wallet to check the balance of
const walletAddress = "..."
// The mint address of the NFT to check the balance of
const nftAddress = "..."
// Get the actual NFT balance of the specified wallet
const balance = await program.balanceOf(walletAddress, nftAddress);
// The address of the wallet to check the balance of
const walletAddress = "..."
// The mint address of the NFT to check the balance of
const nftAddress = "..."
// Get the actual NFT balance of the specified wallet
const balance = await program.balanceOf(walletAddress, nftAddress);
Transfer NFTs
- React
- Javascript
// The wallet address to transfer the NFTs to
const to = "...";
// The mint address of the NFT to transfer
const nftAddress = "...";
const tx = await program.transfer(to, nftAddress);
// The wallet address to transfer the NFTs to
const to = "...";
// The mint address of the NFT to transfer
const nftAddress = "...";
const tx = await program.transfer(to, nftAddress);
Lazy Mint an NFT
- React
- Javascript
// Add the metadata of your NFTs
const metadata = [
{
name: "NFT #1",
description: "My first NFT!",
image: readFileSync("files/image.jpg"),
properties: [
{
name: "coolness",
value: "very cool!"
}
]
}
];
// And lazy mint NFTs to your program
const tx = await program.lazyMint(metadatas);
// Add the metadata of your NFTs
const metadata = [
{
name: "NFT #1",
description: "My first NFT!",
image: readFileSync("files/image.jpg"),
properties: [
{
name: "coolness",
value: "very cool!"
}
]
}
];
// And lazy mint NFTs to your program
const tx = await program.lazyMint(metadatas);
Claim an NFT
- React
- Javascript
import { useProgram, useClaimNFT } from "@thirdweb-dev/react/solana";
export default function Component() {
const { program } = useProgram("{{program_address}}");
const { mutateAsync: claim, isLoading, error } = useClaimNFT(program);
return (
<button onClick={() => claim({amount: 1})}>
Claim
</button>
)
}
// Specify which address to claim the NFTs to
const receiverAddress = "...";
// Claim the NFTs to the specified wallet and get the mint addresses of the NFTs
const claimedAddresses = await program.claimTo(receiverAddress, 1);
console.log("Claimed NFT at address", claimedAddresses[0]);
Burn an NFT
- React
- Javascript
// Specify the address of the NFT to burn
const nftAddress = "..."
// And send the actual burn transaction
const tx = await program.burn(nftAddress);
// Specify the address of the NFT to burn
const nftAddress = "..."
// And send the actual burn transaction
const tx = await program.burn(nftAddress);