thirdweb: Build an NFT Loot Box with thirdweb and IPFS
Learn how to build an NFT loot box with thirdweb and IPFS.
Last updated
Was this helpful?
Learn how to build an NFT loot box with thirdweb and IPFS.
Last updated
Was this helpful?
thirdweb is an easy-to-use platform to build Web3 applications with code or no-code. thirdweb makes creating and deploying apps such as NFT collections or NFT marketplaces easy. thirdweb can be used with objects stored on IPFS, so objects stored in a Filebase IPFS bucket can be seamlessly uploaded for use with a thirdweb app.
Read below to learn how to release an NFT loot box with thirdweb and IPFS.
Let’s start with the ERC-20 token. Select ‘Token’ under the ‘Popular’ category.
Then, select the blockchain for this contract to be deployed on. This tutorial uses the Mumbai Testnet network. When finished, select ‘Deploy Now’ to deploy the smart contract.
To include the token in our loot box, we’ll need to mint some.
Head back to the thirdweb dashboard, select ‘Deploy New Contract’, then select the ‘Edition’ smart contract under ‘NFTs’.
Select ‘Create Bucket’ in the top right corner to create a new bucket for your NFTs.
These files need to be named in sequential order, such as 0.png, 1.png, 2.png, etc.
https://ipfs.filebase.io/ipfs/IPFS_CID
Take note of this URL.
Select the ‘Code’ tab. This code showcases different code snippets to mint your NFTs using scripts, with your contract address and crypto wallet address inputted automatically for easy copy and paste. This tutorial will showcase the JavaScript code examples, but you can use any of the languages showcased in this Code tab. You can follow along with the code examples showcased in this tutorial, or copy and paste the snippets provided in this tab.
npm install @thirdweb-dev/sdk
CONTRACT: Your Edition NFT contract address. This can be found in the thirdweb dashboard here:
WALLET_ADDRESS: Your crypto wallet address.
Each IPFS_CID with your IPFS folder CID you took note of earlier.
Adjust the SUPPLY value for each NFT to reflect how many of each you would like included in your loot box.
You can edit this script to include as many NFTs as you’d like to mint in your loot box.
mint.js
, then run this script with the command:node mint.js
A loot box is a pack of multiple different rewards that contain a random selection of different items based on the reward pool. In this case, our rewards are our NFTs. There is a fixed supply of each NFT that we created, with some being in a much higher supply than others. The NFTs with a lower supply are rare to receive, making them worth more.
When you open a loot box, you’ll receive a random selection of the NFTs based on their rarity.
In this tutorial, we have 5 possible NFTs that can be in the loot box. We’ll configure our loot box to include 3 NFTs, making the NFTs with a lower supply rarer to receive within a loot box pack. Each loot box will also include a set number of the ERC-20 tokens that we created at the start of the tutorial. We’ll set a total number of 62 loot boxes that can be claimed and opened.
npx thirdweb create --next --ts
When prompted with the configuration options, use the following answers:
scripts
, with a new file called deployPack.mjs
. Open this file in your IDE of choice, then insert the following code:Replace the following values:
WALLET_ADDRESS: Your crypto wallet address.
node ./scripts/deployPack.mjs
This script will return a Pack address. Save this address to be used in the next step.
scripts
directory called bundleTokens.mjs
.Inside this file, insert the following code, replacing the following values to match your configuration:
PACK_ADDRESS: The pack address returned in the previous step.
TOKEN_ADDRESS: The contract address for your ERC-20 token. This can be found in the thirdweb dashboard:
EDITION_ADDRESS: The contract address for your ERC-1155 contract. This can be found in the thirdweb dashboard:
Configure the values for quantityPerReward, quantity, and totalReward to match your loot box's values.
node ./scripts/bundleTokens.mjs
First, we need some images stored on IPFS. To do this, navigate to . If you don’t have an account already, , then log in.
PRIVATE_KEY: This is the private key from your crypto wallet. You can learn how to export your private key Note that this value should be stored and accessed securely, and should not be made public at any time.
Now that you’ve created an NFT loot box, you can air drop packs to your friend’s wallets, set up a website for loot boxes to be claimed and opened, or use them as community rewards. To learn more about these workflows, check out the for this project.