If you speak Spanish and would rather prefer a video, here’s a step by step tutorial explaing how to use Defiant to swap BTC for RBTC (or vice-cersa) using RSK Powpeg:
When Defiant first started it was just an app for P2P trading. After a short while in the streets, we realised that, to be competitive, we needed to add wallet functionalities to the app.
In doing so, we had to decide which blockchains would be added, and apart from Bitcoin and Ethereum, we went all in with RSK, a side chain of Bitcoin with all the power of Smart Contracts.
RSK’s strength came from joining the programability of smart contracts with the security of Bitcoin. That last part due to the fact that for every one RBTC (RSK’s base coin) in the RSK system, there was exactly one BTC locked.
This ensures that the RBTC price is pegged to the BTC price, and that the whole blockchain is backed by those locked BTCs.
There has been a number of ways a user that has BTC can “change” it for RBTC, CoinSwitch, Kucoin, Bitfinex, etc.
When we started, we decided CoinSwitch was the simplest way for us to provide a simple and clean way for our users to change their BTCs for RBTCs, and so we leveraged their API and the solution holded up for a few good months.
CoinSwitch gave us what we needed at the time, but there were a few things that didn’t click with us. The fees weren’t always grateful, operations could take hours (sometimes up to a day) to complete and primarily, CoinSwitch is centralized which means there is people in between and that we really didn’t like…
When, last month, CoinSwitch stopped giving liquidity to all RSK pairs (BTC-RBTC and BTC-DOC) we decided it was time we pointed in a new direction…
Apart from the solutions mentioned above, there has always been a clean and simple way to go from BTC to RBTC (and viceversa), the native way, the Powpeg (formerly Two Way Peg).
This is the system that gives RSK its liquidity, the mechanism with which for an RBTC to be released into the system, a BTC has to be locked.
How does it work?
There are two players in this game, a Federation Address and a Bridge.
- The federation address is a Bitcoin address that holds the BTCs for locking.
- The bridge is a pre-compiled smart contract that lives inside the RSK network and manages the RBTC that is released into the system.
The process is (roughly) this:
- A user has a Legacy address with BTC (we’ll go more in depth about this later)
- The user transfers BTC to the federation address (the amount must be, at the moment, at least 0.01 BTC and less than the max amount allowed to be locked in the network, at the moment, 1000 BTCs)
- The user pays the fees for the transfer (this is the only fee)
- The federation address receives it and waits for 100 confirmations.
- After the confirmations, the bridge (on the RSK side) is allowed to release the funds.
- The bridge sends the amount to the matching RBTC address (more on this also later)
- We have RBTC, we celebrate 🎉🎉🎉
- A user has an RBTC address with funds that matches a Legacy one on the Bitcoin side (later).
- The user transfers RBTC to the bridge (the amount must be, at the moment, more than 0.008 RBTC)
- The user pays the fees for the transfer (this is the first fee, but it’s very low)
- The bridge receives it and waits for 4000 blocks (about 100 BTC confirmations on the other side).
- After the blocks, the bridge releases the funds to the BTC network.
- The federation address sends the amount to the matching BTC Legacy address and charges that transference fee to the user (this is the second fee)
- We have BTC, we celebrate 🎉🎉🎉
- From BTC to RBTC (Peg-In):
- The network fee for transfering BTC to the federation address
- From RBTC to BTC (Peg-Out):
- The network fee for transfering RBTC to the bridge
- The network fee for the transference of BTC the federation address sends you
This is the “tricky” part of the process.
In order for the Peg-In and Peg-Out to work correctly, at the moment (there are changes being developed), the address that sends the funds from the BTC side has to be a Legacy one and there has to be a correlation between that address and the address that receives the RBTC on the other side.
This relation is the following: the derivation path that generated the address on the BTC side needs to be the same to generate the RBTC address. The only way the bridge can know to which address the RBTCs should be sent (when pegging in) is by respecting the derivation path.
An example (with derivation paths)
The derivation path is what “describes” the way a blockchain address should be constructed. The BIP-44 explains this in more detail.
Imagine I have a 12 word seed phrase (never use this seed phrase):
abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon
If I use Defiant to import it and generate a wallet with BTC and RBTC, I get this set of addresses:
- BTC Segwit External (derivation path m/84’/0’/0’/0/0): bc1qch27t4mg2ju20gcs22h8de945acge9pfhzx6kl
- BTC Legacy External (derivation path m/44’/0’/0’/0/0): 16Zu6SqMovwr81EPeHdp1HX9DXsP41cMHh
- RBTC (derivation path m/44’/137’/0’/0/0): 0x711c00F4FE4513B0CFe2d3c6032F75268970eD74
Note that each address is different due to each derivation path being different.
Now let’s import the seed phrase again but let’s configure Defiant to generate the RBTC address using the BTC Legacy External derivation path:
- BTC Segwit External (m/84’/0’/0’/0/0): bc1qch27t4mg2ju20gcs22h8de945acge9pfhzx6kl
- BTC Legacy External (m/44’/0’/0’/0/0): 16Zu6SqMovwr81EPeHdp1HX9DXsP41cMHh
- RBTC (m/44’/0’/0’/0/0): 0x87A5c8273fFe7574e5bc7290F568bae337578AeF
Now the RBTC address is different!
That’s because I changed the derivation path.
And now with all this information, let’s see how we solved the process of the Powpeg in Defiant
We wanted to make it extremely easy for our users to change BTC for RBTC (and viceversa), so we adjusted our wallet to integrate “seamlessly” with the great system that RSK had developed.
Setting up tester mode (this post section will desapear in a few days)
The Powpeg is curently being tested, so, to enable it, there are a few steps required.
- Go to the drawer menu
- Scroll to the bottom of the drawer
- Tap rapidly 7 times on the version of the app (pretty cool right?)
- Go to settings, you will see a new item ‘Tester settings’
- Tap on it
- In the next page, enable the Powpeg
Setting up the wallet
As described above, there is a relation between your BTC address and your RBTC address when using the Powpeg, so you can’t use a regular wallet generated in Defiant, but despair not! We got you covered.
With a regular wallet follow these steps.
Note: The whole process will be shown on testnet, but doing it on mainnet is exactly the same. In fact, you can try doing it in testnet first to be sure and then mainnet 😉😉
- From your wallet’s dashboard, go to “change”
- Select BTC and RBTC and press continue
- A message will show up explaining that this wallet is not correclty configured for the Powpeg (we wanted this to happen)
- Let’s tap on “create”. This will create a new wallet using the same seed pharase and coins but using the First BTC Legacy External derivation path to generate the RSK address (m/44’/0’/0’/0/0 for mainnet and m/44’/1’/0’/0/0 for testnet)
- Wait for the wallet to finish creating
- When it finishes, we have 2 wallets, the original one and the new ‘PEG’ one
Change BTC for RBTC (PegIn)
With a wallet correctly configured we’ll make the change
- Go to the PEG wallet (created above)
- Tap on change
- Choose BTC and RBTC and tap on continue
- Enter the amount you want to change (we will use the minimum here) and tap on continue
- Verify the information and scroll to the bottom of the page
- Take a look at the warning “THIS WILL TAKE A FEW HOURS” and, when ready, tap on continue
- Enter your PIN
- When the operation gets dispatched, you’ll be redirected to the “done” page. Tap on the arrow to continue
- You just changed BTC for RBTC using the Powpeg. Have a party with friends 🥳🥳🥳
Change RBTC for BTC (PegOut)
To change RBTC for BTC the process is exactly the same. The minimum changes a little and the time for completion is different, but all in all, it’s the same. Just change the origin coin and the destination coin.
How to see the progress of the swap?
As these changes take a long time to finish, we wanted to make it simple for users to check how it’s going so:
- Go to the History section
- Scroll to the right until you reach the Powpeg history section and tap on it
- A list of your Powpeg operations will be shown
- Tap on the operation you just made
- The “show history operation” is shown
- Scroll to the bottom
- A progress bar is shown with the current state of the operation
- As confirmations/blocks pass by, the bar will fill up until it reaches 100%. At this point, you should have received your BTCs (or RBTCs if you were changing the other way around).
You can also tap on the “receiver” address and see if you received the changed amount in the explorer.
Notes and “caveats”
As mentioned above, the BTC address that does the PegIn needs to be Legacy. If you know how Bitcoin UTXOs work, you should ask “but, if I send using more than one UTXO and mix addresses up?”
Great question! Yes, the BTC you send can come from multiple UTXOs that are from different addresses and can be Legacy, Segwit, Segwit Compatible, etc. In fact, we (Defiant) do this…
The first address in the inputs HAS TO BE A LEGACY ONE
Meaning that that address has to have some BTC, maybe not all the amount you are trying to swap, but it has to have some BTC.
If you don’t do this and the first address is not Legacy… You’ll lose your funds.
Note: Soon you’ll be able to choose the RBTC reception address, but as of right now, you cannot.
These changes take time, from 17 hours to 34 hours depending on the direction of the change.
At the moment, this will not be changing in a near future as it is a security measure.
The minimums are high, we know it. Sadly, it’s not in our control how that is managed. We’ll probably have a solution for smaller amounts soon (stay tuned).
Note: Soon the minimum amounts will be lowered, but as of right now, they are what they are.