Skip to content

eabdelmoneim/nftlabs-sdk-example

 
 

Repository files navigation

thirdweb-sdk-example

A starter project with:

Environment Variables

PRIVATE_KEY=<wallet private key with 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 thirdweb.com>

Usage (pseudocode)

Client Side (React):

Fetching all NFTs available in the module. Source

const sdk = new ThirdwebSDK(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 ThirdwebSDK(
  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

Languages

  • TypeScript 99.3%
  • Shell 0.7%