Complete Tutorial: Deploy ERC20 Tokens on Rootstock


π― What You'll Learn
By following this tutorial, you will:
β Deploy your own ERC20 token on Rootstock Mainnet
β Configure token parameters (name, symbol, supply, etc.)
β Understand how to get rBTC for gas fees
β Learn how to verify your contract on block explorers
β Set up trading pools for your token (optional)
π οΈ Prerequisites
Before you start, make sure you have:
Required Software
Node.js (version 16 or higher)
npm (comes with Node.js)
Git (to clone the repository)
MetaMask or another Web3 wallet
Required Knowledge
Basic understanding of cryptocurrency and tokens
Familiarity with command line/terminal
Basic knowledge of MetaMask wallet usage
Required Assets
rBTC (Rootstock's native token) for gas fees
Typically need 0.001-0.01 rBTC for token deployment
π What is in the Repository?
Repository provides a ready-to-use solution for deploying ERC20 tokens on Rootstock Mainnet (formerly RSK). Rootstock is a smart contract platform secured by Bitcoin's hashpower, allowing you to create tokens that benefit from Bitcoin's security while having Ethereum-compatible smart contract functionality.
π Repository: https://github.com/0xCardiE/rootstock-erc20
π Step-by-Step Tutorial
Step 1: Get the Code
Clone the repository from GitHub:
git clone https://github.com/0xCardiE/rootstock-erc20
cd rootstock-erc20
Install dependencies:
npm install
If you encounter dependency conflicts, try:
npm install --legacy-peer-deps
Step 2: Set Up Your Environment
Create your environment file:
cp env.example .env
Edit the .env file with your details:
# Your wallet private key (NEVER share this!)
PRIVATE_KEY=your_private_key_here_without_0x
# Your token configuration
TOKEN_NAME=My Awesome Token
TOKEN_SYMBOL=MAT
TOKEN_DECIMALS=18
TOTAL_SUPPLY=1000000
MINT_PERCENTAGE=100
# Optional: Custom RPC (uses default if not set)
ROOTSTOCK_RPC_URL=https://public-node.rsk.co
How to get your private key:
Open MetaMask
Click the three dots menu
Go to "Account Details"
Click "Export Private Key"
β οΈ NEVER share your private key with anyone!
Step 3: Get rBTC for Gas Fees
You need rBTC to pay for transaction fees on Rootstock.
Option A: Bridge from Other Chains (Recommended)
Visit Jumper Exchange: https://jumper.exchange/
Select your source chain (Ethereum, Polygon, etc.)
Select your token (ETH, USDC, etc.)
Select Rootstock as destination
Enter your wallet address
Complete the bridge transaction
Option B: Buy rBTC Directly
Use exchanges that support Rootstock
Look for rBTC trading pairs
Withdraw directly to your Rootstock address
Option C: Bitcoin to rBTC (Advanced)
Use Flyover Protocol (official Rootstock bridge)
Convert BTC directly to rBTC
More technical but fully decentralized
Step 4: Add Rootstock to MetaMask
Open MetaMask
Click network dropdown (usually shows "Ethereum Mainnet")
Click "Add Network"
Enter Rootstock details:
Network Name: Rootstock Mainnet
RPC URL: https://public-node.rsk.co
Chain ID: 30
Currency Symbol: rBTC
Block Explorer URL: https://explorer.rootstock.io/
Step 5: Configure Your Token
Edit your .env file to customize your token:
# Basic token information
TOKEN_NAME=My Business Token # Full name of your token
TOKEN_SYMBOL=MBT # Short symbol (3-5 characters)
TOKEN_DECIMALS=18 # Usually 18 (like ETH)
TOTAL_SUPPLY=1000000 # Total number of tokens
# Minting configuration
MINT_PERCENTAGE=100 # How much to mint initially (1-100%)
Token Configuration Examples:
Example 1: Community Token
TOKEN_NAME=Community Rewards Token
TOKEN_SYMBOL=CREW
TOTAL_SUPPLY=10000000
MINT_PERCENTAGE=50 # Mint 50% now, 50% later for rewards
Example 2: Business Token
TOKEN_NAME=Business Loyalty Points
TOKEN_SYMBOL=BLP
TOTAL_SUPPLY=5000000
MINT_PERCENTAGE=100 # Mint all tokens immediately
Example 3: Stablecoin-style
TOKEN_NAME=My Stable Coin
TOKEN_SYMBOL=MSC
TOKEN_DECIMALS=6 # Like USDC (6 decimals)
TOTAL_SUPPLY=1000000
MINT_PERCENTAGE=0 # No initial mint, mint as needed
Step 6: Deploy Your Token
Compile the smart contracts:
npm run compile
Deploy to Rootstock Mainnet:
npm run deploy
What happens during deployment:
β Smart contract is deployed to Rootstock
β Initial tokens are minted (based on your percentage)
β Contract ownership is assigned to your address
β Deployment record is saved
β Links to view your token are provided
Step 7: Verify Deployment Success
After deployment, you'll see output like this:
β Token deployed successfully!
π Contract Address: 0xabcdef1234567890...
π Transaction Hash: 0x1234567890abcdef...
β½ Gas Used: 1,234,567
π View on Rootstock Explorer: https://explorer.rootstock.io/address/0xabcdef...
π View on Blockscout: https://rootstock.blockscout.com/address/0xabcdef...
Important: Save your contract address! You'll need it for:
Adding tokens to wallets
Creating trading pools
Verifying your contract
Future interactions
Step 8: Verify Your Contract (Optional but Recommended)
Contract verification makes your code publicly viewable and increases trust.
# Automatic verification (recommended)
npm run verify
# Alternative method
npm run verify:hardhat
Benefits of verification:
β Users can see your contract source code
β Increases trust and transparency
β Better integration with tools and explorers
β Easier debugging of transactions
Step 9: Add Your Token to MetaMask
Open MetaMask and ensure you're on Rootstock network
Click "Import tokens"
Enter your contract address (from deployment output)
Token symbol and decimals should auto-fill
Click "Add Custom Token"
Confirm and your tokens will appear in your wallet
Step 10: Create Trading Pools (Optional)
To make your token tradeable, you can create liquidity pools:
Visit Oku Trade: https://docs.oku.trade/home/features/pool/pool-creator
Connect your wallet to Rootstock
Enter your token address
Set initial price and liquidity parameters
Create the Uniswap V3 pool
Add initial liquidity (your tokens + rBTC)
π Understanding Your Deployment
Files Created
After deployment, you'll find:
deployment_history/: Detailed records of your deployments
artifacts/: Compiled contract bytecode
typechain-types/: TypeScript definitions for your contract
Your Contract Features
Your deployed token includes:
β Standard ERC20: transfer, approve, allowance functions
β Mintable: Owner can create new tokens
β Burnable: Users can destroy their tokens
β Ownable: Owner has special privileges
β Configurable decimals: Set precision level
Contract Functions You Can Use
For Token Holders:
transfer(to, amount) - Send tokens to another address
approve(spender, amount) - Allow someone to spend your tokens
burn(amount) - Destroy your own tokens
For Contract Owner Only:
mint(to, amount) - Create new tokens
transferOwnership(newOwner) - Change contract owner
π οΈ Customization Options
Advanced Configuration
You can customize deployment by modifying these files:
hardhat.config.ts: Network settings, gas prices, RPC URLs deploy/01_deploy_token.ts: Deployment logic, post-deployment actions contracts/RootstockERC20.sol: Token contract code (advanced users)
Using Alternative RPCs
If the default RPC is slow, try alternatives in your .env:
# Alternative RPC endpoints
ROOTSTOCK_RPC_URL=https://mycrypto.rsk.co
# or
ROOTSTOCK_RPC_URL=https://rootstock-mainnet.public.blastapi.io
Testing Before Mainnet
Test your configuration locally:
# Start local blockchain
npm run node
# In another terminal, deploy locally
npm run deploy:local
Rootstock Testnet
Users can safely test smart contracts and dApps without using real assets. Rootstock Testnet mirrors the functionality of the Rootstock mainnet but uses test tokens instead of real RBTC.
Network Name: Rootstock Testnet
Chain ID: 31
Currency Symbol: tRBTC (testnet RBTC)
Faucet: faucet.rootstock.io
You can get free testnet tokens (tRBTC) from the faucet to interact with applications and deploy contracts β all without spending any real money. Itβs a perfect environment for learning, experimenting, or testing before launching on mainnet.
π§ Troubleshooting
Common Issues and Solutions
β "insufficient funds" error
Solution: Get more rBTC for gas fees
Where to get: Use Jumper Exchange to bridge from other chains
β "nonce too high" error
Solution: Reset your MetaMask account
How: MetaMask Settings β Advanced β Reset Account
β "network not found" error
Solution: Check your RPC URL in .env file
Fix: Try alternative RPC endpoints
β Deployment very slow
Solution: Try different RPC endpoint
Alternative: Increase gas price in hardhat.config.ts
β Contract verification fails
Solution: Wait a few minutes after deployment
Alternative: Try npm run verify:hardhat
Getting Help
Rootstock Discord: https://discord.gg/rootstock
Developer Documentation: https://dev.rootstock.io/
GitHub Issues: Report bugs in the repository
π‘ Use Cases and Examples
Business Loyalty Programs
Deploy tokens to reward customer loyalty:
TOKEN_NAME=Coffee Shop Rewards
TOKEN_SYMBOL=CSR
TOTAL_SUPPLY=1000000
MINT_PERCENTAGE=10 # Start with 10%, mint more as customers earn
Community Governance
Create tokens for community voting:
TOKEN_NAME=Community Governance Token
TOKEN_SYMBOL=CGT
TOTAL_SUPPLY=100000
MINT_PERCENTAGE=100 # All tokens for distribution to members
Project Fundraising
Launch tokens for project funding:
TOKEN_NAME=Project Alpha Token
TOKEN_SYMBOL=PAT
TOTAL_SUPPLY=50000000
MINT_PERCENTAGE=60 # 60% for sale, 40% for team/development
Gaming Tokens
Create in-game currency:
TOKEN_NAME=Game Gold Coins
TOKEN_SYMBOL=GGC
TOTAL_SUPPLY=1000000000
MINT_PERCENTAGE=0 # Mint as players earn them
π Security Best Practices
Protecting Your Private Key
β Never share your private key
β Never commit .env file to version control
β Use hardware wallets for large amounts
β Create separate wallets for development vs. production
Smart Contract Security
β Test thoroughly before mainnet deployment
β Verify contracts on block explorers
β Start with small amounts for testing
β Consider professional audits for high-value projects
Operational Security
β Keep backups of important information
β Document your deployments (built-in with this tool)
β Monitor your contracts after deployment
β Plan for ownership management
π Next Steps After Deployment
1. Community Building
Share your contract address with your community
Explain how to add the token to MetaMask
Create documentation for your specific use case
2. Liquidity Management
Add initial liquidity to trading pools
Consider incentive programs for liquidity providers
Monitor trading activity and adjust as needed
3. Marketing and Adoption
List on token tracking websites
Create social media presence
Engage with the Rootstock community
4. Technical Maintenance
Monitor contract interactions
Plan for future token distribution
Keep deployment records safe
Consider multi-signature wallets for important operations
π Additional Resources
Official Documentation
Rootstock Developers: https://dev.rootstock.io/
Rootstock Website: https://rootstock.io/
OpenZeppelin Contracts: https://docs.openzeppelin.com/contracts/
Tools and Services
Jumper Exchange: https://jumper.exchange/ (Bridging)
Oku Trade: https://docs.oku.trade/ (Pool Creation)
Rootstock Explorer: https://explorer.rootstock.io/
Blockscout: https://rootstock.blockscout.com/
Community
Discord: https://discord.gg/rootstock
Twitter: Follow @rootstock_io
GitHub: https://github.com/rsksmart/
Forum: https://forum.rootstock.io/
π― Summary
Congratulations! You now have everything you need to:
β Deploy ERC20 tokens on Rootstock Mainnet
β Configure token parameters for your specific needs
β Verify and secure your smart contracts
β Create trading pools for your tokens
β Troubleshoot common issues
β Follow security best practices
π Repository: https://github.com/0xCardiE/rootstock-erc20
Ready to deploy? Run npm run deploy and launch your token on Rootstock! π
This tutorial covers everything from setup to deployment. For additional questions or support, please refer to the resources listed above or open an issue in the GitHub repository.
Subscribe to my newsletter
Read articles from Marko B directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
