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.
RSK is an open-source platform for Ethereum compatible smart contracts based on the Bitcoin network. RSK’s virtual machine implementation is compatible with the Ethereum EVM, so we can also use many of Ethereum’s developer tools.
We will do these steps:
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.
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 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
RSK Testnet
31
tR-BTC
Take a look in all fields:
After configuring it, select the RSK Tesnet.
You can get some Testnet R-BTC in the faucet
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!
You can use the faucet only once a day!
Go to Remix
In the home / welcome page, choose environment Solidity.
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 the active account in Metamask.
ChainID 31 was defined at RSK Testnet custom network in Metamask.
Click on the second button on the left side - file explorers
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:
This smart contract has:
storedData
to store a numberget()
to return the number stored at variable storedData
set()
to change the number stored at variable storedData
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 3th button with the message compilation successful
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 select at 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 transaction line or debug button (at 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
The RSK explorer is the blockchain explorer to RSK transactions.
We will use the testnet explorer:
Past the transaction hash at search field, in the top of the screen:
You can verify my example at:
0x419c4b17ec0bf59568d9b5f5c7f0e4678039f52b9c644c2914ccd0bd2bb331da
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 them state changes. This kind of function expends gas when used.
The blue buttons are functions that are read-only and it does not change anything stored on the blockchain. We do not need to expend gas when using them.
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:
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 in 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
Now we have the value 2020 saved, and we can check it.
Click in the button get
And the value is correct!
It is possible to verify all transactions in Metamask:
Wait for the next article where we will teach you how to create a frontend for our smart contract.
Check out the RSK developers portal.
We have run a webinar in which we run through this tutorial, in different languages:
| |
Ask in RSK chat.
Did you think that it would be so easy to use Remix and Metamask to create a smart contract that can be used on both Ethereum or RSK networks?
I showed 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 :)
Author: Solange Gueiros | Reviewer: Brendan Graetz