Pack
Learn how to interact with your Pack contract in the SDK.
Create a Pack Contract
- React
- Javascript
- Python
- Go
const sdk = useSDK();
const contractAddress = await sdk.deployer.deployPack({
name: "My Pack",
primary_sale_recipient: "your-address",
});
const contractAddress = await sdk.deployer.deployPack({
name: "My Pack",
primary_sale_recipient: "your-address",
});
Python SDK support for deployPack is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for deployPack is coming soon.
Want this feature sooner? Let us know in Discord!
Getting the contract in your application
To start using your Pack contract inside your application, you'll need to use its contract address. You can get the contract address from the dashboard.
- React
- Javascript
- Python
- Go
import { usePack } from '@thirdweb-dev/react'
export default function Component() {
const pack = usePack("<YOUR-CONTRACT-ADDRESS>")
// Now you can use the pack contract in the rest of the component
}
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
const sdk = new ThirdwebSDK("{{chainName}}");
const contract = sdk.getPack("{{contract_address}}");
Python SDK support for initializing the SDK is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for initializing the SDK is coming soon.
Want this feature sooner? Let us know in Discord!
Setting Royalty Fees
- 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 pack
contract.royalties.setTokenRoyaltyInfo(packId, {
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 pack
contract.royalties.setTokenRoyaltyInfo(packId, {
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!
Create a Pack
You can bundle any number of ERC20, ERC721, or ERC1155 tokens into a set quantity of ERC1155 pack NFTs.
When you create a pack, it is minted as a new NFT in the smart contract.
- React
- Javascript
- Python
- Go
const pack = {
// The metadata for the pack NFT itself
packMetadata: {
name: "My Pack",
description: "This is a new pack",
image: "ipfs://...",
},
// ERC20 rewards to be included in the pack
erc20Rewards: [
{
assetContract: "0x...",
quantityPerReward: 5,
quantity: 100,
totalRewards: 20,
}
],
// ERC721 rewards to be included in the pack
erc721Rewards: [
{
assetContract: "0x...",
tokenId: 0,
}
],
// ERC1155 rewards to be included in the pack
erc1155Rewards: [
{
assetContract: "0x...",
tokenId: 0,
quantityPerReward: 1,
totalRewards: 100,
}
],
openStartTime: new Date(), // the date that packs can start to be opened, defaults to now
rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1
}
const tx = await contract.createTo("0x...", pack);
const pack = {
// The metadata for the pack NFT itself
packMetadata: {
name: "My Pack",
description: "This is a new pack",
image: "ipfs://...",
},
// ERC20 rewards to be included in the pack
erc20Rewards: [
{
assetContract: "0x...",
quantityPerReward: 5,
quantity: 100,
totalRewards: 20,
}
],
// ERC721 rewards to be included in the pack
erc721Rewards: [
{
assetContract: "0x...",
tokenId: 0,
}
],
// ERC1155 rewards to be included in the pack
erc1155Rewards: [
{
assetContract: "0x...",
tokenId: 0,
quantityPerReward: 1,
totalRewards: 100,
}
],
openStartTime: new Date(), // the date that packs can start to be opened, defaults to now
rewardsPerPack: 1, // the number of rewards in each pack, defaults to 1
}
const tx = await contract.createTo("0x...", pack);
Python SDK support for createTo is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for createTo is coming soon.
Want this feature sooner? Let us know in Discord!
Airdrop a Pack
- React
- Javascript
- Python
- Go
// The token ID of the NFT you want to airdrop
const tokenId = "0";
// Array of objects of addresses and quantities to airdrop NFTs to
const addresses = [
{
address: "0x...",
quantity: 2,
},
{
address: "0x...",
quantity: 3,
},
];
await contract.airdrop(tokenId, addresses);
// You can also pass an array of addresses, it will airdrop 1 NFT per address
const tokenId = "0";
const addresses = [
"0x...", "0x...", "0x...",
]
await contract.airdrop(tokenId, addresses);
// The token ID of the NFT you want to airdrop
const tokenId = "0";
// Array of objects of addresses and quantities to airdrop NFTs to
const addresses = [
{
address: "0x...",
quantity: 2,
},
{
address: "0x...",
quantity: 3,
},
];
await contract.airdrop(tokenId, addresses);
// You can also pass an array of addresses, it will airdrop 1 NFT per address
const tokenId = "0";
const addresses = [
"0x...", "0x...", "0x...",
]
await contract.airdrop(tokenId, addresses);
Python SDK support for airdrop is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for airdrop is coming soon.
Want this feature sooner? Let us know in Discord!
View Packs
One
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: nft, isLoading, error } = useNFT(contract?.nft, <tokenId>);
const nft = await contract.get("0");
Python SDK support for get is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for get is coming soon.
Want this feature sooner? Let us know in Discord!
All
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: nfts, isLoading, error } = useNFTs(contract?.nft, { start: 0, count: 100 });
const packs = await contract.getAll();
console.log(packs;
Python SDK support for getAll is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for getAll is coming soon.
Want this feature sooner? Let us know in Discord!
Owned by a specific wallet
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: ownedNFTs, isLoading, error } = useOwnedNFTs(contract?.nft, <OwnerWalletAddress>);
// Address of the wallet to get the packs of
const address = "{{wallet_address}}";
const packss = await contract.getOwned(address);
Python SDK support for getOwned is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for getOwned is coming soon.
Want this feature sooner? Let us know in Discord!
Amount owned by a specific wallet
- React
- Javascript
- Python
- Go
const { contract } = useContract(<ContractAddress>);
const { data: ownerBalance, isLoading, error } = useNFTBalance(contract?.nft, <OwnerWalletAddress>);
// Address of the wallet to check NFT balance
const walletAddress = "{{wallet_address}}";
const tokenId = 0; // Id of the NFT to check
const balance = await contract.balanceOf(walletAddress, tokenId);
Python SDK support for balanceOf is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for balanceOf is coming soon.
Want this feature sooner? Let us know in Discord!
View Pack Contents
You can view all of the rewards that were bundled to create the packs, but not the contents of each individual pack.
- React
- Javascript
- Python
- Go
const packId = 0;
const contents = await contract.getPackContents(packId);
console.log(contents.erc20Rewards);
console.log(contents.erc721Rewards);
console.log(contents.erc1155Rewards);
const packId = 0;
const contents = await contract.getPackContents(packId);
console.log(contents.erc20Rewards);
console.log(contents.erc721Rewards);
console.log(contents.erc1155Rewards);
Python SDK support for getPackContents is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for getPackContents is coming soon.
Want this feature sooner? Let us know in Discord!
Open Pack
When you open a pack, you receive the tokens within it and burn the pack NFT.
Only the owner of a pack can open it.
Multiple of the same pack can be opened at once.
- React
- Javascript
- Python
- Go
const tokenId = 0
const amount = 1
const tx = await contract.open(tokenId, amount);
const tokenId = 0
const amount = 1
const tx = await contract.open(tokenId, amount);
Python SDK support for open is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for open is coming soon.
Want this feature sooner? Let us know in Discord!
Transferring NFTs
You must be the owner of the pack you're trying to transfer for this to be successful.
- React
- Javascript
- Python
- Go
// Address of the wallet you want to send the NFT to
const toAddress = "{{wallet_address}}";
const tokenId = "0"; // The token ID of the NFT you want to send
const amount = 3; // How many copies of the NFTs to transfer
await contract.transfer(toAddress, tokenId, amount);
// Address of the wallet you want to send the NFT to
const toAddress = "{{wallet_address}}";
const tokenId = "0"; // The token ID of the NFT you want to send
const amount = 3; // How many copies of the NFTs to transfer
await contract.transfer(toAddress, tokenId, amount);
Python SDK support for transfer is coming soon.
Want this feature sooner? Let us know in Discord!
Go SDK support for transfer is coming soon.
Want this feature sooner? Let us know in Discord!