πŸ—»Decarbonize Your Travel

Create, mint, and deploy an NFT to decarbonize your travel using Co2.storage, the FVM Hyperspace Testnet & Remix:

Overview

  1. Create your Decarbonized Travel Asset using form.co2.storage.

  2. Connect to the Filecoin Hyperspace testnet & get some TFIL from the faucet

  3. Create & customize a DecarbonizedTravelNFT Contract in Solidity using Open Zeppelin Contracts Wizard

  4. Deploy the DecarbonizedTravelNFT Contract to the Filecoin Virtual Machine (FVM) Hyperspace Testnet with Remix

  5. Interact with the DecarbonizedTravelNFT Contract & mint your NFT using the asset created on co2.storage.

Create your Decarbonized Travel Asset using form.co2.storage

For this tutorial, we'll be creating an NFT that represents your travel decarbonized on the Filecoin Network.

  1. Fill out the first three fields of the decarbonization form.

    • Attendee Name is your name

    • Emissions Description is a short summary of the travel you are decarbonizing, including your name, the event, and the mode of travel

    • Emissions Amount kg is the amount of CO2 emitted by your travel. For flights, use the ICAO Calculator.

  2. We will retire an offset for you on the Regen Network and add its transaction hash in the sheet. If you want to look it up, use the explorer at https://www.mintscan.io/regen/txs/<TxHash> (example)

  3. Complete the decarbonized travel form to generate an asset on Co2.storage attesting that your travel was decarbonized. In the provenance section, enter your name and choose CC-O.

  4. Note the CID (Content Identifier) that is returned. We'll need this CID later when we mint the NFT.

Connect to the Filecoin Hyperspace testnet & get some TFIL from the faucet

We need to point your wallet to the Filecoin Network, specifically the Hyperspace testnet. We’ll use a website called chainlist.org to give MetaMask the information it needs quickly.

Connect to the Filecoin Hyperspace testnet

  1. Go to chainlist.org & enable the Testnets toggle and enter Filecoin into the search bar.

  1. Scroll down to find the Filecoin – Hyperspace testnet & connect your wallet to the testnet.

  1. Connect network through Metamask & approve when prompted:

In MetaMask click Next:

Get some TFIL from the faucet:

Test-filecoin (TFIL) is FIL that has no value in the real world, and developers use it for testing. We’ll grab some TFIL now.

Go to hyperspace.yoga and click Faucet from the menu:

Create a DecarbonizedTravelNFT Contract in Solidity

The DecarbonizedTravelNFT Smart Contract is based on Open Zeppelin's implementation of ERC721 but uses the ERC721URIStorage version, which includes the metadata standard extensions (so we can pass in our IPFS-addressed metadata - which we've saved on CO2.Storage, to the contract).

We'll be using the Open Zeppelin Contracts Wizard to create our DecarbonizedTravelNFT Contract. Follow along below πŸ‘‡πŸΌ.

Using Open Zeppelin Contracts Wizard:

Head to the Open Zeppelin wizard and select the option for ERC721 as seen below.

The DecarbonizedTravelNFT Contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract DecentralizedTravelNFT is ERC721, ERC721Enumerable, ERC721URIStorage, Ownable {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;

    constructor() ERC721("DecentralizedTravelNFT", "DTN") {}

    function _baseURI() internal pure override returns (string memory) {
        return "https://ipfs.io/ipfs/QmWAtvTBkUKeifvUSu6XA2uFDUQBgmL3U1pTnbgqrHhton?filename=decarbonized%20travel%20photo.png";
    }

    function safeMint(address to, string memory uri) public onlyOwner {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri);
    }

    // The following functions are overrides required by Solidity.
    function _beforeTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
        internal
        override(ERC721, ERC721Enumerable)
    {
        super._beforeTokenTransfer(from, to, tokenId, batchSize);
    }

    function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {
        super._burn(tokenId);
    }

    function tokenURI(uint256 tokenId)
        public
        view
        override(ERC721, ERC721URIStorage)
        returns (string memory)
    {
        return super.tokenURI(tokenId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721, ERC721Enumerable)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }
}

Deploy the DecarbonizedTravelNFT Contract to the Filecoin Virtual Machine (FVM) Hyperspace Testnet

Requirements

We'll be deploying this contract to the Filecoin Virtual Machine Hyperspace Testnet. To deploy to Hyperspace Testnet we'll need to have:

  1. Set up & connected Metamask Wallet to Hyperspace Testnet

  2. Received some test tFIL funds from a faucet (Yoga or Zondax)

Create your workspace

The development environment we’re going to be using is called Remix. Let’s create a new workspace to create our ERC-721 Decarbonized Travel NFT.

Open remix.ethereum.org & click the + icon next to Workspaces to create a new workspace:

Customize the Decarbonized NFT contract

In the editor panel, replace MyToken with whatever you’d like to name your NFT Contract. In this example, we’ll use DecarbonizedTravelNFT.

Compile the Decarbonized NFT contract

Click the green play symbol at the top of the workspace to compile your contract. You can also press CMD + s on MacOS or CTRL + s on Linux and Windows.

Deploy the Decarbonized NFT contract

Now that we’ve successfully compiled our contract, we need to deploy it to the Filecoin Hyperspace testnet! This is where our previous MetaMask setup comes into play.

Click the Deploy tab from the left.

Interact with the DecarbonizedTravelNFT Contract & mint your NFT

Now that we’ve compiled and deployed the contract, it’s time to actually interact with it! We’re going to call a method within the deployed contract to mint an NFT.

Mint your DecarbonizedTravelNFT

Back in Remix, open the Deployed Contracts dropdown, within the Deploy sidebar tab.

Add to Metamask & import your NFT:

Currently, MetaMask has no idea what our NFT is or what it even does. We can fix this by explicitly telling MetaMask the address of our contract.

Go back to Remix and open the Deploy sidebar tab. Under Deployed Contracts, you should see your contract address at the top. Click the copy icon to copy the address to your clipboard:

✨ You should now be able to see that you have 1 Decarbonized Travel NFT within your wallet! ✨

Last updated