Table of Contents
EthGlobal Bangkok is one of the largest hackathons by EthGlobal, With $775k in prizes, 69 partners are on board giving developers a wide variety of choices on which protocol to build. We at Metaschool have shortlisted 7 protocols to write about everything that would help you developers prepare for the Hackathon. The first in the series is Rootstock.
Rootstock is the first sidechain on Bitcoin and thus has the longest existence in the Bitcoin ecosystem in the sidechain category. It has the best of both worlds the smart contract capabilities of Ethereum and the security of Bitcoin. It is open-source, EVM-compatible, and secured by over 60% of Bitcoin’s hashing power.
Technical Foundation
Merge Mining
RSK’s security model is built on the concept called merge mining. This process allows Bitcoin miners to simultaneously mine RSK blocks without requiring additional computational power. The beauty of this system lies in its efficiency miners can earn additional rewards while contributing to the security of both networks. This symbiotic relationship with Bitcoin’s mining network provides Rootstock with a higher level of security.
PowPeg
Smart Bitcoin (RBTC), is the platform’s native currency. RBTC maintains a 1:1 peg with Bitcoin through an ingenious two-way peg mechanism peg-in and peg-out. This system allows users to convert their BTC to RBTC and vice versa, creating a fluid connection between the two networks. The peg mechanism works through a combination of smart contracts and federation nodes, ensuring the stability and reliability of the conversion process.
The RSK Virtual Machine (RVM)
The RSK Virtual Machine represents a significant technical achievement in blockchain interoperability. It is the core of the Smart Contract platform. Smart Contracts are executed by all network full nodes. Built to be fully compatible with the Ethereum Virtual Machine (EVM) at the op-code level, the RVM allows developers to port their Ethereum applications to RSK with minimal modifications. This compatibility extends to development tools, smart contract languages, and web3 libraries, making the transition seamless for Ethereum developers.
Pre-requisites
– Solidity Version – 0.8.19
– Wallet – Metamask
– Node RPC – Get your API key
– Install Hardhat
– Install Foundry
Starter Kits available on Rootstock
- WAGMI Starter Kit
The Wagmi starter kit provides a foundation for building decentralized applications (dApps) on the Rootstock blockchain. It leverages the security of Bitcoin and the flexibility of Ethereum. The kit uses Wagmi, a React Hooks library, to simplify smart contracts and blockchain network interactions and and Shadcn libraries. The components in it include ERC20, ERC721, and ERC1155. - The code responsible for the tabs corresponding to ERC20, ERC721, and ERC1155 can be found in the components folder:
- ERC20: Located in the
components/tokens/ERC20
directory. - ERC721: Located in the
components/tokens/ERC721
directory. - ERC1155: Located in the
components/tokens/ERC1155
directory.
- Hardhat Starter Kit
Hardhat is an Ethereum development environment used by both newbies and experienced developers in web3. Make sure you have hardhat installed in your device.npm i -g hardhat-shorthand
- Rootstock Foundry Starter Kit
This starter kit helps set up your Foundry development environment, connect to a Rootstock network, write and test smart contracts, deploy them to the Rootstock blockchain. Don’t forget to install Foundry in your system.curl -L https://foundry.paradigm.xyz | bash
- Account Abstraction using Etherspot Prime SDK
If you are building a dApp and planning to use AA. With this starter kit, you will learn how to use the Etherspot Prime SDK to deploy an Account Abstraction dApp on the Rootstock network.
Integration of developer-friendly SDKs on Rootstock
Rootstock has two major SDKs – RIF Relay and RBTC Flyover. RIF Relay Project is to provide the Rootstock (RSK) ecosystem with the means to allow blockchain applications and end-users (wallet apps) to transact without needing RBTC. The system should allow Rootstock (RSK) users to pay transaction fees with methods of payment (i.e., tokens) other than RBTC while maintaining their accounts as transaction senders.
Integrating RIF Relay on Rootstock
1. Install the RIF Relay SDK
npm install @rsksmart/rif-relay-sdk
2. Configure the Relay Client
To create a RelayClient
we need to follow these steps:
- Set the configuration
- Set (ethers) provider
- Create instance.
import {
RelayClient,
setEnvelopingConfig,
setProvider,
} from '@rsksmart/rif-relay-client';
setEnvelopingConfig({
chainId: <CHAIN_ID>,
preferredRelays: <SERVER_URL_ARRAY>,
relayHubAddress: <RELAY_HUB_ADDRESS>,
deployVerifierAddress: <DEPLOY_VERIFIER_ADDRESS>,
relayVerifierAddress: <RELAY_VERIFIER_ADDRESS>,
smartWalletFactoryAddress: <SMART_WALLET_FACTORY_ADDRESS>
});
setProvider(ethersProvider);
const relayClient = new RelayClient();
3. Send Transactions Using Relay
To relay transactions we need a smart wallet already deployed, the deployment process and definition of a smart wallet can be found Smart Wallet. The steps that we must follow are:
- Deploy the smart wallet.
- Create the transaction that we would like to relay.
- Relay the transaction.
const relayTransactionOpts: UserDefinedEnvelopingRequest = {
request: {
from: <EOA>,
data: <DATA_TO_EXECUTE>,
to: <DESTINATION_ADDRESS>,
tokenContract: <TOKEN_ADDRESS>,
tokenAmount: <AMOUNT_OF_TOKENS_IN_WEI>,
},
relayData: {
callForwarder: <SMART_WALLET_ADDRESS>,
},
};
const transaction: Transaction = await relayClient.relayTransaction(
relayTransactionOpts
);
Integrating RBTC Flyover on Rootstock
The RBTC Flyover enables fast, trust-minimized onboarding of users into the Rootstock ecosystem from Bitcoin with less friction. It improves the usability for bitcoiners and integrators to interact with the Rootstock ecosystem via the Powpeg and Flyover SDK. There are various use cases of the RBTC depending on the user be it developers or liquidity providers. Let us look at the use case for developers, it offers a way for developers to integrate Flyover into wallets, dApps, DEXs, and swaps using the Flyover SDK.
DeFi and Lending Platforms can integrate Flyover to allow users to easily deposit Bitcoin as collateral for borrowing assets on Rootstock. The faster peg-in times provided by Flyover would unlock borrowing opportunities for users who hold RBTC against other rootstock on-chain assets (MOC, USDRIF, and others).
Another use case could be wallet or exchange platforms integrating Flyover to offer a seamless experience for depositing and withdrawing BTC and RBTC within their platform utilizing the liquidity provided by the Flyover LP network. This eliminates the long wait times associated with traditional peg-in methods, allowing users to quickly move funds between their wallets to other platforms.
Pre-requisites for Integration
- These are the minimum requirements that must be met to run an Rootstock node (Mainnet and Testnet):
- 2 cores
- 8 GB RAM
- 128 GB storage
- OS x64
Getting Testnet Funds
You can get test BTC funds on Coinfaucet. To get test funds for RBTC, use the Rootstock Faucet. To get a legacy wallet address for use on Testnet, consider using an Electrum Bitcoin wallet.
Installation
To install the Flyover SDK
npm install @rsksmart/flyover-sdk
Import the Flyover SDK into project
import { Flyover } from '@rsksmart/flyover-sdk';
Initialize the SDK
const flyover = new Flyover({
network: 'Regtest',
captchaTokenResolver:
async () => Promise.resolve(''),
})
Ideas to build on Rootstock
Here are a few ideas to potentially build during the hackathon:
- Bitcoin-Backed Lending Platform (BTC-Lend) – Create a DeFi lending platform that allows Bitcoin holders to use their BTC as collateral without leaving the Bitcoin ecosystem.
- Cross-Chain DEX Aggregator (CrossChainSwap) – Build a decentralized exchange aggregator that finds the best rates across multiple DEXes while enabling Bitcoin trading.
- Bitcoin Options Trading Platform (BTCOptions) – Develop a decentralized options trading platform specifically for Bitcoin derivatives.
- Decentralized Governance Hub (BTCGov )- Build a governance platform that leverages Bitcoin’s security for transparent and tamper-proof voting.
- Decentralized Identity Solution (BTCIdentity) – Build a decentralized identity system that leverages Bitcoin’s security and RSK’s smart contract capabilities.
- Bitcoin Mining Pool Decentralizer (MinePool) – Create a decentralized mining pool that allows individual miners to participate in Bitcoin mining while earning additional RSK rewards.’
- Automated Treasury Management – Build a treasury management system with automated allocation, spending limits, and investment strategies.
- dePIN Network Orchestrator – Build a platform for managing decentralized physical infrastructure networks with Bitcoin-based incentives.
Conclusion
This article is a part of the Hackathon series for developers participating at EthGlobal Bangkok and interested in building on Rootstock. Feel free to add idea suggestions and let us know what are you planning to build. But if you are starting to learn how to build in web3 start with our Ethereum Track. WAGMI!