DERA chain docs
  • Introduction
  • NFT2.0
    • Introduction
    • Architecture
    • Concepts
      • Collection
      • NFT2.0
      • Data Registry
      • Derivative NFT
      • Derived Account
      • Token Bound Account (aka TBA)
    • Smart Contracts
      • Interfaces
        • Factory
        • Dynamicity
        • Derivability
        • Cross chain ability
      • Use cases
        • Create collection
        • Mint NFT2.0
        • Create Data registry
        • Write onchain data
        • Retrieve onchain data
        • Mint Derivative NFT2.0
        • Create TBA
    • SDK
      • Setup
        • Create Console Account
        • Manage API key
        • Set up metadata schema
        • Initialize the SDK
      • API reference
        • Get List Collection
        • Get List Collection By Owner
        • Get Collection Info
        • Get List NFT By Collection
        • Get List NFT By Owner
        • Get List Derivative NFT By Original
        • Get NFT Info
        • Get List Data Registry
        • Get Data Registry By Owner
        • Get Data Registry Info
        • Get NFT onchain data
        • Get NFT protocol-scoped onchain data
        • Get User Freemint Info
        • Get Claim Token Uri Info
        • Upload JSON Uri Data To IPFS
        • Generate Presigned URL To Upload Image (IPFS)
        • Utility Functions
    • App guide
      • NFT2Scan
        • Create Collection
        • Mint NFT2.0
        • Mint Derivative NFT2.0
      • NFT2Console
        • Create Dapp
        • Register data schema
        • Manage API keys
        • Manage onchain data
    • References
      • Links
  • Bridge
    • Introduction
    • Bridge Token
    • Bridge NFT
  • Staking
    • Introduction
    • Validate
    • Delegate
  • Smart Contracts
    • EVM compatibility
    • Hardhat
    • Foundry
    • Account Abstraction
    • SubQuery Indexer
    • SAFE multisign
  • Nodes & Validators
    • Run a Node
    • Become a Validator
Powered by GitBook
On this page
  • Merkle Tree
  • IPFS URL converter
  • Multi chain
  1. NFT2.0
  2. SDK
  3. API reference

Utility Functions

Merkle Tree

  1. In order to generate an merkle tree with input Whitelist, SDK provides buildWhitelistMerkleTree endpoint to do so.

import { utils } from "@darenft-labs/nft2-client";
 
const data = utils.buildWhitelistMerkleTree([
  {
    address: "0x...",       // user wallet in whitelist
    tokenIdOrAmount: 5,     // FCFS: maximum NFT amount of user, FixedUri: NFT token ID
    tokenUri: 'ipfs://XXX', // tokenUri, only for FixedUri
  },
  ...
]);
 
console.log('data: ', data);
  1. Generate an leaf of merkle tree with input Whitelist, SDK provides an endpoint createWhitelistLeaf to do so

import { utils } from "@darenft-labs/nft2-client";
 
const data = utils.createWhitelistLeaf(
  "0x...",      // user wallet address
  5,            // tokenIdOrAmount
  'ipfs://XXX', // tokenUri, only for FixedUri
);
 
console.log('data: ', data);

IPFS URL converter

  1. Convert url ipfs:// to ipfs public endpoint, SDK provides convertIPFSToUri endpoint to do so.

import { utils } from "@darenft-labs/nft2-client";
 
const accessableUrl = utils.convertIPFSToUri("ipfs://XXX"); // XXX is CID on IPFS
 
console.log('url: ', accessableUrl);
  1. Convert url of an ipfs endpoint to ipfs:// format, SDK provides convertUrlToIPFS endpoint to do so.

import { utils } from "@darenft-labs/nft2-client";
 
const ipfsUrl = utils.convertUrlToIPFS("http://abc/ipfs/XXX"); // XXX is CID on IPFS
 
console.log('url: ', ipfsUrl);

Multi chain

Get network type (mainnet | testnet) of chain id, SDK provides getNetworkKey endpoint to do so

import { utils } from "@darenft-labs/nft2-client";
 
const netWorkType = utils.getNetworkKey(43113);
 
console.log('url: ', netWorkType);
PreviousGenerate Presigned URL To Upload Image (IPFS)NextApp guide

Last updated 7 months ago