This example uses Flair SDK to mint new ERC-721 NFTs from your backend using meta transactions. In this approach you will configure a private key that has the "MINTER_ROLE" on your NFT contract.
- Node.js
- Typescript
- Express
@flair-sdk/metatx
- An Ethereum-compatible wallet private key (either via Javascript using MetaMask)
-
Create a new wallet (address and private key) that is dedicated for minting from your backend.
- The private key of this wallet must be stored securely in your backend.
- Your Node.js server will use it to sign the meta-transactions in backend and send the relay requests to Flair.
- Note that Flair cannot tamper with the request in anyway, it only handles the nonce and gas management complexity.
-
Create and deploy an ERC-721 contract via Flair's Contracts dashboard.
- Choose a ERC-721 contract solution.
- Make sure all required configs are set (the yellow warnings), such as max supply, etc.
- Go to "Access" section under "Grant roles" paste the address of your minter wallet to grant the "MINTER_ROLE" role.
- Go to "Relayer" section and configure the trusted forwarder address as described. Flair's trusted forwarder source code is open and it only handles the standard ERC-2771 meta transaction relaying.
- Finally deploy the ERC-721 NFT contract to get the contract address.
-
Create your first relayer API client if not already done via Flair's Relayer API dashboard.
-
Clone this repo and navigate to the example directory:
git clone https://github.com/flair-sdk/examples cd examples/express/mint-erc721-with-metadata 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 Step 4 above.
- CONTRACT_CHAIN_ID: based on the chain you used to deploy the contract.
1
for Eth mainnet,5
for Goerli testnet,137
for Polygon mainnet, etc. - CONTRACT_ADDRESS: find the address of the deployed contract under "Deploy" section.
- MINTER_PRIVATE_KEY: the private key of the new wallet you created for minting.
-
Build the project to get javascript files based on typescript code:
npm run build
-
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.