Creating a new lootbox
For creating a new Lootbox using @lyncworld/lootbox-evm-sdk, you will need to create an instance of LyncLootboxManager class provided by the SDK. Here is an example of creating a new Lootbox using the SDK:
import { LyncLootBoxCreator, ChainIdentifier } from "@lyncworld/lootbox-evm-sdk";
const lootboxCreator = new LyncLootBoxCreator();
await lootboxCreator.initialize(ChainIdentifier.BASE_SEPOLIA, provider);After creating an instance of Lync Lootbox Creator class, you can utilize the createLootbox method provided by the LyncLootBoxCreator class. Here is the complete specification of the method and an example function for creating a new Lootbox:
Method Overview:
The createLootbox function is an asynchronous method in the LyncLootBoxCreator class. This function is responsible for creating a new loot box with ERC20, ERC721, and ERC1155 items.
Syntax:
async createLootbox(
signer: Signer,
erc20Items: ERC20Item[],
erc721Items: ERC721Item[],
erc1155Items: ERC1155Item[],
whitelist: string[],
trustedForwarder: string, // for meta transactions
activateLootbox: boolean,
maxOpensPerAddress: number,
gasOverrides?: Overrides = {}
): Promise<TransactionResponse[]>
Parameters:
signer (Signer)*:The signer who will be signing the transactions.erc20Items (ERC20Item[])*:An array of ERC20 items to be included in the loot box.erc721Items (ERC721Item[])*:An array of ERC721 items to be included in the loot box.erc1155Items (ERC1155Item[])*:An array of ERC1155 items to be included in the loot box.whitelist (string[])*:An array of addresses that are whitelisted. Keep empty for no whitelist.trustedForwarder (string)*:The address of the trusted forwarder for meta transactions. Pass in zero address if you don’t want to enable meta txns.activateLootbox (boolean)*:A boolean indicating whether to start the loot box.maxOpensPerAddress (number)*:The maximum number of times each address can open the lootboxgasOverrides: Gas override parameters (such as gasLimit, gasPrice, and maxFeePerGas from ethers) that you may need to adjust if transactions are failing to go through.
All the parameters marked with
*in the above list are required parameters for creating a loot box.
Return Value:
This function returns a Promise that resolves to an array of TransactionResponse objects. Each TransactionResponse object contains the transaction, the receipt of the transaction, and additional data related to the transaction.
Errors:
This function throws a LootBoxError if:
Approval fails for
ERC20,ERC721, orERC1155items.Lootbox creation fails.
Important Notes:
For an existing
ERC20,ERC1155orERC721item,name,symbol, anduriBase(in case ofERC1155andERC721items) is not required. Therefore, you can pass empty strings as a value for these arguments:Examples:
For a new
ERC20,ERC1155orERC721item, pass the zero address as a value of thecontractAddressforERC20Item,ERC1155Item, orERC721Item.Examples:
REMARKS -
This function is part of the
LyncLootBoxCreatorclass and cannot be called independently. It must be called on an instance of theLyncLootBoxCreatorclass.
Last updated