This example uses Flair SDK to mint new NFTs from your backend using meta transactions. In this approach you will configure a private key that has the "minter" role on your NFT collection (or is contract owner -- which is less secure).
We're going to use "Digital Asset Collection" collection, which is using OneOfOneExtension, and will mint NFTs with dedicated dynamic metadata and image URI. This means each NFT will have it's own metadata and image IPFS URI.
- Node.js
- Express
flair-sdk
: latest- An Ethereum-compatible wallet private key (either via Javascript using MetaMask)
-
Create and deploy a Digital Asset Collection under 2 minutes via Flair's Collections.
-
Create your first API Key if not already done via Flair's API Keys.
-
Clone this repo and navigate to the example directory:
git clone https://github.com/0xflair/examples cd examples/nodejs/express/mint-one-of-one-nft-meta-transactions npm install
-
Copy
.env.dist
and create a new.env
file:cp .env.dist .env
-
Put the correct values in
.env
file:- FLAIR_CLIENT_ID: copy from step2 above.
- CONTRACT_CHAIN_ID: based on the chain you used to deploy the contract.
1
for Eth mainnet,4
for Rinkeby testnet,137
for Polygon mainnet, etc. - MINTER_PRIVATE_KEY: the private key of your wallet, or a new wallet you created just for minting.
-
If you're using a minter wallet other than your contract owner, give that minter address "MINTER_ROLE", so it can mint NFTs:
- Go to your collection dashboard
- Go to "Roles" admin section
- Paste your minter address, and click on "Grant role".
-
Allow Flair's trusted forwarder to send meta-transactions to your collection:
- Go to your collection dashboard
- Go to "Minting" admin section, scroll down to "Backend minting" card.
- Configure your trusted forwarder address with the value of Flair's latest trusted forwarder shown at the bottom of the same card.
-
Start the test server:
npm start
-
Open the test endpoint in your browser to mint the first NFT:
Our developers are happy to help you debug issues and problems, join our Discord and drop a message.