Deploy Simple Stablecoin on Rootstock Side chain


What is a Stablecoin?
A stablecoin is a special kind of digital money that tries to stay worth about the same amount over time. Unlike regular cryptocurrencies that can fluctuate wildly in value, stablecoins aim to maintain a steady price, usually pegged to another asset like the US dollar.
What is Rootstock?
Rootstock is a revolutionary blockchain project that builds upon the security of Bitcoin to create a powerful smart contract platform. Rootstock is a sidechain that aims to enhance Bitcoin’s capabilities by adding fast, flexible, and feature-rich smart contracts while maintaining Bitcoin’s core strengths. You can develop smart contracts compatible with EVM and deploy it to the Rootstock chain which is a Bitcoin side chain.
With this understanding of Rootstock, let’s proceed to deploying the stablecoin.
How can smart contracts be deployed on Rootstock?
Now it’s time to develop a simple stable coin and deploy it on the Rootstock side chain.
Step 1. Write a smart contract of stablecoin
We are using Remix IDE to develop smart contracts, which is EVM compatible smart contract development online platform.
Open Remix IDE from https://remix.ethereum.org/.
Create a new file.
Now copy the following basic stablecoin contract into your newly created file:
Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
contract RootCoin is ERC20, ERC20Burnable, ERC20Permit {
address public owner;
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
constructor()
ERC20("RootCoin", "RC")
ERC20Permit("RootCoin")
{
owner = msg.sender;
_mint(owner, 1000 10 * decimals());
}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
The contract imports the following modules from the OpenZeppelin library:
ERC20: Implements the standard ERC-20 functionality, such as token transfers, balances, and approvals.
ERC20Burnable: Allows token holders to burn (destroy) their tokens, reducing the total supply.
ERC20Permit: Enables gasless approvals by using EIP-2612 permits, allowing users to approve token allowances via a signature instead of a transaction.
Functionalities:
Constructor
The constructor is executed once during contract deployment and performs the following:
Initializes the ERC-20 token with:
Name: “RootCoin”
Symbol: "RC"
Sets the deployer of the contract (msg.sender) as the initial owner.
Initializes the ERC20Permit feature with the token name ("RootCoin").
Mints an initial supply of tokens (1000 10 * decimals()) to the deployer's(owner) address.
onlyOwner Modifier
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
Purpose: Allows the contract owner to mint (create) new tokens.
mint Function
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
Purpose: Allows the contract owner to mint (create) new tokens.
Parameters:
to: Address where the newly minted tokens will be sent.
amount: The number of tokens to mint.
Access Control: This function is restricted to the owner of the contract using the onlyOwner modifier, so that no one can mint the coin to ourself.
Burnable Tokens
Since the contract inherits from ERC20Burnable, it allows any token holder to burn their tokens, permanently reducing the total supply.
RootCoin.burn(amount);
This functionality is available to all token holders, enabling them to destroy their own tokens.
Permit (Gasless Approval)
The ERC20Permit integration allows users to approve token allowances via signatures instead of on-chain transactions. This reduces the need for gas fees when interacting with decentralized applications (dApps).
Key Functionality:
Approve token spending using permit, passing the signature details instead of calling the standard approve function.
Step 2. Compile our contract
Now go to the compiler section for the compilation of our contract.
First, set the compiler version according tothe contract version.
You can check the auto-compile option also, by checking that you are able to compile automatically without manual compile.
Step 3. Deploy our contract
For deployment purposes, you need to navigate into the deployment section as shown in the figure. To deploy our contract on the Rootstock chain, we need to sign the transaction from our wallet.
To do this, select the injected provider in the environment section.
Step 4. Add network to MetaMask
I've used MetaMask, which is compatible with most chains compatible with EVM.
First, we need to add the Rootstock network to our MetaMask:
Unlock your MetaMask:
Go to settings:
Navigate to networks
Click on add custom network:
Enter the following fields:
Name: Rootstock Testnet
RPC URL: https://public-node.testnet.rsk.co
Chain ID: 31
Symbol: tRBTC
Block explorer URL: https://explorer.testnet.rootstock.io/
This will configure your MetaMask for the Rootstock testnet.
Now select the Rootstock contract and deploy it.
MetaMask will prompt you to confirm. click the confirm button as shown in figure below.
Now open your terminal to see the transaction data.
The output should be same as figure shown below.
It's time to celebrate! Your contract has been deployed on the Rootstock chain. You can now interact with your deployed smart contract by the public and private getter functions shown in figure below.
let’s check our balance, for that call the balanceOf function as shown in above image and pass your MetaMask address, because you are the owner of the contract as you have deployed it. You can see balance as shown in below image.
As well as you can use all the functionalities by passing required argument. Let’s mint 10 tokens to another account for that do same as shown in image
Now check the balance of passed account through balanceOf function as we done first.
After this all stuff verify your deployment on the https://explorer.rootstock.io/.
You just have to pass your deployed contract address in the search field of explorer as shown step below.
Copy the contract address, past in into search bar in explorer
Congratulations! You have successfully deployed your basic stable coin on the Rootstock sidechain.
By:- Gaurang Bharadava / HEXXA Protocol
Subscribe to my newsletter
Read articles from Gaurang directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
