Using Remix

Interacting Remix with CLV

This guide shows how to create and deploy a Solidity-based smart contract to a CLV standalone node using the Remix IDE.

Remix is one of the most popular Solidity IDE used to write, compile and debug Solidity code. With CLV Ethereum compatibility features, Remix can be used directly with a CLV node.

This guide assumes that you have a running local CLV node running in --dev mode, and that you have a MetaMask installation configured to use this local node. If you don't know how to do it, you can find instructions for running a local CLV node here and to connect MetaMask to it here.

Checking Prerequisites

We assume you have followed the guides above, and have a local CLV node producing blocks. It should look like this:

And you should have installed MetaMask connected to your local CLV dev node. You should have at least one account that has a balance. It should look like this (expanded view):

Getting Started with Remix

Now that we can start with Remix to exercise some advanced functionalities in CLV.

To launch Remix, you need to navigate to https://remix.ethereum.org/. In the main screen, select Solidity to configure Remix for Solidity development, then navigate to the File Explorers view:

Now we can create a new file to save the Solidity smart contract. Click the "+" button under "File Explorers" at the top left. Give it a name "MyToken.sol" in the popup box.

Now paste the following smart contract code into the editor tab on the right side:

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

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0/contracts/token/ERC20/ERC20.sol";

contract Token is ERC20 {

    constructor (uint256 initialSupply) public ERC20("MyToken", "ABC") {
        _mint(msg.sender, initialSupply);
    }
}

This is a simple ERC-20 contract based on the current Open Zeppelin ERC-20 template. It creates MyToken with symbol ABC and mints the entirety of the initial supply to the creator of the contract.

Now the editor should look like this:

Now navigate to the compile sidebar option first and then click the β€œCompile MyToken.sol” button at the bottom left:

You will see Remix download all of the Open Zeppelin dependencies and compile the contract.

Deploying a Contract to CLV Using Remix

To deploy the contract, you need to navigate to the Deployment sidebar option on the left. Change the topmost β€œEnvironment” dropdown from β€œJavaScript VM” to β€œInjected Web3”. Thus you can use the MetaMask injected provider, which will point it to your CLV standalone node.

Note that you should allow Remix to access your MetaMask account after selecting "Injected Web3", by clicking the "Next" and then the "Connect" button.

Now you should see the account in metamask showing up on the Remix side, ready for deployment. Let’s specify an initial supply of 5M tokens in the box next to the Deploy button. Since this contract uses the default of 18 decimals, the value is 5000000000000000000000000.

Then, click the Deploy button. You will need to confirm the contract deployment transaction in Metamask.

After the deployment is complete, you will see the transaction record listed in MetaMask. Also, the contract will appear under Deployed Contracts in Remix.

After the contract is deployed, you can interact with it from within Remix.

Now you can try clicking on name, symbol, and totalSupply. There should return β€œMyToken,” β€œABC,” and β€œ5000000000000000000000000” respectively. If you copy the address and paste it into the balanceOf field, you should see the entirety of the balance of the ERC20 as belonging to that user.

Interacting with a CLV-based ERC-20 from MetaMask

To add the newly deployed ERC-20 tokens, you need to copy the contract's address from Remix first. Then back in MetaMask, click on β€œAdd Token” as shown below. Make sure you are in the account that deployed the token contract.

Paste the copied contract address into the β€œCustom Token” field. The β€œToken Symbol” and β€œDecimals of Precision” fields should automatically show up.

Then click the β€œNext” and then the β€œAdd Tokens” button, you should see a balance of 5M MyTokens in MetaMask:

Now we can send some of these ERC-20 tokens to the other account. Hit β€œsend” to initiate the transfer of 500 MyTokens. Select the destination account and hit β€œnext,” you will be asked to confirm this transaction as shown below.

Click β€œConfirm” to send. After the transaction is complete, you will see a confirmation and a reduction of the account balance from the sender account in MetaMask:

If you own the account which you send to, you can check the account balance to verify that the transaction has been successfully.

Last updated