Book a free call

How to Build a dApp on Rootstock: A Practical Guide

Building a dApp on Rootstock means writing Solidity contracts for an EVM-compatible Bitcoin sidechain, testing on chain 31 with tRBTC, then deploying to mainnet.

Hertiv engineering teamReviewed by a senior engineer
7 min read
How to Build a dApp on Rootstock: A Practical Guide
On this page

Short answer

To build a dApp on Rootstock, you write Solidity smart contracts with Hardhat or Foundry, test them on the Rootstock testnet (chain ID 31) using free tRBTC from the faucet, and deploy to mainnet (chain ID 30) where fees are paid in rBTC, a token pegged one-to-one to bitcoin. The frontend connects through a wallet such as MetaMask, and the same Ethereum tooling works because Rootstock is fully EVM-compatible.

What is Rootstock?

Rootstock is a Bitcoin sidechain that runs smart contracts. It is fully compatible with the Ethereum Virtual Machine, so Solidity contracts and Ethereum tools such as Hardhat, Foundry and Remix work on it, while the network itself is secured by Bitcoin miners through merge mining.

The sidechain has its own currency, rBTC, which is pegged one-to-one to bitcoin through the PowPeg bridge. Locking bitcoin on the Bitcoin network mints rBTC on Rootstock, and burning rBTC releases the bitcoin. Fees on Rootstock are paid in rBTC, so a dApp's users transact in a bitcoin-backed token rather than a separate gas token.

That combination is the reason teams choose Rootstock: they get Ethereum-style smart contracts with Bitcoin's security behind them. A dApp built here can serve bitcoin holders directly, including lending, payments and tokenised assets, without asking users to leave the Bitcoin ecosystem.

Rootstock is not a layer 2 in the rollup sense. It is a separate chain with its own blocks and validators, linked to Bitcoin by the peg. For a builder, the practical difference is small: you write contracts, deploy them and build a frontend, much as you would on any EVM chain. Bitcoin layer 2 options explains how Rootstock compares with other ways to build on Bitcoin.

What do you need before you build?

Before you build, you need a wallet, testnet funds, a development environment and a way to read the chain. Most of it is the standard Ethereum setup, with Rootstock's network details added.

What you need Rootstock detail
Wallet MetaMask with the Rootstock testnet added
Testnet funds tRBTC from the Rootstock faucet, free for testing
Network Testnet chain ID 31, mainnet chain ID 30
Contract tools Hardhat or Foundry, Solidity up to version 0.8.35
Frontend tools React with wagmi or ethers to connect wallets
Explorer Rootstock Explorer to check transactions

Add the testnet to MetaMask with the public RPC address, chain ID 31 and the tRBTC currency symbol, then get tRBTC from the faucet. The faucet gives test tokens only, so you can deploy and test as much as you like without spending real funds.

For contracts, start from the Rootstock Hardhat starter kit, which is set up for both testnet and mainnet. It includes example contracts and deploy scripts, so you can check your setup by deploying a sample before writing your own code.

How do you set up a Rootstock project?

You set up a Rootstock project the same way you would for any EVM chain, then point it at the Rootstock testnet. The steps below take you from an empty folder to a contract running on testnet.

  1. Install the tools. Install Node.js and Hardhat, then clone the Rootstock Hardhat starter kit and install its dependencies.
  2. Add the testnet. Put the testnet RPC address and chain ID 31 in the Hardhat config, and store your wallet's private key in an environment file, never in the code.
  3. Write the contract. Write a Solidity contract, keeping it small for the first deploy: one clear purpose, a few functions, and events for anything the frontend needs to read.
  4. Test locally. Run the contract's tests on a local Hardhat network first, so basic errors show up before you spend testnet tokens.
  5. Deploy to testnet. Deploy with the Hardhat deploy command for the testnet, then check the contract on Rootstock Explorer.
  6. Verify the contract. Verify the source on the explorer, so users and auditors can read the code that holds their funds.

Foundry works the same way if you prefer it: configure the testnet RPC and chain ID, then deploy with forge. The Rootstock developer docs list both paths with the exact network settings, and the public RPC endpoints work without an API key for development use.

How does the frontend connect to the dApp?

The frontend connects to a Rootstock dApp through the user's wallet, usually MetaMask. The page asks the wallet to connect, checks that the wallet is on the right network, and then reads contract data or sends transactions through it.

For reading, the frontend calls the contract's view functions through an RPC provider, which needs no wallet at all. A voting dApp, for example, can show the vote counts to anyone, while only connected users can cast a vote. Use wagmi or ethers for this: both support Rootstock once the chain details are added.

For writing, the frontend builds a transaction and asks the wallet to sign it. The user sees the action, the contract and the fee in rBTC before approving. Nothing is signed without the user, which is the point of a dApp: the user keeps control of their funds.

Handle the common failure states in the interface. If the wallet is on the wrong chain, offer a button that switches it to Rootstock testnet or mainnet. If the user has no tRBTC on testnet, link them to the faucet. A dApp that fails silently when the network is wrong loses users fast. Bitcoin layer 2 solutions compares Rootstock with the other networks your users might already use.

How do rBTC, fees and the Bitcoin peg work?

rBTC is the currency of Rootstock, pegged one-to-one to bitcoin. Every rBTC on Rootstock is backed by a bitcoin locked on the Bitcoin network, and the PowPeg bridge handles the conversion in both directions.

To get rBTC, a user sends bitcoin to the PowPeg, which locks it and mints the same amount of rBTC on Rootstock. To go back, the user burns rBTC, and the PowPeg releases the bitcoin. The bridge is secured by merge mining, which means Bitcoin miners also secure the peg, and the locked bitcoin is held by a federation of hardware-secured signers.

Fees on Rootstock are paid in rBTC, and they follow the same gas model as Ethereum: each transaction costs gas, priced in rBTC. Because rBTC tracks the price of bitcoin, fee costs in fiat terms move with bitcoin's price, so a dApp should show fees clearly and keep transactions small where it can.

On testnet, the same mechanics use tRBTC, which has no value and comes free from the faucet. Build and test everything with tRBTC first. Moving to mainnet should be a config change, not a rewrite, because the contracts and the frontend are the same on both networks.

Example (hypothetical): a voting dApp on testnet

Example (hypothetical): a team builds a simple voting dApp on the Rootstock testnet. The contract holds three options, counts votes, and stops accepting them after a deadline. The frontend shows the counts and lets a connected wallet vote once.

The team deploys the contract to testnet with tRBTC from the faucet, then invites 200 test users. Each user casts one vote, so the test produces 200 vote transactions plus 200 read calls that confirm the counts. All of it costs nothing, because tRBTC is free.

The votes split 58, 41 and 21 across the three options, which adds to 120 votes. Wait: 58 plus 41 plus 21 is 120, not 200. The team checks the traces and finds 80 votes were rejected because those wallets had already voted once. The contract worked as designed; the test users simply tried to vote twice.

That check is the point of testing on testnet. The team fixes the frontend to show a clear message when a wallet has already voted, then re-runs the test with 200 fresh wallets and gets 200 accepted votes. Only then do they deploy the same contract to mainnet.

What are the common mistakes?

The most common Rootstock dApp mistakes are deploying to the wrong chain, leaking a private key, and skipping verification.

  • Wrong chain ID. Mainnet is chain ID 30 and testnet is 31. A deploy aimed at the wrong one either fails or, worse, lands on mainnet with real funds at stake.
  • Private key in the code. A deploy key committed to a repository is a stolen key. Keep it in an environment file, and use a separate wallet for deployment.
  • Skipping verification. An unverified contract cannot be read on the explorer, so users cannot check what it does before trusting it.
  • Assuming Ethereum behaviour. Rootstock is EVM-compatible, but a few opcodes and gas costs differ, so test on testnet rather than assuming a contract that works on Ethereum works here.
  • No peg check. A dApp that handles rBTC should explain the peg to users, because some will not know that rBTC is backed by locked bitcoin.
  • Mainnet first. Testing on mainnet with real rBTC turns every bug into a loss. Testnet exists for this reason.

If you need a team to build it, dApp development covers the design, contract and frontend work.

For the build process itself, smart contract development explains each stage in more depth.

Key takeaways

  • Rootstock is an EVM-compatible Bitcoin sidechain, so Solidity and Ethereum tools work on it
  • Testnet is chain ID 31 with free tRBTC from the faucet; mainnet is chain ID 30 with fees in rBTC
  • rBTC is pegged one-to-one to bitcoin through the PowPeg bridge, secured by merge mining
  • Build with Hardhat or Foundry, test locally, then deploy and verify on testnet
  • Never deploy to mainnet before the contract is tested and verified on testnet

Frequently asked questions

What is Rootstock?

Rootstock is a Bitcoin sidechain that runs smart contracts. It is fully compatible with the Ethereum Virtual Machine, so Solidity contracts and tools such as Hardhat and Foundry work on it, while the network is secured by Bitcoin miners through merge mining.

What is rBTC?

rBTC is Rootstock's native currency, pegged one-to-one to bitcoin. Locking bitcoin on the Bitcoin network through the PowPeg bridge mints rBTC on Rootstock, and burning rBTC releases the bitcoin. Fees on Rootstock are paid in rBTC.

What is the Rootstock testnet chain ID?

The Rootstock testnet uses chain ID 31, and mainnet uses chain ID 30. Testnet tokens are called tRBTC and come free from the Rootstock faucet, so you can build and test without spending real funds.

Can I use Hardhat with Rootstock?

Yes. Rootstock is fully EVM-compatible, so Hardhat, Foundry and Remix all work. The Rootstock Hardhat starter kit is set up for both testnet and mainnet, with example contracts and deploy scripts included.

Is Rootstock the same as a Bitcoin layer 2?

Not exactly. Rootstock is a sidechain with its own blocks, linked to Bitcoin by the PowPeg bridge, rather than a rollup that settles on Bitcoin. For a builder, the workflow is similar: write contracts, deploy, and build a frontend.

How do users connect to a Rootstock dApp?

Users connect with a wallet such as MetaMask, with the Rootstock network added. The frontend reads contract data through an RPC provider and asks the wallet to sign any transaction, so users keep control of their funds.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building a dApp on Bitcoin-secured rails? Talk to Hertiv.

A senior engineer replies within one business day. Or see our dApp Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call