TLDR:
ERC-721 is the non-fungible token (NFT) standard for smart contracts.
In this tutorial, you will:
To get from zero to a deployed ERC-721 contract on the Fantom testnet, do the following:
With Chainstack, create a .
With Chainstack, join the Fantom testnet.
With Chainstack, access your Fantom node credentials.
With OpenZeppelin, create an ERC-721 contract.
With Truffle, compile and deploy the contract through your Fantom node.
With FTMScan, verify the deployed contract.
See Create a project.
See View node access and credentials.
See Truffle Suite: Installation.
On your machine, in the contract directory, initialize Truffle:
This will generate the Truffle boilerplate structure:
Go to the contracts
directory. In the directory, create your ERC-721 contract Fantom721Collection.sol
.
The contract implementation is the following:
createCollectible
.Create 2_deploy_contracts.js
in the migrations
directory.
This will create the contract deployment instructions for Truffle.
Install HDWalletProvider
.
HDWalletProvider is Truffle’s separate npm package used to sign transactions.
Run:
Edit truffle-config.js
to add:
HDWalletProvider
Your Fantom node access and credentials
Your Fantom account that you will use to deploy the contract.
where
testnet
— any network name that you will pass to the truffle migrate --network
command.HDWalletProvider
— Truffle’s custom provider to sign transactions.network_id
— the network ID of the Fantom network: mainnet is 250
, testnet is 4002
.solc
— the Solidity compiler version that Truffle must use.Run:
This will engage 2_deploy_contracts.js
and deploy the contract to the Fantom testnet as specified in truffle-config.js
.
Once your contract is deployed, you can view it online at FTMScan testnet.
For an easy way to interact with your deployed contract, verify it on FTMScan.
Since your ERC-721 contract uses imported OpenZeppelin libraries, you must put all the imports into one .sol
file to make FTMScan be able to verify it.
Install Truffle Flattener.
Run:
Flatten the contract.
In the contracts
directory, run:
Clean up the licensing information.
The flattened contract will have the same licensing note imported from each of the files. Multiple licensing notes in one file break the FTMScan verification, so you have to leave one licensing note for the entirety of the flattened contract.
The easiest way to clean up is to search for the SPDX
mentions in the file and remove all of them except for the very first one.
At this point, you have your flattened and cleaned-up contract ready for the FTMScan verification.
Go to FTMScan testnet.
Find your deployed contract. The address of your contract should have been printed by Truffle at the end of the deployment in the contract address
field.
On the contract page on FTMScan, click Contract > Verify and Publish.
In Compiler Type, select Solidity (Single file).
In Compiler Version, select v0.8.9. This is the version this tutorial used to compile the contract.
In Open Source License Type, select MIT License (MIT).
Click Continue.
Keep the Optimization option set to No as Truffle does not use optimization by default.
Paste the entirety of your flattened .sol
contract in the Enter the Solidity Contract Code below field.
Click Verify and Publish.
FTMScan will take a few seconds to compile your contract, verify, and publish it.
Now that your ERC-721 contract is verified, FTMScan is effectively a front-end instance for your contract.
You can use any account to call the createCollectible
function.
Make sure you have:
On FTMScan, on your contract, click Contract.
Click Write Contract.
Click Connect to Web3.
Under createCollectible, in the tokenURI field, provide any string to serve as metadata for this specific NFT. See also OpenZeppelin ERC-721 for a metadata example.
Click Write.
This will send a transaction to mint in NFT in your contract collection and distribute the token to the account called createCollectible
.
Check the NFT balance of an address:
On FTMScan, on your contract, click Contract.
Click Read Contract.
Scroll to the balanceOf field.
In the owner (address) field, provide the address of the account you used to deploy the contract.
Click Query.
Check the number of minted NFTs
On FTMScan, on your contract, click Contract.
Click Read Contract.
Check the tokenCounter field.
Having gone through the tutorial to understand the basics of creating an NFT collection, you can amend the contract to your needs and deploy it on the Fantom mainnet.
Once deployed, you can list the collection at an NFT marketplace—Artion.
See Artion: Register Collection.
This tutorial guided you through the basics of creating and deploying a contract in the ERC-721 non-fungible token standard.
The contract that you created is a collection that anyone on the Fantom network can interact with to add their tokens to the collection.
When you are ready, you can also deploy your own ERC-721 contract on the Fantom mainnet and list the collection on a Fantom NFT marketplace.
This tutorial uses testnet, however, the exact same instructions and sequence work on the mainnet.
TLDR:
ERC-721 is the non-fungible token (NFT) standard for smart contracts.
In this tutorial, you will:
To get from zero to a deployed ERC-721 contract on the Fantom testnet, do the following:
With Chainstack, create a .
With Chainstack, join the Fantom testnet.
With Chainstack, access your Fantom node credentials.
With OpenZeppelin, create an ERC-721 contract.
With Truffle, compile and deploy the contract through your Fantom node.
With FTMScan, verify the deployed contract.
See Create a project.
See View node access and credentials.
See Truffle Suite: Installation.
On your machine, in the contract directory, initialize Truffle:
This will generate the Truffle boilerplate structure:
Go to the contracts
directory. In the directory, create your ERC-721 contract Fantom721Collection.sol
.
The contract implementation is the following:
createCollectible
.Create 2_deploy_contracts.js
in the migrations
directory.
This will create the contract deployment instructions for Truffle.
Install HDWalletProvider
.
HDWalletProvider is Truffle’s separate npm package used to sign transactions.
Run:
Edit truffle-config.js
to add:
HDWalletProvider
Your Fantom node access and credentials
Your Fantom account that you will use to deploy the contract.
where
testnet
— any network name that you will pass to the truffle migrate --network
command.HDWalletProvider
— Truffle’s custom provider to sign transactions.network_id
— the network ID of the Fantom network: mainnet is 250
, testnet is 4002
.solc
— the Solidity compiler version that Truffle must use.Run:
This will engage 2_deploy_contracts.js
and deploy the contract to the Fantom testnet as specified in truffle-config.js
.
Once your contract is deployed, you can view it online at FTMScan testnet.
For an easy way to interact with your deployed contract, verify it on FTMScan.
Since your ERC-721 contract uses imported OpenZeppelin libraries, you must put all the imports into one .sol
file to make FTMScan be able to verify it.
Install Truffle Flattener.
Run:
Flatten the contract.
In the contracts
directory, run:
Clean up the licensing information.
The flattened contract will have the same licensing note imported from each of the files. Multiple licensing notes in one file break the FTMScan verification, so you have to leave one licensing note for the entirety of the flattened contract.
The easiest way to clean up is to search for the SPDX
mentions in the file and remove all of them except for the very first one.
At this point, you have your flattened and cleaned-up contract ready for the FTMScan verification.
Go to FTMScan testnet.
Find your deployed contract. The address of your contract should have been printed by Truffle at the end of the deployment in the contract address
field.
On the contract page on FTMScan, click Contract > Verify and Publish.
In Compiler Type, select Solidity (Single file).
In Compiler Version, select v0.8.9. This is the version this tutorial used to compile the contract.
In Open Source License Type, select MIT License (MIT).
Click Continue.
Keep the Optimization option set to No as Truffle does not use optimization by default.
Paste the entirety of your flattened .sol
contract in the Enter the Solidity Contract Code below field.
Click Verify and Publish.
FTMScan will take a few seconds to compile your contract, verify, and publish it.
Now that your ERC-721 contract is verified, FTMScan is effectively a front-end instance for your contract.
You can use any account to call the createCollectible
function.
Make sure you have:
On FTMScan, on your contract, click Contract.
Click Write Contract.
Click Connect to Web3.
Under createCollectible, in the tokenURI field, provide any string to serve as metadata for this specific NFT. See also OpenZeppelin ERC-721 for a metadata example.
Click Write.
This will send a transaction to mint in NFT in your contract collection and distribute the token to the account called createCollectible
.
Check the NFT balance of an address:
On FTMScan, on your contract, click Contract.
Click Read Contract.
Scroll to the balanceOf field.
In the owner (address) field, provide the address of the account you used to deploy the contract.
Click Query.
Check the number of minted NFTs
On FTMScan, on your contract, click Contract.
Click Read Contract.
Check the tokenCounter field.
Having gone through the tutorial to understand the basics of creating an NFT collection, you can amend the contract to your needs and deploy it on the Fantom mainnet.
Once deployed, you can list the collection at an NFT marketplace—Artion.
See Artion: Register Collection.
This tutorial guided you through the basics of creating and deploying a contract in the ERC-721 non-fungible token standard.
The contract that you created is a collection that anyone on the Fantom network can interact with to add their tokens to the collection.
When you are ready, you can also deploy your own ERC-721 contract on the Fantom mainnet and list the collection on a Fantom NFT marketplace.
This tutorial uses testnet, however, the exact same instructions and sequence work on the mainnet.