Pack

When using the Pack smart contract, additional top-level functionality is available to use.

To access the top-level functionality, provide the marketplace contract type when creating the contract instance:

Contract contract = sdk.GetContract("0x...");
Pack pack = contract.Pack;

AddPackContents

Add additional tokens to the pool of tokens that can be opened from a pack.

// Define ERC20 rewards to add to the pack
ERC20Reward erc20Reward = new ERC20Reward();
erc20Reward.contractAddress = "0x123abc";
erc20Reward.quantityPerReward = "100";
// Define ERC721 rewards to add to the pack
ERC721Reward erc721Reward = new ERC721Reward();
erc721Reward.contractAddress = "0x456def";
erc721Reward.tokenId = "12345";
// Define ERC1155 rewards to add to the pack
ERC1155Reward erc1155Reward = new ERC1155Reward();
erc1155Reward.contractAddress = "0x789ghi";
erc1155Reward.tokenId = "67890";
erc1155Reward.quantityPerReward = "5";
PackRewards packRewards = new PackRewards();
packRewards.erc20Rewards = new List<ERC20Reward>() { erc20Reward };
packRewards.erc721Rewards = new List<ERC721Reward>() { erc721Reward };
packRewards.erc1155Rewards = new List<ERC1155Reward>() { erc1155Reward };
var data = await pack.AddPackContents("{{token_id}}", packRewards);

Create

Mint a new pack NFT, which can be opened to receive rewards, to the connected wallet.

Each pack NFT is an ERC1155 token, which means it can have more than one quantity.

Provide the metadata for the pack NFT itself, and the rewards that can be opened from the pack.

The quantity of packs created is determined by the total number of rewards available, divided by the number of rewards per pack. For example, if you had 20 total ERC20 rewards + 60 total ERC1155 rewards + 20 total ERC721 rewards, and you wanted to create packs with 5 rewards each, the result would be the creation of 20 packs (100 total rewards / 5 rewards per pack = 20 packs).

var packContents = new PackContents
{
erc20Contents = new List<ERC20Contents>
{
new ERC20Contents
{
contractAddress = "0x1234567890123456789012345678901234567890",
quantityPerReward = "10",
totalRewards = "5",
}
},
erc721Contents = new List<ERC721Contents>
{
new ERC721Contents
{
contractAddress = "0x0987654321098765432109876543210987654321",
tokenId = "1234"
}
},
erc1155Contents = new List<ERC1155Contents>
{
new ERC1155Contents
{
contractAddress = "0x4567890123456789012345678901234567890123",
tokenId = "5678",
quantityPerReward = "1",
totalRewards = "1",
}
}
};
var newPackInput = new NewPackInput
{
packMetadata = new NFTMetadata
{
name = "My Pack",
description = "A pack of rewards",
image = "https://example.com/pack.png",
external_url = "https://example.com/pack"
},
rewardsPerPack = "3",
erc20Contents = packContents.erc20Contents,
erc721Contents = packContents.erc721Contents,
erc1155Contents = packContents.erc1155Contents
};
var data = await pack.Create(newPackInput);

CreateTo

The same as Create, but allows you to specify the address that will receive the pack NFT(s), rather than using the connected wallet.

var packContents = new PackContents
{
erc20Contents = new List<ERC20Contents>
{
new ERC20Contents
{
contractAddress = "0x1234567890123456789012345678901234567890",
quantityPerReward = "10",
totalRewards = "5",
}
},
erc721Contents = new List<ERC721Contents>
{
new ERC721Contents
{
contractAddress = "0x0987654321098765432109876543210987654321",
tokenId = "1234"
}
},
erc1155Contents = new List<ERC1155Contents>
{
new ERC1155Contents
{
contractAddress = "0x4567890123456789012345678901234567890123",
tokenId = "5678",
quantityPerReward = "1",
totalRewards = "1",
}
}
};
var newPackInput = new NewPackInput
{
packMetadata = new NFTMetadata
{
name = "My Pack",
description = "A pack of rewards",
image = "https://example.com/pack.png",
external_url = "https://example.com/pack"
},
rewardsPerPack = "3",
erc20Contents = packContents.erc20Contents,
erc721Contents = packContents.erc721Contents,
erc1155Contents = packContents.erc1155Contents
};
var data = await pack.CreateTo("{{wallet_address}}", newPackInput);

GetPackContents

Get all the tokens that were "wrapped up" in the pack NFTs when they were created.

var data = await pack.GetPackContents("{{pack_id}}");

Open

Open a pack NFT to receive the rewards inside.

To open a pack, the wallet that initiates this transaction must have sufficient quantity of the pack NFT to open.

var data = await pack.Open("{{pack_id}}", "{{amount}}");

Balance

Get the quantity of a specific NFT owned by the connected wallet.

var data = await contract.ERC1155.Balance("{{token_id}}");

BalanceOf

Get the quantity of a specific NFT owned by a wallet.

var data = await contract.ERC1155.BalanceOf("{{wallet_address}}", "{{token_id}}");

Get

Get the metadata of an NFT using it’s token ID.

Metadata is fetched from the uri property of the NFT.

If the metadata is hosted on IPFS, the metadata is fetched and made available as an object. The object’s image property will be a URL that is available through the thirdweb IPFS gateway.

Transfer

Transfer an NFT from the connected wallet to another wallet.

var data = await contract.ERC1155.Transfer("{{wallet_address}}", "{{token_id}}", 1);

IsApprovedForAll

Get whether this wallet has approved transfers from the given operator.

This means that the operator can transfer NFTs on behalf of this wallet.

var data = await contract.ERC1155.IsApprovedForAll("{{owner_address}}", "{{operator_address}}");

SetApprovalForAll

Give another address approval (or remove approval) to transfer all of your NFTs from this collection.

var data = await contract.ERC1155.SetApprovalForAll("{{operator_address}}", true);

TotalCount

Get the total number of unique NFTs in the collection.

var data = await contract.ERC1155.TotalCount();

TotalSupply

Returns the total supply of a token in the collection, including burned tokens.

var data = await contract.ERC1155.TotalSupply("{{token_id}}");

GetAll

Get the metadata and current owner of all NFTs in the contract.

By default, returns the first 100 NFTs (in order of token ID). Use queryParams to paginate the results.

var data = await contract.ERC1155.GetAll();

GetOwned

Get all the data associated with the NFTs owned by a specific wallet.

var data = await contract.ERC1155.GetOwned();