Using Remix

In this tutorial, we provide guidelines on how to create, compile, and deploy a simple MLD-721 NFT on MELD using the Remix IDE.

Pre-requisites

There is no need for any local environment settings for deploying solidity smart contracts on MELD using the Remix IDE.

All you require is a browser-based Web3 wallet (e.g. MetaMask) to interact with the Kanazawa Testnet and deployed contracts. If you are already using MetaMask, it is recommended to create a new account for testing with Replit. You can do this from the account menu, which appears when you click on the account avatar in the top right corner of MetaMask interface.

You must set up all of the following pre-requisites to be able to deploy your solidity smart contract on MELD:

  • Download and Set Up MetaMask Wallet:

    • Install the MetaMask extension in your web browser.

    • Create a new wallet or import an existing one.

  • Configure Kanazawa Testnet on MetaMask:

    • Open MetaMask and select "Custom RPC" from the network dropdown.

    • Add a new network with the following details:

  • Acquire gMELD Testnet Tokens:

    • Copy your wallet address from MetaMask.

    • Visit the Kanazawa Testnet Faucet here and request test gMELD tokens.

2. Setting Up Remix IDE

  • Access Remix IDE: Go to Remix IDE.

  • Choose Solidity Compiler:

    • Navigate to the Solidity Compiler tab.

    • Select compiler version 0.8.15 or above.

3. Writing the NFT Smart Contract

  • Create a New File for NFT Contract:

    • In Remix, create a new file named MyNFT.sol.

  • Write or Paste NFT Contract Code:

    • You can write your own NFT contract or use a template like OpenZeppelin's ERC721 implementation.

    • Ensure to modify the contract to fit your requirements.

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.18;
    
    import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
    
    contract MyNFT is ERC721 {
        constructor() ERC721("MyNFT", "MNFT") {
        }
    
        function mintNFT(address to, uint256 tokenId) public {
            _mint(to, tokenId);
        }
    }

4. Compile the NFT Smart Contract

  • Compile the Contract:

    • Click the "Compile" button in the Solidity Compiler tab.

    • Ensure there are no compilation errors.

5. Deploy the NFT Smart Contract

  • Connect Remix to MetaMask:

    • Go to the "Deploy & Run Transactions" tab in Remix.

    • Select "Injected Web3" in the Environment dropdown.

    • Confirm the connection in MetaMask.

    • Make sure you are connected to the Kanazawa Testnet.

  • Deploy the Contract:

    • Select your MyNFT.sol contract.

    • Click "Deploy".

    • Confirm the transaction in MetaMask.

  • Contract Deployment:

    • After deployment, your contract will appear under the "Deployed Contracts" section in Remix.

    • Note the contract address for future reference.

6. Interact with Your Deployed NFT Contract

  • Mint an NFT:

    • In the "Deployed Contracts" section, expand your NFT contract.

    • Use the mintNFT function to mint an NFT to a specified address with a unique tokenId.

7. Verifying the Deployed Contract on MELD Block Explorer

  • Flatten the Smart Contract Code

    • Copy and Paste your smart contract into a local file on your system named as MyNFT.sol.

    • Use a package installer to install Truffle Flattener

      • For NPM run the command npm install truffle-flattener on your terminal or command prompt.

      • For Homebrew run the command brew install truffle

    • Flatten the contract by running the command in the npx truffle-flattener MyNFT.sol > FlatMyNFT.sol contracts directory

    • 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 MELD block explorer 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.

    Using Flattened Code to Verify

    At this point, you have your flattened and cleaned-up contract ready for the MELD block explorer verification.

    • Find your deployed contract by searching it using its address.

    • On the main page of MELD block explorer, on the header click Misc > Verify Contract.

    • In Compiler Type, select Solidity (Single file).

    • In Compiler Version, select v0.8.15. 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 Remix 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.

    • MELD block explorer will take a few seconds to compile your contract, verify, and publish it.

Conclusion

This tutorial walked you through the process of creating, compiling, and deploying an NFT smart contract on the MELD Blockchain's Kanazawa Testnet using Remix and MetaMask. It also covered basic interactions with the deployed contract and how to verify it on the MELD block explorer. Remember, this process is similar for both testnet and mainnet deployments, with the main difference being the network configuration in MetaMask.

Last updated