Pack
Learn how to interact with your Pack contract in the SDK.
Create a Pack Contract
- React
- Javascript
- Python
- Go
- Unity
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",
});
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
.DeployPack(new NFTContractDeployMetadata()
{ name = "My Collection", primary_sale_recipient = "0x..." });
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
- Unity
import { useContract } from '@thirdweb-dev/react'
export default function Component() {
const { contract } = usePack("<YOUR-CONTRACT-ADDRESS>", "pack")
// 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 = await sdk.getContract("{{contract_address}}", "pack");
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!
Pack contract = sdk.GetContract("{{contract_address}}").pack;
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 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..."
});
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!
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
- Unity
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);
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!
// The address to check the funds of
var address = "{{wallet_address}}";
await contract
.CreateTo(address,
new NewPackInput()
{
packMetadata =
new NFTMetadata()
{
name = "My Pack",
description = "My Pack Description",
image = "https://myimage.com",
external_url = "https://myimage.com"
},
erc1155Rewards =
new List<ERC1155Contents> {
new ERC1155Contents()
{
contractAddress = "0x...",
tokenId = "0",
quantityPerReward = "1"
}
},
erc721Rewards =
new List<ERC721Contents> {
new ERC721Contents()
{
contractAddress = "0x...",
tokenId = "0"
}
},
erc20Rewards =
new List<ERC20Contents> {
new ERC20Contents()
{
contractAddress = "0x...",
quantityPerReward = "1",
totalRewards = "1"
}
}
});
Add more contents to an existing Pack
You can add ERC20, ERC721, or ERC1155 tokens to a an existing packId, up till the first transfer of those packs.
When you add contents, an additional supply of ERC1155 pack NFTs is minted for a packId.
- React
- Javascript
- Python
- Go
- Unity
const packContents = {
// 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,
}
],
}
const tx = await contract.addPackContents(packId, packContents);
const packContents = {
// 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,
}
],
}
const tx = await contract.addPackContents(packId, packContents);
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!
// Pack token ID
string packId = "0";
await contract
.AddPackContents(packId,
new PackRewards()
{
erc1155Rewards =
new List<ERC1155Reward> {
new ERC1155Reward()
{
contractAddress = "0x...",
tokenId = "0",
quantityPerReward = "1"
}
},
erc721Rewards =
new List<ERC721Reward> {
new ERC721Reward()
{ contractAddress = "0x...", tokenId = "0" }
},
erc20Rewards =
new List<ERC20Reward> {
new ERC20Reward()
{ contractAddress = "0x...", quantityPerReward = "1" }
}
});
Airdrop a Pack
View Packs
One
- React
- Javascript
- Python
- Go
- Unity
const tokenId = 0; // the tokenId to look up
const { data: nft, isLoading, error } = useNFT(contract, tokenId);
const pack = await contract.get(0);
console.log(packs;
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 pack = await contract.Get(tokenId);
All
- React
- Javascript
- Python
- Go
- Unity
const { data: nfts, isLoading, error } = useNFTs(contract, { start: 0, count: 100 });
const packs = await contract.getAll();
console.log(packs;
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 packs = await contract.GetAll();
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 packs of
const address = "{{wallet_address}}";
const packss = await contract.getOwned(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!
// Address of the Wallet to get the packs of
var address = "{{wallet_address}}";
var packss = await contract.GetOwned(address);
Amount 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);
// 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);
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 to check NFT balance
var walletAddress = "{{wallet_address}}";
var tokenId = "0"; // Id of the NFT to check
var balance = await contract.BalanceOf(walletAddress, tokenId);
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
- Unity
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);
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 packId = "0";
var contents = await contract.GetPackContents(packId);
Debug.Log(contents.erc20Rewards);
Debug.Log(contents.erc721Rewards);
Debug.Log(contents.erc1155Rewards);
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
- Unity
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);
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 amount = "1";
var tx = await contract.Open(tokenId, amount);
Transferring NFTs
You must be the owner of the pack you're trying to transfer for this to be successful.