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:
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