Skip to main content

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);
Configuration

packId

The ID of the pack you want to add tokens to.

For example, in your pack contract you may have a common pack with ID 0 and a rare pack with ID 1.

To add more tokens to the common pack, you would pass "0" as the packId.

Must be a string.

rewards

An instance of the PackRewards class containing the tokens you want to add to the pack.

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);
Configuration

packMetadata

An NFTMetadata struct containing standard metadata properties.

The metadata is uploaded and pinned to IPFS for you before the packs are minted. The IPFS URI is then used as the metadata for the pack NFT.

erc20Contents

A list of of ERC20 tokens to include in the pack.

Each item in the list must contain a contractAddress, quantityPerReward, and totalRewards property.

erc721Contents

A list of ERC721 tokens to include in the pack.

Each item in the list must contain a contractAddress and tokenId property.

erc1155Contents

A list of ERC1155 tokens to include in the pack.

Each item in the list must contain a contractAddress, tokenId, quantityPerReward, and totalRewards property.

rewardsPerPack

The number of rewards in each pack.

Must be a string.

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);
Configuration

to

The wallet address to mint the pack NFTs to.

Must be a string.

See Create for more information on the rest of the configuration options.

GetPackContents

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

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

packId

The token ID of the pack to get the contents of.

Must be a string.

Return Value

Returns all the tokens that were included in the rewards when the packs were created.

{
List<ERC20Contents> erc20Contents;
List<ERC721Contents> erc721Contents;
List<ERC1155Contents> erc1155Contents;
}

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}}");
Configuration

packId

The token ID of the pack to open.

Must be a string.

amount

The number of packs to open.

Optional. Defaults to "1".

Must be a string.

Balance

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

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

tokenId

The token ID of the NFT to check the balance of.

Must be a string.

Return Value

A string representing the quantity of the NFT owned by the wallet.

string

BalanceOf

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

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

address

The wallet address to check the NFT balance for.

Must be a string.

tokenId

The token ID of the NFT to check the balance of.

Must be a string.

Return Value

A string representing the quantity of the NFT owned by the wallet.

string

Get

Get the metadata of an NFT using its 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 objects image property will be a URL that is available through the thirdweb IPFS gateway.


Configuration

tokenId

The token ID of the NFT to get the metadata for.

Must be a string.

Return Value

Returns an NFT struct containing the following properties:

{
{
string id;
string uri;
string description;
string image;
string name;
string external_url;
object attributes;
}
string owner;
string type;
int supply;
int quantityOwned; // only for ERC1155
}

Transfer

Transfer an NFT from the connected wallet to another wallet.

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

to

The wallet address to send the NFT to.

Must be a string.

tokenId

The token ID of the NFT to transfer.

Must be a string.

amount

The quantity of the NFT to transfer.

Must be an int.

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}}");
Configuration

owner

The wallet address that owns the NFT.

Must be a string.

operator

The wallet address of the operator to check (i.e. the wallet that does/does not have approval).

Must be a string.

SetApprovalForAll

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

Warning

Proceed with caution. Only approve addresses you trust.

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

operator

The wallet address to approve.

Must be a string.

approved

Whether to grant approval (true) or remove approval (false).

Must be a bool.

TotalCount

Get the total number of unique NFTs in the collection.

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

Return Value

Returns an int representing the total number of unique NFTs in the collection.

int

TotalSupply

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

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

tokenId

The token ID of the NFT to get the total supply of.

Must be a string.

Return Value

Returns an int representing the total supply of the token.

int

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();
Configuration

queryParams (optional)

Provide an optional object to configure the query. Useful for paginating the results.

var data = await contract.ERC1155.GetAll(new QueryAllParams()
{
count = 100,
start = 0
});

Return Value

Returns a list of NFT structs, each containing the following properties:

{
{
string id;
string uri;
string description;
string image;
string name;
string external_url;
object attributes;
}
string owner;
string type;
int supply;
int quantityOwned;
}

GetOwned

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

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

address

The address of the wallet to get the NFTs of.

Must be a string.

Return Value

Returns a list of NFT structs, each containing the following properties:

{
{
string id;
string uri;
string description;
string image;
string name;
string external_url;
object attributes;
}
string owner;
string type;
int supply;
int quantityOwned;
}