Leveraging the power of Bitcoins with RSK

Learn how RSK works and how to deploy your smart contracts to it

I'm always interested in what other ways one can use their blockchain and Solidity skills. While many projects are still only in the planning or in testnet status, with Rootstock (RSK) you can transfer mainnet Bitcoins to an EVM sidechain and vice-versa already today. Utilizing the power of the EVM allows you to deploy Solidity contracts and use existing Ethereum infrastructure and tooling around it.

Let's see how to use it...

Bitcoiners

What is RSK?

RSK is a sidechain for the Bitcoin blockchain with full EVM support. This means you can deploy Solidity contracts here, while leverage the security of Bitcoin mining. Most tools will also have support for the RSK chain given its EVM capability.

All details can be seen in the Whitepaper.

What is the RSK sidechain?

Sidechains generally are EVM-compatible, separate blockchains with their own consensus models. Sidechains are designed to easily allow transfer of value and arbitrary state with the main chain. RSK is special as it's not connecting towards the Ethereum mainnet, but rather the Bitcoin blockchain.

+ allow you to run fully functioning smart contracts
+ value exchange with Bitcoin main chain

- security currently still relies on a set of 15 trusted notaries

How is the sidechain secured?

The sidechain of RSK is run by Bitcoin miners via 'merged mining'. Any Bitcoin miner can choose to additionally become a miner in the RSK network without having to allocate extra resources for the RSK chain. How does that work?

  1. The miner creates a block for the RSK chain containing all newly added transactions in the RSK chain.
  2. The miner then hashes this block and creates a valid Bitcoin transaction containing the hash and adds it into the existing new Bitcoin transactions.
  3. Now the miner creates the final Bitcoin header with this transaction in it.


Now there are three scenarios:

  1. The new block satisfies the Bitcoin difficulty which will be the least likely. In this case the RSK block hash is simply ignored, but the overhead is tiny as it's just a single additional hash. The transaction fees from the Bitcoin network will go towards the miner.
  2. The new block satisfies the RSK difficulty, but not the Bitcoin difficulty. In this case only the RSK block will be activated and integrated in the RSK sidechain. The transaction fees from the RSK network will go towards the miner.
  3. The new block doesn't satisfy any difficulty, so it's just ignored.


As you can see, almost no extra work is required for the miner this way. The difficult part of computing hashes has to be done only once for the Bitcoin and RSK chain at the same time. This incentivizes Bitcoin miners to also mine RSK as it's simply free additional money. As of now the participation rate is very high ranging from 60% to 80%. The higher the more secure the sidechain will be.

How is the transfer between Bitcoin and RSK secured?

The current 2-way peg design in RSK allows to transfer Bitcoins from the Bitcoin blockchain to the RSK chain and vice-versa.

Current Design: Transfers are secured by 15 public and well-known, trusted notaries. Once you lock Bitcoins in the main chain, they will control those funds. Only once you burn the funds in the RSK chain, will the notaries return your funds on the main chain.

The obvious advantage here is that the system is not fully decentralized.

Notary Bridge

Future Design: In the future RSK may change the design to a so-called drive-chain. In this design the locked funds are solely controlled by the Bitcoin miners. Unlocking funds happens in a voting period. For this to work however, a new OPCODE in Bitcoin would be required and thus a soft fork introducing the new capability. An existing proposal for a BIP (the Bitcoin equivalent of EIP) is here.

Hybrid: This future design could be added in a hybrid model depending on miner participation. If the miner participation is low, keep the current design with notaries. But as participation increases, give more and more power to the miners. Eventually only miners will control the funds.

You can find more details about the two peg design here.

Dynamic Hybrid RSK
Hybrid RSK

RSK further told me they are about to announce their PowPeg very soon, a new peg system. This will come in the form of a blog post and an accompanying page on our developer portal.... so watch this space!

Existing projects on RSK

But not only that, many projects or forks of those already exist inside RSK. Some highlights include:

Uniswap Fork Another One

How to deploy to RSK

Deploying to the RSK sidechain is very simple. If you're using Truffle, simply add the network configuration like this:

Truffle's built in HDWalletProvider, as well as the bundled Web3Provider, were previously using hard coded values that are OK for Ethereum, but not OK for RSK. This was due to larger block times, the resulting rate limits configured on our public nodes.

You can now override these defaults - to make Truffle work better with RSK.

testnet: {
      provider: () => new HDWalletProvider({
        mnemonic: {
          phrase: testnetSeedPhrase,
        },
        providerOrUrl: 'https://public-node.testnet.rsk.co/2.0.1/',
        // Higher polling interval to check for blocks less frequently
        pollingInterval: 15e3,
      }),
      // Ref: http://developers.rsk.co/rsk/architecture/account-based/#chainid
      network_id: 31,
      gasPrice: Math.floor(gasPriceTestnet * TESTNET_GAS_MULT),
      networkCheckTimeout: 1e6,
      timeoutBlocks: 100,
      // Higher polling interval to check for blocks less frequently
      // during deployment
      deploymentPollingInterval: 15e3,
},

Without the above, you're likely to run into intermittent failures for truffle migrate, and intermittent warnings when you leave truffle console running.

You'll also need funds in the sidechain of course. For the testnet, just use the available faucet here. For mainnet you need to use the bridge as described below and further use the config:

  • provider: () => new HDWalletProvider(mnemonic, 'https://public-node.rsk.co')
  • network_id: 30

Be aware that for production services you may not want to rely on a public node, but rather run your own RSK node.

Onboarding users

MetaMask

To interact with the side chain, users need to add the RSK network to their MetaMask. Click on the network selection in MetaMask and then choose 'Custom RPC'. For the current testnet, use the configuration of


  • RPC URL: https://public-node.testnet.rsk.co
  • ChainID: 31
  • Symbol: tR-BTC
  • Block Explorer URL: https://explorer.testnet.rsk.co


For mainnet you can use

  • RPC URL: https://public-node.rsk.co
  • ChainID: 30
  • Symbol: R-BTC
  • Block Explorer URL: https://explorer.rsk.co
RSK MetaMask

Value transfer from and to RSK

1. Getting the native RSK (BTC <-> R-BTC)

To get the native RSK token, you only need to transfer Bitcoins to the bridge address.

  1. To have a testnet BTC address, start Electrum in testnet mode.
  2. If you want to try it in the testnet, obtain some testnet BTC via https://testnet-faucet.mempool.co/.
  3. Now using MyCrypto, choose the RSK Testnet in “More Networks” and navigate to “MyCrypto -> Contracts -> Select Existing Contracts -> “Bridge” -> “getFederationAddress”. This will give you the bridge address for the testnet. You can send BTC to this bridge. 
  4. Your respective RSK EVM key can be generated from the Bitcoin address using the converter tool.

The way back is even easier, just send the (t)R-BTC to the address 0x0000000000000000000000000000000001000006. Done.

2. Moving Ethereum ERC-20 tokens to RSK (e.g. DAI <-> r-DAI)

RSK Token Bridge

Since RSK is an EVM compatible chain, it makes sense that they further offer to transfer Ethereum tokens to it. To move a token between RSK chain and Ethereum mainnet, there is a bridging system that is very easy to use. You can use the following services:

  1. For the mainnet use https://tokenbridge.rsk.co/.
  2. For the testnet (BTC testnet <-> Kovan testnet) use https://testnet.tokenbridge.rsk.co/.

Future RSK Development

The obvious next step for RSK would be integrating the described drivechain design. However since it's relying on a Bitcoin soft fork, we have no idea when or even if this is will be coming in the future. If you have further details about it, I'd love to hear it and please leave a comment.

Otherwise the team is working on bring meta-transactions to the system:

"

The Research & Innovation team is developing a solution for meta-transactions named Enveloping. The main goal is to allow users to submit transactions to the network through a service provider (Sponsor) and pay for this service in tokens, removing the need to get native currency to operate with our blockchain network.

Horacio S. Caceres (Qubistry)


Have you used RSK before? Maybe even on Mainnet? Let me know in the comments.

Next week we will look at everything one needs to know about ERC-1155, so stay tuned!


Markus Waas

Solidity Developer

More great blog posts from Markus Waas

  • Exploring the Openzeppelin CrossChain Functionality

    What is the new CrossChain support and how can you use it.

    For the first time Openzeppelin Contracts have added CrossChain Support. In particular the following chains are currently supported: Polygon: One of the most popular sidechains right now. We've discussed it previously here. Optimism: A Layer 2 chain based on optimistic rollups. We discussed the...

  • Hedera Preview

    Deploying Solidity Contracts in Hedera

    What is Hedera and how can you use it.

    Hedera is a relatively new chain that exists since a few years, but recently added token service and smart contract capabilities. You can now write and deploy Solidity contracts to it, but it works a little differently than what you might be used to. Let's take a look! What is the Hedera Network?...

  • Foundry Forge

    Writing ERC-20 Tests in Solidity with Foundry

    Blazing fast tests, no more BigNumber.js, only Solidity

    Maybe you are new to programming and are just starting to learn Solidity? One annoyance for you might have been that you were basically required to learn a second language (JavaScript/TypeScript) to write tests. This was undoubtedly a downside which is now gone with the new foundry framework. But...

  • ERC-4626: Extending ERC-20 for Interest Management 

    How the newly finalized standard works and can help you with Defi

    Many Defi projects have an ERC-20 token which represents ownership over an interest generating asset. This is for example the case for lending/borrowing platforms (money markets) like Compound and Aave. As a lender you will receive aDAI or cDAI. And since lenders receive interest payments for...

  • Advancing the NFT standard: ERC721-Permit

    And how to avoid the two step approve + transferFrom with ERC721-Permit (EIP-4494)

    There's a new standard in the making. To understand how this really works, I recommend you take a look at my tutorials on: ERC721 ERC20-Permit ecrecover incl EIP712 But we'll try to cover the basics here also. You might be familiar already with ERC20-Permit (EIP-2612). It adds a new permit...

  • Moonbeam: The EVM of Polkadot

    Deploying and onboarding users to Moonbeam or Moonriver

    We've covered several Layer 2 sidechains before: Polygon xDAI Binance Smart Chain Evmos Aurora (NEAR) But Moonbeam is unique since it's a parachain of the Polkadot ecosystem. It only just launched which means you are now able to deploy smart contracts to the chain. Being able to deploy EVM...

  • Advanced MultiSwap: How to better arbitrage with Solidity

    Making multiple swaps across different decentralized exchanges in a single transaction

    If you want maximum arbitrage performance, you need to swap tokens between exchanges in a single transaction. Or maybe you just want to save gas on certain swaps you perform regularly. Or maybe you have your own custom use case for swapping between decentralized exchanges. And of course maybe you...

  • Deploying Solidity Smart Contracts to Solana

    What is Solana and how can you deploy Solidity smart contracts to it?

    Solana is a new blockchain focusing on performance. It supports smart contracts like Ethereum which they call Programs. You can develop those in Rust, but there's also a new project now to compile Solidity to Solana. In other words you can deploy your contracts written in Solidity now to Solana!...

  • Smock 2: The powerful mocking tool for Hardhat

    Features of smock v2 and how to use them with examples

    We’ve covered mocking contracts before as well as the first version of the new mocking tool Smock 2. It simplifies the mocking process greatly and also gives you more testing power. You’ll be able to change the return values for functions as well as changing internal contract storage directly!...

  • Using the new Uniswap v3 in your contracts

    What's new in Uniswap v3 and how to integrate Uniswap v3

  • What's coming in the London Hardfork?

    Looking at all the details of the upcoming fork

    The Berlin Hardfork only just went live on April 14th after block 12,224,00. Next up will be the London Hardfork in July which will include EIP-1559 and is scheduled for July 14th (no exact block decided yet). So let's take a look at the new changes and what you need to know as a developer....

  • Matrix Simulation

    Welcome to the Matrix of blockchain

    How to get alerted *before* getting hacked and prevent it

    Defi hacks alone have totaled $285M just since 2019. Let's take the Balancer hack for example. The hack was exploiting the fact that a pool with a deflationary token STA (Statera) was created. The pool accumulated a significant liquidity when it was eventually drained by the hack. Read my post on...

  • Solidity Fast Track: Learn Solidity Fast

    'Learn X in Y minutes' this time with X = Solidity 0.7 and Y = 20

    You might be familiar with the Learn X in Y minutes. For example you could learn JavaScript in 20 minutes at https://learnxinyminutes.com/docs/javascript/. Unfortunately there is no equivalent for Solidity, but this is about to change. Do you have 20 minutes to learn all of the basics? We even...

  • Decentralized Etherscan

    Sourcify: The future of a Decentralized Etherscan

    Learn how to use the new Sourcify infrastructure today

    We all love Etherscan. It's a great tool to interact with contracts, read the source codes or just see the status of your transactions. But unfortunately as great as it is, we should not forget that it's a centralized service. The website could be taken down any day. This kind of defeats the...

  • 0x Contracts

    Integrating the 0x API into your contracts

    How to automatically get the best prices via 0x

    How can you add 0x to your contracts to automatically convert between tokens? We have done this in a similar fashion before with Uniswap and Balancer. The 0x API has a bit of a twist. Let's take a look why... Why you want 0x in your contracts? It's simple: Okay, but seriously. Let's see why the...

  • How to build and use ERC-777 tokens

    An intro to the new upgraded standard for ERC-20 tokens

    The new upgraded standard for ERC-20 tokens is becoming more and more popular. It's fully backwards compatible, you can easily create one using the Openzeppelin contracts and there are many interesting new features not available in ERC-20. Should you upgrade from ERC-20? Well let's look into what...

  • COMP Governance Explained

    How Compound's Decentralized Governance is working under the hood

  • xDai

    How to use xDai in your Dapp

    Deploying and onboarding users to xDai to avoid the high gas costs

    Gas costs are exploding again, ETH2.0 is still too far away and people are now looking at layer 2 solutions. Here's a good overview of existing layer 2 projects: https://github.com/Awesome-Layer-2/awesome-layer-2. Today we will take a closer look at xDai as a solution for your Dapp. What are...

  • 15 Stacks

    Stack Too Deep

    Three words of horror

    You just have to add one tiny change in your contracts. You think this will take you only a few seconds. And you are right, adding the code took you less than a minute. All happy about your coding speed you enter the compile command. With such a small change, you are confident your code is...

  • Chainlink Thumbnail

    Integrating the new Chainlink contracts

    How to use the new price feeder oracles

    By now you've probably heard of Chainlink. Maybe you are even participating the current hackathon? In any case adding their new contracts to retrieve price feed data is surprisingly simple. But how does it work? Oracles and decentralization If you're confused about oracles, you're not alone. The...

  • TheGraph: Fixing the Web3 data querying

    Why we need TheGraph and how to use it

    Previously we looked at the big picture of Solidity and the create-eth-app which already mentioned TheGraph before. This time we will take a closer look at TheGraph which essentially became part of the standard stack for developing Dapps in the last year. But let's first see how we would do...

  • truffle buidler typescript

    Adding Typescript to Truffle and Buidler

    How to use TypeChain to utilize the powers of Typescript in your project

    Unlike compiled languages, you pretty much have no safeguards when running JavaScript code. You'll only notice errors during runtime and you won't get autocompletion during coding. With Typescript you can get proper typechecking as long as the used library exports its types. Most Ethereum...

  • Balance Rope

    Integrating Balancer in your contracts

    What is Balancer and how to use it

    What is Balancer? Balancer is very similar to Uniswap. If you're not familiar with Uniswap or Balancer yet, they are fully decentralized protocols for automated liquidity provision on Ethereum. An easier-to-understand description would be that they are decentralized exchanges (DEX) relying on...

  • mousetrap

    Navigating the pitfalls of securely interacting with ERC20 tokens

    Figuring out how to securely interact might be harder than you think

    You would think calling a few functions on an ERC-20 token is the simplest thing to do, right? Unfortunately I have some bad news, it's not. There are several things to consider and some errors are still pretty common. Let's start with the easy ones. Let's take a very common token: ... Now to...

  • Aave

    Why you should automatically generate interests from user funds

    How to integrate Aave and similar systems in your contracts

    If you're writing contracts that use, hold or manage user funds, you might want to consider using those funds for generating free extra income. What's the catch? That's right, it's basically free money and leaving funds unused in a contract is wasting a lot of potential. The way these...

  • How to use Polygon (Matic) in your Dapp

    Deploying and onboarding users to  Polygon  to avoid the high gas costs

  • Web3 1.2.5: Revert reason strings

    How to use the new feature

    A new Web3 version was just released and it comes with a new feature that should make your life easier. With the latest version 1.2.5, you can now see the the revert reason if you use the new handleRevert option. You can activate it easily by using web3.eth.handleRevert = true . Now when you use...

  • Gaining back control of the internet

    How Ocelot is decentralizing cloud computing

    I recently came across an ambitious company that will completely redefine the way we are using the internet. Or rather, the way we are using its underlying infrastructure which ultimately is the internet. While looking at their offering, I also learned how to get anonymous cloud machines, you...

  • Devcon 5 - Review

    Impressions from the conference

    I had a lot to catch up on after Devcon. Also things didn't go quite as planned, so please excuse my delayed review! This year's Devcon was certainly stormy with a big typhoon warning already on day 1. Luckily (for us, not the people in Tokyo), it went right past Osaka. Nevertheless, a lot of...

© 2024 Solidity Dev Studio. All rights reserved.

This website is powered by Scrivito, the next generation React CMS.