Skip to content

gabriel-horvat/nftlabs-sdk-example

Repository files navigation

nftlabs-sdk-example

A starter project with:

Environment Variables

PRIVATE_KEY=<wallet private key with admin/minter role>
NEXT_PUBLIC_RPC_URL=<alchemy / infura / rpc url. defaults to Polygon Mumbai public rpc if left empty>
NEXT_PUBLIC_NFT_MODULE_ADDRESS=<NFT module address from console.nftlabs.co>

Usage (pseudocode)

Client Side (React):

Fetching all NFTs available in the module. Source

const sdk = new NFTLabsSDK(library.getSigner());
const nft = sdk.getNFTModule(
  process.env.NEXT_PUBLIC_NFT_MODULE_ADDRESS as string
);
...
const tokens = await nft.getAll();

Server Side (REST API Handler):

Minting NFTs with random properties. Source

// connect to wallet with minter permission
const sdk = new NFTLabsSDK(
  new ethers.Wallet(
    process.env.PRIVATE_KEY as string,
    ethers.getDefaultProvider(process.env.NEXT_PUBLIC_RPC_URL)
  )
);

const nft = sdk.getNFTModule(
  process.env.NEXT_PUBLIC_NFT_MODULE_ADDRESS as string
);

...
const token = await nft.mintTo(account, {
  name: `${type} sword - ${rarity}`,
  description: `The special ${type} sword crafted for ${account}`,
  image: image,
  properties: {
    type: type,
    rarity: rarity,
    element: sample(["fire", "water", "earth", "lightning", "wind"]),
    attack: getRandomInt(10, 30),
  },
})

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published