🎉 ⏱ Ready to build? Get early access now!⏱ 🎉
Bundle Drop Code Examples
Last updated:
January 13, 2022
Easy copy and paste snippets to use thirdweb Bundle Drop module
Deploy a Bundle Drop
- Import
readFileSync
at the top of your file if you want to add an image for your bundle. - Import
ethers
if you want to make your bundle drop free.
import { readFileSync } from "fs"; import { ethers } from "ethers";
const app = sdk.getAppModule("<BUNDLE_DROP_MODULE_ADDRESS>"); const deployBundleDrop = async () => { try { const bundleDrop = await app.deployBundleDropModule({ // The collection's name, ex. CryptoPunks name: "NarutoDAO Membership", // A description for the collection. description: "A DAO for fans of Naruto.", // The image that will be held on our NFT! The fun part :). image: readFileSync("scripts/assets/naruto.png"), // We need to pass in the address of the person who will be receiving the proceeds from sales of nfts in the module. // We're planning on not charging people for the drop, so we'll pass in the 0x0 address // you can set this to your own wallet address if you want to charge for the drop. primarySaleRecipientAddress: ethers.constants.AddressZero, }); console.log( "✅ Successfully deployed bundleDrop module, address:", bundleDrop.address ); } catch (error) { console.log("failed to deploy bundleDrop module", error); } }; deployBundleDrop();
Configure the bundle drop
Remember to import readFileSync
at the top of your file:
import { readFileSync } from "fs";
const bundleDrop = sdk.getBundleDropModule("<BUNDLE_DROP_MODULE_ADDRESS>"); const configBundleDrop = async () => { try { await bundleDrop.createBatch([ { name: "Leaf Village Headband", description: "This NFT will give you access to NarutoDAO!", image: readFileSync("scripts/assets/headband.png"), }, ]); console.log("✅ Successfully created a new NFT in the drop!"); } catch (error) { console.error("failed to create the new NFT", error); } }; configBundleDrop();
Setting Claim Conditions
const bundleDrop = sdk.getBundleDrop("<MODULE_ADDRESS>"); const setClaimCondition = async () => { const allowList = [ "<ALLOWED_ADDRESS_1>", "<ALLOWED_ADDRESS_2>", "<ALLOWED_ADDRESS_3>", "<ALLOWED_ADDRESS_4>", ]; const factory = bundleDrop.getClaimConditionFactory(); const claimPhase = factory.newClaimPhase({ startTime: new Date(), maxQuantity: 10, maxQuantityPerTransaction: 1, }); claimPhase.setPrice( // price cannot be set above, use this way instead 1, "<TOKEN_ADDRESS>" ); // optional, can be left blank for native currency claimPhase.setWaitTimeBetweenClaims(24 * 60 * 60); claimPhase.setSnapshot(allowList); await bundleDrop.setClaimCondition("0", factory); // 0 refers to token id };
Snapshot Condition
Bundle drops are a special type of drop that allows you to create a collection (ERC-1155) of NFTs. That means that each token you mint gets its own ID, and in turn its own set of claim conditions.
In this case, you'll notice on the last line that we pass the argument "0"
, which
applies the claim conditions for that specific token ID.
const factory = bundleDropModule.getClaimConditionFactory(); const phase = factory.newClaimPhase({ startTime: new Date(), }); await phase.setSnapshot(["<ALLOWED_ADDRESS_1>", "<ALLOWED_ADDRESS_2>", ...]); await bundleDropModule.setClaimCondition("0", factory);
Get
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop // module in the dashboard. const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const get = async () => { // Get with tokenId try { await bundleDrop.get('0'); } catch (error) { console.log('Failed to get. Error: ', error); } }; get();
Get All
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getAll = async () => { try { await bundleDrop.getAll(); } catch (error) { console.log('Failed to get all. Error: ', error); } }; getAll();
Get Royalty Bps
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getRoyaltyBps = async () => { try { await bundleDrop.getRoyaltyBps(); } catch (error) { console.log('Failed to get royalty Bps. Error: ', error); } }; getRoyaltyBps();
Get Royalty Recipient Address
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getRoyaltyContract = async () => { try { await bundleDrop.getRoyaltyRecipientAddress(); } catch (error) { console.log('Failed to get royalty contract. Error: ', error); } }; getRoyaltyContract();
Get Default Sale Recipient
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getDefaultSaleRecipient = async () => { try { await bundleDrop.getDefaultSaleRecipient(); } catch (error) { console.log('Failed to get default sale recipient. Error: ', error); } }; getDefaultSaleRecipient();
Get All Claim Conditions
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getAllClaimConditions = async () => { // Get all claim conditions by tokenId try { await bundleDrop.getAllClaimConditions(0); } catch (error) { console.log('Failed to get all claim condition. Error: ', error); } }; getAllClaimConditions();
Get Active Claim Conditions
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getActiveClaimConditions = async () => { // Get active claim conditions by tokenId try { await bundleDrop.getActiveClaimCondition(0); } catch (error) { console.log('Failed to get active claim conditions. Error: ', error); } }; getActiveClaimConditions();
Claim
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const claim = async () => { // Claim an NFT for yourself with (tokenId, quantity) try { await bundleDrop.claim(0, 1); console.log('Claim successful!'); } catch (error) { console.log('Claim failed. Error: ', error); } }; claim();
Balance
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const balance = async () => { // Get balance of claimed NFTs by tokenId try { await bundleDrop.balance(0); } catch (error) { console.log('Failed to get balance. Error: ', error); } }; balance();
Balance Of
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const balanceOf = async () => { // Get the balance of an NFT in a wallet address - (wallet address, tokenId) try { await bundleDrop.balanceOf("<WALLET_ADDRESS>", 0); } catch (error) { console.log('Failed to get balance of. Error: ', error); } }; balanceOf();
Burn
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const burn = async () => { // burn from the claimed supply - (tokenId, amount) try { await bundleDrop.burn(0, 1); } catch (error) { console.log('Failed to burn. Error: ', error); } }; burn();
Can Claim
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const canClaim = async () => { // Check if can claim. (tokenId, amount, wallet address) try { await bundleDrop.canClaim(0, 1, "<WALLET_ADDRESS>"); } catch (error) { console.log('Failed to check can claim. Error: ', error); } }; canClaim();
Get Claim Ineligibility Reasons
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getClaimIneligibilityReasons = async () => { // Get reasons for claim ineligibility - (tokenId, amount, wallet address) try { await bundleDrop.getClaimIneligibilityReasons(0, 1, "<WALLET_ADDRESS>"); } catch (error) { console.log('Failed to get ineligibility reasons. Error: ', error); } }; getClaimIneligibilityReasons();
Get All Claimer Addresses
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getAllClaimerAddresses = async () => { // Get all claimer addresses for specific tokenId try { await bundleDrop.getAllClaimerAddresses(0); } catch (error) { console.log('Failed to get all claimer addresses. Error: ', error); } }; getAllClaimerAddresses();
Get Owned
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getOwned = async () => { // Get owned NFTs for a wallet address try { await bundleDrop.getOwned("<WALLET_ADDRESS>"); } catch (error) { console.log('Failed to get owned. Error: ', error); } }; getOwned();
Is Restricted
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const isTransferRestricted = async () => { try { await bundleDrop.isTransferRestricted(); } catch (error) { console.log('Failed to get restricted status. Error: ', error); } }; isTransferRestricted();
Set Restricted Transfer
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const setRestrictedTransfer = async () => { // Set transfer restriction with a boolean try { await bundleDrop.setRestrictedTransfer(false); } catch (error) { console.log('Failed to set restricted status. Error: ', error); } }; setRestrictedTransfer();
Total Supply
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const totalSupply = async () => { // Get total supply for an NFT by tokenId try { await bundleDrop.totalSupply(0); } catch(error) { console.log('Failed to get total supply. Error: ', error); } }; totalSupply();
Get Sale Recipient
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getSaleRecipient = async () => { // Get sale recipient for an NFT by tokenId try { await getSaleRecipient(0); } catch (error) { console.log('Failed to get sale recipient. Error: ', error); } }; getSaleRecipient();
Set Sale Recipient
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const setSaleRecipient = async () => { // Set sale recipient with tokenId and wallet address try { await bundleDrop.setSaleRecipient(0, '<WALLET_ADDRESS>'); } catch (error) { console.log('Failed to set saile recipient. Error: ', error); } }; setSaleRecipient();
Set Default Sale Recipient
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const setDefaultSaleRecipient = async () => { try { await bundleDrop.setDefaultSaleRecipient('<WALLET_ADDRESS>'); } catch (error) { console.log('Failed to set default sale recipient. Error: ', error); } }; setDefaultSaleRecipient();
Get Claim Conditions Factory
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const getClaimConditionsFactory = async () => { try { return await bundleDrop.getClaimConditionsFactory(); } catch (error) { console.log('Failed to get factory. Error: ', error); } }; getClaimConditionsFactory();
Update Claim Conditions
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const updateClaimConditions = async () => { // Create conditions of type PublicClaimCondition const conditions: PublicClaimCondition = { currentMintSupply: 12, maxMintSupply: 10, startTimestamp: ethers.BigNumber.from(Math.floor(Date.now() / 1000)), quantityLimitPerTransaction: 2, waitTimeSecondsLimitPerTransaction: 1, pricePerToken: 5, currency: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", merkleRoot: "0x0000000000000000000000000000000000000000000000000000000000000000", }; // Create a claim condition factory const factory = bundleDrop.getClaimConditionFactory(); // Update the tokenId with factory using the conditions try { await bundleDrop.updateClaimConditions(0, factory.fromPublicClaimConditions([conditions])); } catch(error) { console.log('Failed to update claim conditions. Error: ', error); } }; updateClaimConditions();
Claim To
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const claimTo = async () => { // Claim NFT and send to address - (tokenId, amount, wallet address) try { await bundleDrop.claimTo(0, 1, "<WALLET_ADDRESS>"); } catch (error) { console.log('Failed to claim to. Error: ', error); } }; claimTo();
Is Approved
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const isApproved = async () => { // Check if the other contract (operator) has approval try { await bundleDrop.isApproved("<APP_MODULE_ADDRESS", "<OPERATOR_CONTRACT_ADDRESS"); } catch (error) { console.log('Failed to check approved. Error: ', error); } }; isApproved();
Set Approval
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const setApproval = async () => { // Set approval for other contract (operator) try { await bundleDrop.setApproval("<OPERATOR_CONTRACT_ADDRESS", false); } catch (error) { console.log('Failed to set approval. Error: ', error); } }; setApproval();
Set Royalty Bps
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const setRoyaltyBps = async () => { // Set royalty Bps to a new value try { await bundleDrop.setRoyaltyBps(3); } catch (error) { console.log('Failed to set royalty Bps. Error: ', error)l; } }; setRoyaltyBps();
Create Batch
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const createBatch = async () => { // Create batch data const batchData = { name: "Leaf Village Headband", description: "This NFT will give you access to our DAO!", image: readFileSync("assets/1.png"), }; // Call create batch method with batch data param try { await bundleDrop.createBatch([batchData]); } catch (error) { console.log('Failed to create bacth. Error: ', error); } }; createBatch();
Lazy Mint Batch
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const lazyMintBatch = async () => { // Create batch data const batchData = { name: "Joburg", description: "This NFT is for devs in Johannesburg, South Africa!", image: readFileSync("assets/2.png"), }; // Call lazy mint batch method with batch data param await bundleDrop .lazyMintBatch([batchData]) .then((data) => console.log(data)) .catch((error) => console.error(error)); }; lazyMintBatch();
Set Module Metadata
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const setModuleMetadata = async () => { const metadata: BundleDropModuleMetadata = { primarySaleRecipientAddress: "<WALLET_ADDRESS>", name: "Bundle Drop Module", }; try { await bundleDrop.setModuleMetadata(metadata); } catch (error) { console.log('Failed to set module metadat. Error: ', error); } }; setModuleMetadata();
Transfer To
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const transferTo = async () => { // Transfer NFT to wallet address - (wallet address, tokenId, amount) try { await bundleDrop.transfer("<WALLET_ADDRESS>", 0, 1); } catch (error) { console.log('Failed to transfer to. Error: ', error); } }; transferTo();
Transfer From
// Set variable for the bundle drop module contract address which can be found after creating a bundle drop module in the dashboard const bundleDropAddress = "<BUNDLE_DROP_MODULE_ADDRESS>"; // Initialize the bundle drop module with the contract address const bundleDrop = sdk.getBundleDropModule(bundleDropAddress); const transferFrom = async () => { // Transfer an NFT (from wallet, to wallet, tokenId, amount) try { await bundleDrop.transferFrom("<FROM_WALLET_ADDRESS>", "<TO_WALLET_ADDRESS>", 0, 1); } catch (error) { console.log('Failed to transfer from. Error: ', error); } }; transferFrom();
Ready to build your first web3 app? Get early access & add web3 features to your project today.
Contents
Deploy a Bundle Drop
Configure the bundle drop
Setting Claim Conditions
Snapshot Condition
Get
Get All
Get Royalty Bps
Get Royalty Recipient Address
Get Default Sale Recipient
Get All Claim Conditions
Get Active Claim Conditions
Claim
Balance
Balance Of
Burn
Can Claim
Get Claim Ineligibility Reasons
Get All Claimer Addresses
Get Owned
Is Restricted
Set Restricted Transfer
Total Supply
Get Sale Recipient
Set Sale Recipient
Set Default Sale Recipient
Get Claim Conditions Factory
Update Claim Conditions
Claim To
Is Approved
Set Approval
Set Royalty Bps
Create Batch
Lazy Mint Batch
Set Module Metadata
Transfer To
Transfer From