Rootstock DeFi Developer Guide
The Rootstock DeFi Developer Guide covers token standards, oracle integration, AMM patterns, and security practices for protocols on Rootstock. Use it to review fundamentals before you deploy vault, lending, or stablecoin flows to mainnet.
This guide provides practical workflows, example code, and best practices for building DeFi protocols on Rootstock.
This guide assumes you have basic knowledge of Solidity, blockchain fundamentals, and the Rootstock ecosystem. You should have a development environment set up (Hardhat or Foundry) and a testnet wallet with tRBTC. See Shared Setup.
Why Rootstock for DeFi?
- Bitcoin security: Rootstock is merge-mined with Bitcoin and secured by over 85% of Bitcoin hash power.
- EVM compatibility: Write and deploy contracts in Solidity with Ethereum-familiar tooling.
- Lower fees: Transactions on Rootstock typically cost less than on Ethereum mainnet.
- DeFi tooling: Bridges, oracles, and protocol integrations are documented in this portal.
- rBTC: The native asset is Bitcoin-pegged (1 rBTC = 1 BTC). Bitcoin holders can use rBTC as gas and collateral in DeFi protocols.
What You Will Learn
This guide is divided into five main sections, each building on the previous:
1. Token Standards & Best Practices
Learn how to implement and extend ERC-20, ERC-721, and ERC-4626 tokens on Rootstock. Understand wrapping RBTC (wRBTC), gas optimization, and security considerations specific to token development.
2. Oracle Integration
Fetch reliable off-chain data using Chainlink or other oracles. Implement price feeds, randomness (VRF), and oracle patterns that reduce manipulation risk.
3. Automated Market Makers (AMM) Basics
Build a simple constant-product AMM from scratch. Understand liquidity pools, swap mechanics, fees, and slippage. Test your contract with Hardhat and integrate it with a React frontend.
4. Security Patterns
Review security practices for DeFi: reentrancy protection, access control, integer safety, upgradeability, circuit breakers, and flash loan resistance. Learn how to audit your code and avoid common pitfalls.
5. Example Templates
Get started quickly with full-stack templates. Each template includes smart contracts, Hardhat deployment scripts, and a React frontend with ethers.js integration. Templates cover price oracles, AMMs, ERC-20 with permit, yield vaults (ERC-4626), and upgradeable contracts.
Target Audience
This guide is designed for:
- Solidity developers who are new to Rootstock and want to deploy their first DeFi dApp.
- DeFi protocols planning to expand to Rootstock and seeking best practices.
- Web3 developers looking for reusable patterns and templates to accelerate development.
- Students and researchers interested in learning how DeFi protocols work under the hood.
Prerequisites
Before diving in, ensure you have:
- Basic Solidity knowledge: You should understand functions, modifiers, events, and inheritance.
- Familiarity with Ethereum concepts: Transactions, gas, wallets, and ERC standards.
- A development environment: We recommend Hardhat, but Foundry or Truffle also work.
- A Rootstock testnet wallet: You'll need tRBTC (testnet RBTC) to deploy and test contracts.