A starter project with:
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>
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();
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),
},
})