Skip to content

Basic ERC721 token with Enumerator and URI storage

Notifications You must be signed in to change notification settings

tnkerer/eggnator

Repository files navigation

EGGnator

A huge thanks to Atelier Pixerelia for the amazing assets!

🧭 Table of contents

🚀 Quick Start

✅ Clone or fork eggnator:

git clone https://github.com/menezesphill/eggnator.git

💿 Install dependencies with yarn:

cd eggnator
yarn install

💿 Install truffle for all users:

npm install -g truffle

🧆 Navigating Truffle

✅ In case of making any modifications within .sol files, you can run:

truffle compile

To update build artifacts;

✅ Check if the test checklist passes by running:

truffle test

Testing cases are not as extensive as we would like. if you want to contribute creating new test cases, please do so.

✅ Deploying contracts to local testnet:

There is a portion of the community that might be tempted to use Remix but we are not taking shortcuts. We would like to use a more "Orthodox" approach, if you will. For simplicity we will use Ganache GUI, which can be downloaded here: https://trufflesuite.com/ganache/

Upon starting Ganache, go ahead and QUICKSTART a new network, you will see a window that looks like this:

Make sure to change NETWORK ID and RPC SERVER info in your truffle-config.js file:

  networks: {
     development: {
      host: "127.0.0.1",     // Localhost
      port: 7545,            // Standard Ethereum port
      network_id: "5777",       // Any network
     },
   }

⚠️ ATENTION: If you are using a WSL instance, you might need to configure the Ethernet virtual network on Ganache in order to deploy to the testnet.

When you are good to go, you can go ahead and:

truffle migrate

Now you can also run the tests on your local testnet:

truffle test --network development

And interact with your Smart Contracts from the console:

truffle console

🪅 Publishing data to IPFS using Pinata

This contract allow you to create new ERC721 compatible tokens that accept and store URI to the NFT original artwork:

function mint(address _to, string memory _tokenURI) public returns(uint256)

✅ Getting started with Pinata

If you want to ensure verifiability and decentralization, the argument _tokenURI should be an IPFS stored file. 🪅Pinata provides an API to help you store data to the IPFS. To get started, you need to head to 🪅Pinata Website and create a free account. Once your free account is created head to the Menu on the Top-right and go to API Keys:

Pinata API Key

And click in + New Key, create a new API Key with access to pinFileToIPFS and give it the name you want. Remember to save the info in the pop-up, you will be using it in the next steps:

Pinata secret Key

With the Secret Key and API Key in hand, go ahead and create a new secrets.json file in your working directory:

touch secrets.json

Add your Secret Key and API Key to this file:

{
    "pinataApiKey": "YOURAPIKEY",
    "pinataSecretApiKey": "YOURSECRETKEY"
 }

Make sure to hide your secrets.json file in case you plan to publish or share your working directory:

echo secrets.json >> .gitignore

✅ Uploading files

If you look at the folder eggnator/img you will notice 9 images going from file (1).png to file (9).png. The script uploadFiles.js is configured to upload file (1).png using your newly created Keys from Pinata, if you configured everything correctly, you can go ahead and run:

node uploadFiles.js

If the image is uploaded correctly, you will be able to see a message on the console like this one:

{
  IpfsHash: 'QmXSS5ahu9cXTkfTzUin6XrPhxbaFktURaRzX8w86wtEFx',
  PinSize: 391,
  Timestamp: '2022-03-21T03:04:42.066Z',
}

And also, a JSON file is created at eggnator/img with the same name of its respective image. You can check out the uploaded file at:

https://gateway.pinata.cloud/ipfs/{IpfsHash}

⚠️ ATENTION: uploadFiles.js is configured to upload only file (1).png. If you want to upload different images or a different number of images, make sure to edit uploadFiles.js accordingly.

✅ Uploading Metadata

The METADATA is what you actually want as an argument for _tokenURI. The metadata file contains all information you want to make avaiable along with your newly uploaded file/image. In eggnator/metadata you can see an example of what a metadata JSON file looks like:

{
    "name":"Brown Eggo",
    "hash": "QmXSS5ahu9cXTkfTzUin6XrPhxbaFktURaRzX8w86wtEFx", // IpfsHash from previous step
    "gen": "0",
    "image" : "https://gateway.pinata.cloud/ipfs/QmXSS5ahu9cXTkfTzUin6XrPhxbaFktURaRzX8w86wtEFx" // Ipfs link generated in previous step
  }

You can add whatever metadata you'd like, but "name", "hash" and "image" have to be there if you want your ERC721 token to be displayed correctly on OpenSea or any other marketplace.

Upload the metadata by using:

node uploadMetadata.js

uploadMetadata.js and uploadFiles.js are the same, they are two separated files for didactic reasons. Like before, if uploaded correctly, the console will show something like:

{
  IpfsHash: 'QmZcpMmryMAQ1TyTRSCXkfffx8snA1zQtcemKBqUC8tdK9',
  PinSize: 217,
  Timestamp: '2022-03-21T15:56:16.420Z'
}

You can again check the uploaded file at:

https://gateway.pinata.cloud/ipfs/{IpfsHash}

Note it is a different IpfsHash from the one in ✅ Uploading files !!!

🍾 Minting

Try ou minting your new ERC721 using truffle. On your project folder, run:

truffle migration --network development

And run truffle console:

truffle console --network development

On truffle console, instantiate the Eggnator contract you just created and then use the mint method:

contract = await Eggnator.deployed()
contract.mint(accounts[0], "https://gateway.pinata.cloud/ipfs/{IpfsHash_from_Metadata_file}")

You can check if the tokenURI is correctly set by calling the methods tokenURI(_tokenID)

contract.tokenURI("1")

You should see your IPFS CID:

'https://gateway.pinata.cloud/ipfs/{IpfsHash_from_Metadata_file}'

You can also deploy to different testnets. If you deploy to Rinkeby, for example, you will be able to see your collection on OpenSea Testnet and Rarible on Rinkeby:

Eggnator on OpenSea

For more details on deploying on different testnets using Truffle, THIS article can help you out!

About

Basic ERC721 token with Enumerator and URI storage

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published