Using Remix and Metamask with RSK testnet
RSK's virtual machine implementation is compatible with the Ethereum EVM, we can also use many of Ethereum's developer tools.
In this tutorial I will show you step-by-step how to use Remix and Metamask, which are tools that were originally built for Ethereum, to create and deploy a simple smart contract on RSK's Testnet.
Overview
We will do these steps:
- Configure Metamask to connect to RSK testnet;
- Get some testnet RBTCs at faucet;
- Connect Remix with RSK Testnet;
- Create a smart contract at Remix;
- Compile it;
- Using Remix, deploy the smart contract at RSK Testnet;
- Know the RSK explorer;
- Interact with the smart contract;
- Check the transactions in Metamask.
Webinar
We have run a webinar in which we run through this tutorial:
The same webinar is also available in Español and Português.
Check out our other webinars.
Translations
This article is also available in Português.
Requirements
- Metamask
- Remix
Metamask
Metamask is a kind of web wallet which facilitates transactions using yours accounts. It can be used with RSK networks too. It has versions for several browsers, like Chrome, Firefox, Opera and Brave.
Go to metamask.io and install it.
You can either use the metamask-landing.rifos.org tool to download/install Metamask, and add RSK custom network or follow the steps listed in metamask.io.
Create an account.
Write down your seed phrase, or mnemonic, or backup phrase (all these terms mean the same), with 12 words. This is used to recover your account, in case you lose your password.
The seed phrase is the most important thing in a wallet / account!
Remix
Remix is an online web tool. It is an IDE (Integrated Development Environment) used to write, compile, deploy and debug Solidity code. Can be connected with Metamask and used to deploy smart contracts to both the RSK Testnet and Mainnet.
Can be accessed at remix.ethereum.org
Connect MetaMask to RSK testnet
- Go to networks
- Custom RPC
-
Network Name
RSK Testnet
-
New RPC URL
-
ChainID (optional)
31
-
Symbol (optional)
tRBTC
-
Block Explorer URL (optional)
After configuring it, select the RSK Testnet.
TestNet Faucet
You can get some Testnet RBTC at faucet.testnet.rsk.co.
Copy your address from Metamask
Enter your wallet address and pass the CAPTCHA.
Wait a few seconds...
You can see the transaction hash, for example 0xf63c45dabd52e0b44f4cf15825985e9ddfe790b4323a88a3531f762a417f9011
.
Now I have 0.05 RBTC!
Remix
Go to
In the home / welcome page, choose environment Solidity
.
Remix Connect RSK Testnet
With the RSK network selected at Metamask...
At Remix, on the left side, locate the button Deploy and run transactions
.
For now it is the 4th button
At Environment, choose Injected Web3
Injected Web3 connects Remix with active account in Metamask
ChainID 31 was defined at RSK Testnet custom network in Metamask.
Create a smart contract
Click on the second button on the left side - file explorer
Click on + create a new file
File name: SimpleStorage.sol
Copy this example:
pragma solidity >=0.4.0 <0.7.0;
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}
And paste it here:
SimpleStorage.sol
This smart contract has:
- A variable
storedData
to store a number - A function
get()
to return the number stored at variablestoredData
- A function
set()
to change the number stored at variablestoredData
Compile a smart contract
In the 3rd button at left side click on Solidity compiler
It is useful to enable auto-compile
For now click in the button Compile SimpleStorage.sol
Check the green sign at 3rd button with the message compilation successful
Deploy a smart contract at RSK testnet
In the left side panel, go to the button Deploy and run transactions
. Actually, it is the 4th button.
For now we have only one smart contract, so it is automatically selected in the dropdown.
Click in the button Deploy
.
It will open a Metamask popup window, to confirm the transaction to create the smart contract SimpleStorage.sol
Click on confirm.
At bottom right, we can check the message: creation of SimpleStorage pending...
Once it is confirmed, we can check it
Click on the transaction line or the debug button (at the right side) to see more details of the transaction:
Copy the transaction hash to verify at blockchain explorer
Is this example, the transaction hash is:
0x419c4b17ec0bf59568d9b5f5c7f0e4678039f52b9c644c2914ccd0bd2bb331da
RSK Explorer
The RSK explorer is the blockchain explorer for RSK transactions. We will use the Testnet explorer:
Past the transaction hash at search field, at the top of the screen
This is the result:
You can verify my example at: 0x419c4b17ec0bf59568d9b5f5c7f0e4678039f52b9c644c2914ccd0bd2bb331da
Interact with the smart contract
When a smart contract is deployed with Remix, we can see it in the left panel under deploy and run transactions:
Click on > to expand SimpleStorage:
These are the same functions we created in our smart contract!
The orange buttons are functions which will change some information stored on the blockchain, we call it state changes. This kind of function expends gas when used.
The blue buttons are functions which are read-only and it does not change anything stored on the blockchain. We do not need to expend gas when using them.
Get
First of all, we will check the value stored at deploy.
Click in the button get
We do not have any value stored, because we do not define anything at the moment when we deployed.
At bottom right, we can check that it was a call to SimpleStorage.get()
function:
Set
Put a value in the field at the right side of the set button, and click on the button
It will open a Metamask popup window, to confirm the transaction to store a value.
Click on confirm
At bottom right, we can verify that the transaction is pending, waiting confirmation at blockchain:
After a few seconds, Metamask will show when the transaction has been confirmed!
At bottom right, we have the transaction’s details
You can copy the transaction hash and verify at RSK explorer too: 0xb9f4d73e7555d2b3cdf516f2d3044daa58669f7324cb957f2b83da21a6c89b4b
Get (again)
Now we have the value 2020 saved, and we can check it
Click in the button get
And the value is correct!
Transactions in Metamask
It is possible to verify all transactions in metamask
Final considerations
Did you think that it would be so easy to use Remix and Metamask to create a smart contract which can be used on both Ethereum or RSK networks?
I showed to you how we can use some Ethereum developer tools, and it is great to realize that they can be used on the RSK network as well.
Our goal is to join forces and give options to people who believe in smart contracts based on Ethereum, and also believe in the power of Bitcoin, through RSK.
I hope this tutorial has been helpful and I'd appreciate your feedback. Share it if you like it :)