Hackernoon logoHow to do Conversions Between BTC and R-BTC Using the Powpeg Protocol by@RSKsmart

How to do Conversions Between BTC and R-BTC Using the Powpeg Protocol

image
RSK Hacker Noon profile picture

@RSKsmartRSK

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.

Overview

Steps

  • 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.

My suggestion is to use the Electrum wallet, check out the download options. I will show you how to do this in the next steps.

Electron wallet

Go to the Electron wallet download page.

image

I am using Windows OS. I decided to use the Portable version and copied it into the C:\RSK\Electrum folder.

image

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:\RSK\Electrum folder.

I will run:

electrum-4.0.9-portable.exe --testnet
image

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.

image

You don’t need to change the default_wallet, so click the Next button again. 

image

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.

image

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.

image

The next step is very important! You must NOT choose Segwit!

So select Legacy and click the Next button.

image

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!

image

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.

image

This is the result for my example seed:

image

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

image

Now you can decide if you would like to keep your Electrum updated. It is up to you.

image

The next message is to alert us that we are in Testnet. Perfect! This is our goal.

image

This is your wallet

image

Get your BTC Legacy address

  1. Go to the third tab, Receive
  2. Change the Expires after to Never.
  3. Click the new address button
image

You will see a Bitcoin Testnet address like below.

image

My Legacy BTC testnet address is:

n2pUF7gJiFZoSpJJBxvnzPVuJ7qN9vK6aT

You can check it out in the zoomed image:

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/

image

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.

n2pUF7gJiFZoSpJJBxvnzPVuJ7qN9vK6aT

https://live.blockcypher.com/btc-testnet/address/n2pUF7gJiFZoSpJJBxvnzPVuJ7qN9vK6aT 

Take a look in some requests

image
image
image

n2pUF7gJiFZoSpJJBxvnzPVuJ7qN9vK6aT

https://live.blockcypher.com/btc-testnet/address/n2pUF7gJiFZoSpJJBxvnzPVuJ7qN9vK6aT 

You can check your balance in Blockcypher - a block explorer for Bitcoin testnet

image

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 

image
  1. Select Network RSK Testnet
  2. Select Contract Bridge
  3. Click on Interact with Contract
image

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.

image

Copy the address. For example, now it is:

2N1GMB8gxHYR5HLPSRgf9CJ9Lunjb9CTnKB

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

So

0.01 BTC = 10 mBTC

Pay to:

2N1GMB8gxHYR5HLPSRgf9CJ9Lunjb9CTnKB

Amount: 10

image

Click on the Pay button

Confirm the transaction and click the Send button.

image
image

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

image

You don’t need to export it, just copy the first address and your private key, like mine:

image

Address:

n2pUF7gJiFZoSpJJBxvnzPVuJ7qN9vK6aT 
  

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. 

https://iancoleman.io/bip39/

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

image

I saved, unzipped it in C:\RSK and renamed to rsk-utils-build

image

In the build folder, open index.html in your browser

image

For example, my path is file:///C:/RSK/rsk-utils-build/build/index.html

image

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

cUkVmQJPb5wwfW1pvqVfGAcF7fSPQN7nJGFJaYr59QoQ5pabdswR

Click on the Transform button.

Then you’ll get your RSK address.

image

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.

Next steps

Monitor your address on RSK explorer 

You can monitor your address on RSK explorer

Take a look at my RSK testnet address:

https://explorer.testnet.rsk.co/address/0xc5b5ced7337f059eff3b307284aee9f60926be7869b67c8ee198b410a2eb6e40

Note 1

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

For example:

https://explorer.testnet.rsk.co/block/0xc5b5ced7337f059eff3b307284aee9f60926be7869b67c8ee198b410a2eb6e40 

Will be

https://explorer.testnet.rsk.co/address/0xc5b5ced7337f059eff3b307284aee9f60926be7869b67c8ee198b410a2eb6e40

Note 2

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:

image

But after 100 confirmations + a minimum of 5 minutes (more than 16h hours), I got my balance!

image

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.

Final message

I showed you how to transform your BTCs in tR-BTCs 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 :)

Tags

Join Hacker Noon

Create your free account to unlock your custom reading experience.