LYNC
DashboardSupport
  • 👋Introducing LYNC
  • Products
    • LYNC Account Abstraction SDK
    • LYNC Account Abstraction WebGL SDK
    • Metamask Wallet
    • LYNC Metamask PC SDK
    • OKX Wallet
    • LYNC In-Game Marketplace SDK
    • NFT Fetcher
    • No-Code Smart Contract Deployer
    • EVM Lootbox SDK
      • Getting Started
      • Using the SDK
        • Creating a new lootbox
        • Opening a lootbox
        • Claiming rewards
        • Whitelisting users using lootbox
        • Lootbox admin functions
        • Useful information functions from LyncLootBox class
        • Multicall : opening and claiming multiple lootboxes in a single transaction
      • Example Codes in React & TypeScript
        • Example code for creating a new lootbox
        • Example code for opening a lootbox
        • Example code for claiming a lootbox
    • Launch your products on Telegram
      • Configure Your Telegram Bot
      • Deploying Your Product on TG
  • APTOS
    • LYNC Paymaster - Supporting Aptos
      • How to Register on LYNC Dashboard
      • How to Create Paymaster
      • How to Fund the Paymaster
      • Module & Function Whitelist
      • How to Integrate Paymaster
        • Unity
        • API
        • JavaScript/ TypeScript
    • LYNC Unity Aptos SDK
    • Keyless Accounts
      • Configure Your OIDC Provider
      • Integrate Keyless in Unity
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
        • Mint NFT transactions
        • Send generic transactions on Aptos
    • LYNC Social Login SDK on Aptos
      • Getting Started
      • Using the SDK
      • Example Codes in React & TypeScript
      • Types Used in the Methods Provided by the SDK
      • Other Specification
    • LYNC Aptos Lootbox
      • Getting Started
      • Creating a Lootbox
      • Opening a Lootbox
      • Claiming the Rewards
      • Conclusion
  • Movement Labs
    • 📇Indexer
      • How to run index custom data?
      • Example Queries
        • Get Token Info
        • Get Token Balances
        • Get NFTs Owned by an Account
    • NFT Deployer
    • LYNC Social Login SDK on Movement
      • Getting Started
      • Using the SDK
      • Example Codes in React & TypeScript
      • Types and Enums Used in the Methods Provided by the SDK
      • Other Specification
    • LYNC Unity Movement SDK
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
        • Mint NFT transactions
    • LYNC Paymaster - Supporting Movement
      • How to Register on LYNC Dashboard
      • How to Create Paymaster
      • How to Fund the Paymaster
      • Module & Function Whitelist
      • How to Integrate Paymaster
        • JavaScript/ TypeScript
  • Supra
    • LYNC Paymaster - Supporting Supra L1
      • How to Register on LYNC Dashboard
      • How to Create Paymaster
      • How to Fund the Paymaster
      • Module & Function Whitelist
      • How to Integrate Paymaster
        • JavaScript/ TypeScript
    • LYNC Unity SUPRA SDK
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
        • Mint NFT transactions
  • Fuel
    • LYNC Unity Fuel SDK
    • LYNC NFT Deployer
      • Introduction
      • Getting Started
      • Deploying Your NFTs
        • Launch Your Entire Collection
      • Troubleshooting and FAQs
    • LYNC Fuel Lootbox
      • Getting Started
      • Creating a Lootbox
      • Opening a Lootbox
      • Claiming the Rewards
      • Conclusion
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
    • Fuel Marketplace NPM SDK
      • Getting Started
      • Using the SDK
        • Using hooks to get the marketplace data
        • Using services provided by the SDK to list, buy, and manage tokens
        • Some useful functions provided by the SDK
        • Error codes for the SDK
        • Interfaces and Enums provided by the SDK
      • Support
  • Metis
    • Wallet Creation and Transaction APIs
      • Pre-requisites
      • Integration
        • API Overview
        • Create a new wallet
        • Get already created wallet
        • Mint NFT transactions
  • NPM Packages
    • Marketplace
      • Hook: useAllCollectionNFT
      • Hook: useAllBuyNFT
      • Hook: useAllOwnerNFT
      • Hook: useNFTDetails
      • Hook: useAllNFTForRent
Powered by GitBook
On this page
  • Method Overview:
  • Parameters:
  • Return Value
  • Errors:
  1. Products
  2. EVM Lootbox SDK
  3. Using the SDK

Opening a lootbox

For opening a Lootbox using @lyncworld/lootbox-evm-sdk, you will need to create an instance of LyncLootbox class provided by the SDK and initialize the lootbox instance with a valid lootbox address. Here is an example of creating and initializing a lootbox using the SDK:

import { ChainIdentifier, LyncLootBox } from "@lyncworld/lootbox-evm-sdk";

const lootbox = new LyncLootBox();
const provider = new ethers.providers.Web3Provider(window.ethereum);

const lootboxId = "0x..." // a valid lootbox id created using `createLootBox` method

lootbox
	.initialize(ChainIdentifier.BASE_SEPOLIA, provider, lootboxId)
	.then((response) => console.log(response))
	.catch((err) => console.error("Error in initializing lootbox: ", err));

After creating an instance of LyncLootbox class and intializing, you can utilize the openLootBox method provided by the LyncLootBox class. Here is the complete specification of the method and an example function for creating a new Lootbox:

Method Overview:

The openLootBox function is an asynchronous function that is used to open a loot box. It performs several checks and operations before and after the loot box is opened.

Parameters:

The function takes one parameter:

  • signer (Signer): The signer who will be signing the open loot box transactions. It represents the entity (usually a user) that is initiating the transaction to open the loot box.

  • gasOverrides?: (optional) Gas override parameters (such as gasLimit, gasPrice, and maxFeePerGas from ethers) that you may need to adjust if transactions are failing to go through.

Return Value

The function returns a Promise that resolves to an object with two properties:

  • txn: This is the transaction object returned from the openLootBox function of the lootBoxInstance.

  • receipt: This is the receipt object returned from calling the wait function on the transaction object.

Errors:

The function can throw several errors, all instances of the LootBoxError class:

  • If the Merkle proof validation fails, it throws a LootBoxError with the VALIDATION_ERROR code.

  • If the wallet has no more remaining opens, it throws a LootBoxError with the LOOTBOX_OPENED_ERROR code.

  • If there are too many pending requests, it throws a LootBoxError with the TOO_MANY_REQUESTS_ERROR code.

  • If the loot box opening fails for any other reason, it throws a LootBoxError with the LOOTBOX_OPENED_ERROR code.

NOTE - This function will trigger a transaction on the blockchain, which will require the user to pay gas fees. Make sure the user is aware of this before calling this function. The TransactionResponse object can be used to track the status of the transaction on the blockchain.

PreviousCreating a new lootboxNextClaiming rewards

Last updated 8 months ago