How to do Conversions Between BTC and R-BTC Using the Powpeg Protocol
Smart Contract Platform On Top of Bitcoin
What is Powpeg?
The Powpeg is RSK’s 2-way peg protocol used to do conversions between BTC and R-BTC.
The RSK Powpeg protects private keys stored in special purpose PowHSMs based on tamper-proof secure elements, using a layered design which is referred to as defense-in-depth.
To learn more about it, I suggest you read the article Building the Most Secure, Permissionless and Uncensorable Bitcoin Peg, from Sergio Demian Lerner and Sebastian Lindner.
Part 1: how to convert BTCs in R-BTCs using RSK’s 2-way peg protocol
I strongly recommend trying the 2-way peg on Testnet, before doing it on Mainnet.
At this moment, the minimum amount of the process is 0.01 BTCs, so you must be careful not to do something wrong and lose your “real” funds.
- Get a BTC wallet with a Legacy address, like Electrum
- Have BTCs in this Legacy address
- Know the BTC address for RSK Peg using MyCrypto
- Send Bitcoin to the RSK Peg address
- Get your tBTC private key on Electrum
- Get tR-BTC address using your tBTC private key
- Use your tR-BTCs 🙂
BTC wallet with a Legacy address
Legacy address, or P2PKH, is an address format of Bitcoin which starts with a 1 in Mainnet.
It is the original BTC address. All mnemonics and private keys can generate BTC legacy addresses.
But be careful! Some wallets use the new SegWit formats and don’t allow you to send BTC from your original Legacy address.
Go to the Electron wallet download page.
I am using Windows OS. I decided to use the Portable version and copied it into the C:RSKElectrum folder.
I strongly recommend verifying the GPG signatures to make sure that your download is original, there are instructions on the same page.
If you are using Windows OS, check out some notes in the download page too.
Run Electron wallet on BTC testnet
Open the folder where you copied / installed the Electrum wallet, and run the following command to execute it on Testnet
For example, I save it in the C:RSKElectrum folder.
I will run:
It will open the Electrum app in a new window.
Configuring Electrum in the first time
This is the first time we are executing Electrum, so we need to finish the installation with some configuration in order to create a new wallet.
Although you can connect to a trusted server (and this is recommended for secure use), letting Electrum decide on a server is a good beginner option.
Select Auto connect, and click the Next button.
You don’t need to change the default_wallet, so click the Next button again.
There are some different options on the next step. I will create a Standard wallet, and then send BTCs to this new wallet.
Select the Standard wallet click the Next button.
The seed or mnemonic is a group of words which generates all addresses in a wallet, using the pattern defined at BIP39
Choose Create a new seed click the Next button.
The next step is very important! You must NOT choose Segwit!
So select Legacy and click the Next button.
Write down your seed phrase, or mnemonic, or backup phrase (all these terms mean the same), with 12 words.
This is used to recover your account, in case you lose your password.
Save your seed in a safe place.
Do not show your seed to anyone!
For example, my seed in this tutorial is
endless core secret strategy other tomato beef young snake ceiling hurdle filter
I am showing it to you because this is a tutorial and we’re using the Testnet, however I will never store real cryptos using this seed 🙂
After saving your seed, click the Next button.
Paste your seed to confirm that you can restore it properly then click the Next button.
This is the result for my example seed:
Remember: the seed phrase is the most important thing in a wallet / account!
You can also define a password to encrypt your seed. I will not do it here because it is only a tutorial
Now you can decide if you would like to keep your Electrum updated. It is up to you.
The next message is to alert us that we are in Testnet. Perfect! This is our goal.
This is your wallet
Get your BTC Legacy address
- Go to the third tab, Receive.
- Change the Expires after to Never.
- Click the new address button
You will see a Bitcoin Testnet address like below.
My Legacy BTC testnet address is:
You can check it out in the zoomed image:
BTC Testnet faucet
We need some t-BTCs to experience this process. So get test Bitcoin from Testnet Faucet.
There are a few options to get Bitcoin on Testnet. We use https://testnet-faucet.mempool.co/
This site gives us 0.01 BTCs each hour. Because 0.01 BTCs is the minimum to send in to PowPeg and we need to pay the miner fee, we must have more than 0.01 BTCs. So I will do the process to get 0.01 BTCs twice, in 2 hours.
Take a look in some requests
You can check your balance in Blockcypher – a block explorer for Bitcoin testnet
Know the BTC address for RSK Peg using MyCrypto
Now you need to know the Peg address, or RSK Federation address. The RSK Federation address is retrieved by making a Smart Contract call on RSK Testnet.
You will execute a call to the smart contract Bridge to get the address. An option is using MyCrypto
The most secure and trusted way to do it is to install the desktop version of MyCrypto on your computer. Check your version in MyCrypto’s download page
Another alternative, though not so secure is to use the web app. In this case it is important to be sure that you are in the “real” MyCrypto website, be careful not to go to a false website.
Here I will do in MyCrypto web app
In the main page, navigate to Tools => Interact with contracts or go directly to https://app.mycrypto.com/interact-with-contracts
- Select Network RSK Testnet
- Select Contract Bridge
- Click on Interact with Contract
In Read / Write Contract, select getFederationAddress to execute a call to the smart contract Bridge and get the address.
It should look like the screenshot below.
Copy the address. For example, now it is:
Send Bitcoin to the RSK Peg address
Great! Now you have more than 0.01 BTCs and you know the Peg address.
The next step is to send Bitcoin to the Peg address, or RSK Federation address.
Once you have the RSK Federation address, you can send Bitcoin to it from your Bitcoin address.
Note: You need to send a minimum amount of 0.01 BTC for conversion.
Come back to Electrum to do the transfer
Go to the Send tab
Pay attention: the value is represented in mBTC.
1 mBTC = 0.0010 BTC
0.01 BTC = 10 mBTC
Click on the Pay button
Confirm the transaction and click the Send button.
Done! Now you must be patient 🙂
You have to wait a minimum of 100 confirmations + a minimum of 5 minutes for checking your R-BTC balance.
Get your tBTC private key on Electrum
Here I am doing a tutorial, so I can share it only for educational purposes.
Go to menu Wallet => Private Keys => Export
You don’t need to export it, just copy the first address and your private key, like mine:
Private key: p2pkh:cUkVmQJPb5wwfW1pvqVfGAcF7fSPQN7nJGFJaYr59QoQ5pabdswR
Get tR-BTC address using your tBTC private key
The same private key can be used to generate addresses for different networks.
The private key for your Bitcoin address will be used to discover your tR-BTC address, and also to transfer your tR-BTC later.
RSK has a tool to get your tR-BTC in a secure way, on your desktop, without exposing your private key on the internet. So, let’s use it!
Go to github.com/rsksmart/utils.
If you do not want to compile the utility, you can download the latest release. I will use it.
Go to last release page and click on build.zip to download it
I saved, unzipped it in C:RSK and renamed to rsk-utils-build
In the build folder, open index.html in your browser
For example, my path is file:///C:/RSK/rsk-utils-build/build/index.html
Now enter your Bitcoin private key.
Do NOT include p2pkh: in the front!
My saved private key is: p2pkh:cUkVmQJPb5wwfW1pvqVfGAcF7fSPQN7nJGFJaYr59QoQ5pabdswR
So I will fill only
Click on the Transform button.
Then you’ll get your RSK address.
In my example, the RSK address is 2226ac4054d6a0ebfec341014974796ede3701de
Remember: never share your private key!
Here I am doing a tutorial, so I can share it only for educational purposes.
Monitor your address on RSK explorer
You can monitor your address on RSK explorer.
Take a look at my RSK testnet address:
Maybe the first time you search in explorer, you’ll get a block information, and not an address information. If this happens, just change block for address in the URL
Remember that the 2-way peg process takes some time.
You have to wait a minimum of 100 confirmations + a minimum of 5 minutes for checking your R-BTC balance
Probably the first time you try to check your address in explorer, it will return a Not found message. This happens because your address didn’t receive any transaction yet, so the explorer doesn’t know the address until now.
As seen in this image:
But after 100 confirmations + a minimum of 5 minutes (more than 16h hours), I got my balance!
How to use my R-BTC?
RSK has many wallets, check it out in wallet’s page on DevPortal.
The inverse process: Peg out
Additionally, I would like to do the inverse process: I will transform my R-BTC back into BTC. This process will be explained in the next article.
I showed you how to transform your BTCs in R-RBTCs and opened a door for the DeFi possibilities over Bitcoin on the RSK network.
I hope this tutorial has been helpful and I’d appreciate your feedback.
Happy with this tutorial? Share it if you like it 🙂
Create your free account to unlock your custom reading experience.