EVM NFT Creation
A developers guide to creating NFTs on EVM blockchains which are compatible with GhostMarket
Introduction
This page provides a step-by-step guide for deploying GhostMarket compatible NFTs on supported EVM compatible blockchains (Avalanche, BSC, Polygon, Ethereum, Base).
The NFT creation process requires interaction with the blockchain. For retrieving existing NFT metadata, see Accessing NFT data, which uses the GhostMarket APIs.
The snippets used in this guide are javascript and the contract addresses used are for the BSC contracts. For other EVM chains, please adjust using the appropriate contract addresses specified in the Contracts page.
The code snippets also assume a node.js environment.
See our Metadata Reference for full details and requirements of GhostMarket NFT metadata.
NFT Creation
The NFT creation process on all blockchains broadly consists of the following steps.
Prepare Off-Chain Media and persist it
Assemble On/Off-Chain Metadata
Persist Off-Chain metadata
Build a transaction
Sign the transaction
Broadcast to the blockchain
1. Prepare your Off-Chain Media
The preferred decentralized platform for persisting image/media data for your NFT is IPFS.
This guide will use Piñata to upload and pin your images to IPFS.
Set up a Piñata account and get started here.
You can either manually upload you metadata, noting the IPFS hash, or dive into the Pinata js-sdk to interact with Piñata programatically.
Be sure to note the IPFS hash of the uploaded metadata, you will need it in the following step.
Prepare the Web3 javascript environment
Install the web3 javascript module
Import the Web3 module and set up Web3
This sample assumes node.js, for browser and metamask development, adapt the provider and wallet connection appropriately.
Download and save the contact ABI using the relevant explorer (e.g. BSC ERC721) and store it locally. Node.js allows us to "require" it directly into the ABI objects.
After downloading the contract ABI, be sure to edit the file so it contains only the value of the "result" object
e.g. [{ "anonymous" true ... }]
2. Assemble On/Off-Chain Metadata
GhostMarket supports both ERC721 and ERC1155 NFT token standards on EVM platforms. The metadata setup is identical, however the contract parameters differ. We highlight these differences below.
GhostMarket EVM NFT contracts provide the option to store metadata on, or off chain as a JSON string. However, because of the high cost of storing Metadata on-chain, we will be storing the metadata off-chain.
Build the metadata:
3. Persist metadata to IPFS
Since this example uses Off-chain persistence of the NFT metadata. Upload the metadata to IPFS using the same process as persisting the media and again.
Be sure to note the IPFS hash, we will use this below.
4. Build the transaction
The royalties and lockedContent are parameters to the contract method, so these are prepared first.
This code snippet constructs the contract & method objects for both the ERC721 & ERC1155 contracts. Use the contract which corresponds to your use case.
5. Sign the Transaction
Not needed here. In this sample, signing is done as part of the Web3 Broadcast.
6. Broadcast the Transaction to the network
That's it, you've created and persisted a GhostMarket compatible NFT.
For clarity, all of the above snippets exclude error and promise handling for clarity. Production code should include thorough exception management and handle promises appropriately.
Last updated