Are you a smart contract developer on Ethereum? If yes, you can now develop a smart contract on Bitcoin with the tools you already know using Rootstock. In this tutorial, we will be using Ethereum-related tools to create and deploy smart contracts on Rootstock.
Prerequisites
- Web browser
- Metamask Wallet
What Is Rootstock?
Rootstock is an EVM-compatible chain, merging the benefits of Bitcoin with the benefits of Ethereum. The beautiful part is Rootstock has a token called RBTC which is equal to BTC. Being an EVM-compatible chain, it lowers development barriers because tools used in an EVM-compatible chain can also be used at Rootstock.
Setting up Metamask Wallet With Rootstock
Since it is an EVM chain, we will be using ChainList to add Rootstock to Metamask
-
Visit ChainList EVM Filtered link where Rootstock has been searched in networks.
-
Make sure Include Testnets is checked.
-
Click on the connect wallet button; this will pop up a Metamask modal to connect to ChainList.
Clicking on Connect Wallet changed the Connect Wallet to Add to Metamask
-
Click Add to Metamask for Rootstock Mainnet.
-
Click Add to Metamask for Rootstock Testnet; this popup is a modal by Metamask to approve and later switch the network.
Getting Rootstock Testnet Native Token (tRBTC)
-
Visit Rootstock faucet, and copy and paste your Metamask wallet address.
-
Check the I'm not a robot,
-
Click the Get test RBTC button. After a few seconds, check your wallet, and you will see the balance.
Checking Your First Transaction on Testnet Explorer
Visit Rootstock Testnet Explorer at explorer.testnet.rootstock.io, enter your wallet address, and press enter key to search. The Testnet faucet transaction is shown in the screenshot below.
Writing First Smart Contract Using Remix
We will be using the Remix IDE to write our first smart contract.
-
Create a new file called SimpleStorage.sol.
-
Copy and paste the code below in the newly created SimpleStorage.sol file.
// SPDX-License-Identifier: MIT
// compiler version must be greater than or equal to 0.8.24 and less than 0.9.0
pragma solidity ^0.8.24;
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}
Compile SimpleStorage.sol on Remix
-
Click on the Solidity logo Icon by the left menu.
-
Check the Auto compile.
-
Click the Compile SimpleStorage button.
Deploying the Smart Contract on Rootstock
In your MetaMask switch your MetaMask network to Rootstock Testnet.
-
Click the deploy & run transaction button.
-
Select Inject Provider - MetaMask.
-
Make sure the account you select the account with balance.
-
Select the smart contract in this example SimpleStorage.
-
Click the Deploy button.
Verifying Smart Contract Transaction on Rootstock Testnet Explorer
-
Copy your smart contract address, and paste the address into the search input; press enter to search
What Next?
All the tools and languages used on Ethereum are compatible with Bitcoin thanks to Rootstock, you can now port your favorite Ethereum protocol to Bitcoin. Take your learning to the next level at https://dev.rootstock.io/