Back to blog
How to Deploy an ERC-721 NFT on Robinhood Chain with IPFS
An NFT can still be in your wallet long after its image has stopped loading. The contract keeps recording who owns the token, but the website that hosted the artwork is gone, and nothing on-chain can bring the file back.
This happens because the artwork and description often live outside the contract. ERC-721’s metadata extension provides a tokenURI() function that points to a JSON document, which in turn can point to an image. Those references depend on how the creator stores the files. (ERC-721 specification)
IPFS lets us reference files by their content. Changing the artwork or metadata produces a different content identifier, or CID. Someone else can preserve the original files under their existing CIDs, so their availability can extend beyond the creator’s website. The files still need continued pinning to remain available. (IPFS content identifiers, persistence)
We’ll use Pinata to upload an image and its metadata, then deploy an ERC-721 contract on Robinhood Chain Testnet. Deployment will mint one NFT to your wallet and fix its metadata reference.
Before you begin
You’ll need:
- Foundry and Git installed.
- A test wallet with ETH on Robinhood Chain Testnet.
- A Pinata account.
- An image saved as
artwork.png.
Robinhood Chain is EVM-compatible, so we can use Solidity and Foundry for this example.
1. Upload the artwork and metadata
Upload artwork.png to public IPFS through the Pinata dashboard. Copy its CID.
Create a file named metadata.json:
{
"name": "Chain Keepsake #1",
"description": "A collectible minted on Robinhood Chain Testnet.",
"image": "ipfs://YOUR_ARTWORK_CID"
}Replace YOUR_ARTWORK_CID with the image’s CID and customize the name and description. Upload the completed JSON file to public IPFS through Pinata, then copy its CID.
You now have two references:
Artwork: ipfs://YOUR_ARTWORK_CID
Metadata: ipfs://YOUR_METADATA_CIDThe NFT will reference the metadata. The metadata’s image field references the artwork.
2. Create the project
Initialize a Foundry project and install a specific OpenZeppelin release:
forge init robinhood-nft
cd robinhood-nft
forge install OpenZeppelin/[email protected]Replace the generated foundry.toml with:
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
solc = "0.8.30"
evm_version = "cancun"
remappings = [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/"
]This fixes the compiler, EVM target, and dependency path for the example.
Forge init also creates sample Counter files in src/, test/ and script/. You can leave them or delete them; they don't affect this tutorial.
3. Create the NFT contract
Create src/ChainKeepsake.sol:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {ERC721} from
"@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {ERC721URIStorage} from
"@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
contract ChainKeepsake is ERC721URIStorage {
constructor(string memory metadataURI)
ERC721("Chain Keepsake", "KEEP")
{
_safeMint(msg.sender, 1);
_setTokenURI(1, metadataURI);
}
}OpenZeppelin’s ERC721URIStorage provides storage for each token’s metadata URI. Our constructor mints token 1 to the deploying wallet and assigns the reference passed during deployment. (OpenZeppelin ERC-721 documentation)
This contract creates a single NFT. It has no function for minting another token or changing the metadata URI, so check your uploaded files before deploying.
Compile it:
forge build4. Deploy and mint on Robinhood Chain Testnet
Import your test wallet into Foundry’s encrypted keystore:
cast wallet import robinhood-nft-deployer --interactiveEnter the private key when prompted, then choose a keystore password. Use a wallet intended for testing.
The prompt hides your input, so nothing appears as you paste or type. Paste the private key once (0x followed by 64 hex characters) and press Enter. An "invalid string length" or "odd number of digits" error usually means the key was pasted incompletely, or the wallet address was pasted instead.
Set the testnet RPC URL and your metadata reference:
export RH_RPC_URL="https://rpc.testnet.chain.robinhood.com"
export NFT_METADATA_URI="ipfs://YOUR_METADATA_CID"Replace YOUR_METADATA_CID with the JSON file’s CID.
Check the network:
cast chain-id --rpc-url "$RH_RPC_URL"The result should be 46630, the Robinhood Chain Testnet chain ID.
Deploy the contract:
forge create src/ChainKeepsake.sol:ChainKeepsake \
--rpc-url "$RH_RPC_URL" \
--account robinhood-nft-deployer \
--broadcast \
--constructor-args "$NFT_METADATA_URI"Foundry will prompt for your keystore password. Deployment also mints the NFT, so there’s no separate mint transaction.
Copy the address printed beside Deployed to:
export NFT_ADDRESS="0xYOUR_DEPLOYED_CONTRACT_ADDRESS"5. Check the owner and follow the metadata
Read the owner of token 1:
cast call "$NFT_ADDRESS" \
"ownerOf(uint256)(address)" 1 \
--rpc-url "$RH_RPC_URL"The result should match your deploying wallet.
Read the token’s metadata reference:
cast call "$NFT_ADDRESS" \
"tokenURI(uint256)(string)" 1 \
--rpc-url "$RH_RPC_URL"The result should match NFT_METADATA_URI.
Cast prints string values in quotation marks, so the result will look like "ipfs://...". The quotes aren't part of the stored URI.
Next, open the metadata through your Pinata gateway, substituting your gateway subdomain and metadata CID:
https://YOUR_GATEWAY.mypinata.cloud/ipfs/YOUR_METADATA_CIDCheck that the JSON contains the expected name and description. Take the CID from its image field and open the artwork through the same gateway:
https://YOUR_GATEWAY.mypinata.cloud/ipfs/YOUR_ARTWORK_CIDKeep both files pinned. Anyone preserving the NFT’s supporting files will need the metadata and the artwork it references.
Happy Pinning.