Minting with viem

For developers who prefer granular control over the minting process, you can use vanilla TypeScript with viem, a TypeScript interface for EVM-based projects. The Ethers.js library is also a robust approach.

Going vanilla requires you to perform a bit more work than when relying on frameworks such as thirdweb. For instance, unless you run your own IPFS node, you will need to rely on an NFT storage platforms, which are for-pay.

Now, let's install viem, the Pinata SDK, and the dotenv module:

npm i viem pinata dotenv

Configure your .env file to work with your needs:

# Wallet / contract
PRIVATE_KEY=0xabc...                      # server-side only
CONTRACT_ADDRESS=0xYourErc721Address
RECIPIENT=0xRecipientOrLeaveEmpty         # optional; defaults to minter

# Pinata
PINATA_JWT=eyJhbGciOi...                  # JWT from Pinata dashboard
PINATA_GATEWAY=your-subdomain.mypinata.cloud

# Single mint
IMAGE_PATH=./art/image.png
NAME=My Chiliz NFT
DESCRIPTION=Minted on Chiliz with viem

# Batch mint
IMAGES_DIR=./art
NAME_PREFIX=My Chiliz NFT
BATCH_DESCRIPTION=Batch minted on Chiliz with viem

Now, let's dive into the code. Take inspiration from it, don't use as-is!

Minting a single NFT

Minting a collection of NFTs

Last updated

Was this helpful?