Sidechains: Alpha Sidechain Tutorial

This tutorial was authored by Albert Szmigielski and has been originally published on CryptoIQ

In this tutorial we will take a practical look at sidechains [1]. We will concentrate on the Elements project [2] and its first sidechain known as Alpha . Alpha is a developer sidechain that is pegged to Bitcoin’s testnet [3]. In order to play around with sidechains in general and with Alpha in particular we need to have the mainchain installed on our machine. The mainchain in our case is the bitcoin testnet. Then we will need to install the Alpha sidechain. Let’s proceed. The instructions below are for Linux Ubuntu.

Step 1 — Install bitcoind & alphad

  • First we need to get some dependencies:

sudo apt-get install build-essential
sudo apt-get install libtool autotools-dev autoconf pkg-config
sudo apt-get install libssl-dev libboost-all-dev libdb4.8-dev libdb4.8++-dev
  • If you do not have git installed on your machine:
sudo apt-get install git
  • To be organized let’s create a sidechains directory:
mkdir sidechains
  • Now let’s go ahead and clone the Elements Project:
git clone https://github.com/ElementsProject/elements 
cd elements
  • let’s install the mainchain:
git chekout mainchain
./autogen.sh && ./configure && make
  • move the newly built binaries out of the src folder:
mv src/bitcoin{d,-cli,-tx} ../
  • let’s install the alpha sidechain:
git checkout alpha
./autogen.sh && ./configure && make
  • move the newly build binaries out of the src folder:
mv src/alpha{d,-cli,-tx} ../ 
cd..

Step 2 — Run and Synch bitcoin testnet

  • First let’s set some values for the RPC user and password so we do not need to retype them each time:
RPC_USER=bitcoin_user RPC_PASS=qwertyu873nld9j4n09sn3mm
  • Now let’s run bitcoind in testnet mode
./bitcoind -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS -testnet -txindex -daemon
  • While the testnet is synching, we can start alphad. I would recommend opening a new terminal window. We have to set the RPC values in this terminal instance as well. Then navigate to the elements directory, and then run alphad:
RPC_USER=bitcoin_user 
RPC_PASS=qwertyu873nld9j4n09sn3mm
cd elements
./alphad -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS -testnet -rpcconnect=127.0.0.1 -rpcconnectport=18332 -tracksidechain=all -txindex -blindtrust=true -daemon
  • You can now take a break and give both chains time to download their blockchains

Step 3 — Make sure bitcoind and alphad are running

bitcoin-cli -testnet -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS getblockcount
alpha-cli -testnet -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS getblockcount
  • both commands should produce a numeric output. At the time of this writing Bitcoin testnet is in the 720,000’s block [4], and the alpha testnet is in the 130,000’s block [5].
  • Step 4 — Get some bitcoin testnet coins
bitcoin-cli -testnet -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS getnewaddress
  • Once you have your testnet address you can go visit any of the testnet faucets to receive some coins. For example try https://testnet-faucet.elementsproject.org/
  • check your balance (remember it takes a few blocks before you see the transfer)

bitcoin-cli -testnet -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS getblalance

Step 5 — Install the necessary tools to transfer funds between chains

  • First we will need the secp256k1 library, put it in the sidechains folder:
git clone https://github.com/bitcoin/secp256k1
cd secp256k1
./autogen.sh && ./configure — with-bignum=no && make
make DESTDIR=`pwd`/install install
cd ..
  • Next up is contracthashtool:
git clone https://github.com/blockstream/contracthashtool
cd contracthashtool
make CXXFLAGS=”-I../secp256k1/install/usr/local/include -L ../secp256k1/install/usr/local/lib -static”
cd..
  • Now we will need Jeff Garzik’s python RPC library:
git clone https://github.com/jgarzik/python-bitcoinrpc

Step 6 — Modify sidechains/elements/contrib/sidechain-manipulation.py to include your credentials

  • In our case the lines in question are #53 and 54. Originally they look like the following:
sidechain_url = “http://user:pass@127.0.0.1:4241"
bitcoin_url = “http://user:pass@127.0.0.1:18332"
  • We want to change user to our own RPC_USER set before and pass to our own RPC_PASS
     In our case it would be:
sidechain_url = “http://bitcoin_user:qwertyu873nld9j4n09sn3mm@127.0.0.1:4241" 
bitcoin_url = “http://bitcoin_user:qwertyu873nld9j4n09sn3mm@127.0.0.1:18332"
  • don’t forget to save the file

Step 7 — Send coins to the alpha sidechain

  • Now, we are ready to transfer some tBTC to the Alpha sidechain
  • make sure you’re in the elements directory
./contrib/sidechain-manipulation.py generate-one-of-one-multisig sidechain-wallet
  • we got the following output:
./elements/contrib/sidechain-manipulation.py generate-one-of-one-multisig sidechain-wallet 
One-of-one address: 22E8UzLXiZrtSZfqqmEdjqJsk1RBqdpnPmbXYkDVHxrveGb2DVNcic9ksGGS2xiXAE2hvqGNEJp3zoijb
P2SH address: 2N8qM71fbG1DiWcuDCLP7negcKq3X1rmhyE
  • Now we are ready to send coins to the Alpha sidechain
     We will use the send-to-sidechain command; as arguments it takes the sidechain address and amount of coins to send
send-to-sidechain <sidechain P2SH address> <amount to send>
  • In our case we do the following:
send-to-sidechain 2N8qM71fbG1DiWcuDCLP7negcKq3X1rmhyE 0.25
  • The output looks like the following:
./elements/contrib/sidechain-manipulation.py send-to-sidechain 2N8qM71fbG1DiWcuDCLP7negcKq3X1rmhyE 0.25 
Sending 0.25 to 2MtrP6754YcjN7gc7Z7TgjqLxAEjxMDJJUp…
(nonce: 2452357eb5e1e471378ebda207e4305b)
sendrawtransaction — Sent tx with id d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b9

Step 7a — (Optional) Check the transactions

  • Switch to the terminal where you are running bitcoind and issue the following command:
gettransaction <transaction id>

In our case:
 bitcoin-cli -testnet -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS gettransaction d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b

bitcoin-cli -testnet -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS gettransaction d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b9 
{
“amount” : -0.25000000,
“fee” : -0.00011363,
“confirmations” : 554,
“blockhash” : “0000000000002825aa76d1edcbbc6154dac41382e99163668069ad215ff0f6ad”,
“blockindex” : 4,
“blocktime” : 1456386026,
“txid” : “d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b9”,
“walletconflicts” : [
],
“time” : 1456385130,
“timereceived” : 1456385130,
“bip125-replaceable” : “no”,
“details” : [
{
“account” : “”,
“address” : “2MtrP6754YcjN7gc7Z7TgjqLxAEjxMDJJUp”,
“category” : “send”,
“amount” : -0.25000000,
“vout” : 0,
“fee” : -0.00011363
}
],
“hex” : “0100000001b9636e0be8c05da39a4bcc93249582c2a3af864507a72c0f80e484012bca3497000000006b483045022100b7fb3f55063c3cf678db4385460ba93cbcdcbe007fec90be4a738335f4d72ba302202f7051cca79b057df6b58d4e45b81edbcbe0c04d9dd43f87e3ba28232568ca200121022ca1cc72f06578ae084f802286398608c1cc5f165e183240e1267002843682b2feffffff0240787d010000000017a914119e47f3209297c306b5ccbfbaa97f339f837328879d19c323000000001976a914a63d1c27021d954d7dbd2c0b960bd412a251771d88ac00000000”
}

Now we wait 10 bitcoin testnet blocks before we can claim the funds on the Alpha sidechain

Step 8 — Claim the coins to the alpha sidechain

  • We will use the claim-on-sidechain command, as arguments it takes the sidechain address, the nonce, and the transaction id we got when we sent coins to the sidechain:
claim-on-sidechain <sidechain P2SH address> <nonce> <tx id>

In our case we do the following:
 claim-on-sidechain 2N8qM71fbG1DiWcuDCLP7negcKq3X1rmhyE 2452357eb5e1e471378ebda207e4305b d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b9 
 The output looks like the following:

./elements/contrib/sidechain-manipulation.py claim-on-sidechain 2N8qM71fbG1DiWcuDCLP7negcKq3X1rmhyE 2452357eb5e1e471378ebda207e4305b d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b9 Redeeming from utxo 4a466058a8754698a95ff29bc8bece97e1e131dfda29f76d30c958903fd85eb0:1 (value 20994180.93597788, refund 20994180.68597788) 
Success!
Resulting txid: 2f7abb3d4dee1183ce7d85a488cef8e0692926879672ffd57b1db8b3dbd4d2f9

Now we need to wait 144 alpha sidechain testnet blocks before we can redeem the coins

Step 8a — (Optional) check the transaction on the alpha sidechains
 First we get the raw transaction using the tx id we got from claim-on-sidechain :

./alpha-cli -testnet -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS getrawtransaction “2f7abb3d4dee1183ce7d85a488cef8e0692926879672ffd57b1db8b3dbd4d2f9” 
0100000001b05ed83f9058c9306df729dadf31e1e197cebec89bf25fa9984675a85860464a01000000fd4a030575029000a1015128503253482452357eb5e1e471378ebda207e4305baafdf837b48134e18b7d6be3a8b29cb6f6e1aa184d79010400000098e20e338800cd917efcf4e2609571eadc6f6e3d37dd2d81572c000000000000e9517719b85d5bd50f352c1c6f13f68390f1cd659e182069abb8f65265eddf32eaafce56c0ff3f1ad4fc19483b00000009a4f870e9e88b6a4a96782dac161292d4995873901e8c77980291fd9b16d31de8e27ec97035649207e35c81ef76fe54c90e03554cbbbb548eaeb993455fca90f5a9e7e2d352c623073853335b0b0175073a22a3dd6c684fb71ff56a0e1f19def5b9521daeb29fe36e006c9d4e3566add30ebdd5429eac9c9bb77169b830eb3bd9437dfe584b23aadd7ef87f20091635b2c103c25f54f2b9f2cb625fd0f7aebcdc8516c3f2899a9d30799a34ba0b15e9be5857ea87e374fea382198b5cdbc14c72637c3c0826c54294fc9ffef94c229333f9de85eb42183159e2c3c06e8d2f11793c66e87d9743628af4c252d22895a0fa49863ee3868e6000a4b5195579785f382161011021bacb2b1c88cc744c2dfab6a9338303fae257036c6f009cc6eb501b037f0e00514ce00100000001b9636e0be8c05da39a4bcc93249582c2a3af864507a72c0f80e484012bca3497000000006b483045022100b7fb3f55063c3cf678db4385460ba93cbcdcbe007fec90be4a738335f4d72ba302202f7051cca79b057df6b58d4e45b81edbcbe0c04d9dd43f87e3ba28232568ca200121022ca1cc72f06578ae084f802286398608c1cc5f165e183240e1267002843682b2feffffff0240787d010000000017a914119e47f3209297c306b5ccbfbaa97f339f837328879d19c323000000001976a914a63d1c27021d954d7dbd2c0b960bd412a251771d88ac0000000051004cb501000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0403ad000bffffffff04a3f46c230000000017a914349ef962198fcc875f45e786598272ecace9818d873f50dd010000000017a914349ef962198fcc875f45e786598272ecace9818d870000000000000000226a20000000000000000000000000000000000000000000000000589ea7610000000000000000000000000a6a08bf7f0234cf0300000000000051ffffffff0000000000000000020000000000000000000000000000000000000000000000000000000000017d784000007d6303ad000b20d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b90000149eac001049d5c38ece8996485418421f4a01e2d7206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000b467029000b275a914aafdf837b48134e18b7d6be3a8b29cb6f6e1aa1887680000000000000000000000000000000000000000000000000000077568dc36bc1c000037206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000149eac001049d5c38ece8996485418421f4a01e2d7b300000000

Now we decode the raw transaction:

./alpha-cli -testnet -rpcuser=$RPC_USER -rpcpassword=$RPC_PASS decoderawtransaction 0100000001b05ed83f9058c9306df729dadf31e1e197cebec89bf25fa9984675a85860464a01000000fd4a030575029000a1015128503253482452357eb5e1e471378ebda207e4305baafdf837b48134e18b7d6be3a8b29cb6f6e1aa184d79010400000098e20e338800cd917efcf4e2609571eadc6f6e3d37dd2d81572c000000000000e9517719b85d5bd50f352c1c6f13f68390f1cd659e182069abb8f65265eddf32eaafce56c0ff3f1ad4fc19483b00000009a4f870e9e88b6a4a96782dac161292d4995873901e8c77980291fd9b16d31de8e27ec97035649207e35c81ef76fe54c90e03554cbbbb548eaeb993455fca90f5a9e7e2d352c623073853335b0b0175073a22a3dd6c684fb71ff56a0e1f19def5b9521daeb29fe36e006c9d4e3566add30ebdd5429eac9c9bb77169b830eb3bd9437dfe584b23aadd7ef87f20091635b2c103c25f54f2b9f2cb625fd0f7aebcdc8516c3f2899a9d30799a34ba0b15e9be5857ea87e374fea382198b5cdbc14c72637c3c0826c54294fc9ffef94c229333f9de85eb42183159e2c3c06e8d2f11793c66e87d9743628af4c252d22895a0fa49863ee3868e6000a4b5195579785f382161011021bacb2b1c88cc744c2dfab6a9338303fae257036c6f009cc6eb501b037f0e00514ce00100000001b9636e0be8c05da39a4bcc93249582c2a3af864507a72c0f80e484012bca3497000000006b483045022100b7fb3f55063c3cf678db4385460ba93cbcdcbe007fec90be4a738335f4d72ba302202f7051cca79b057df6b58d4e45b81edbcbe0c04d9dd43f87e3ba28232568ca200121022ca1cc72f06578ae084f802286398608c1cc5f165e183240e1267002843682b2feffffff0240787d010000000017a914119e47f3209297c306b5ccbfbaa97f339f837328879d19c323000000001976a914a63d1c27021d954d7dbd2c0b960bd412a251771d88ac0000000051004cb501000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0403ad000bffffffff04a3f46c230000000017a914349ef962198fcc875f45e786598272ecace9818d873f50dd010000000017a914349ef962198fcc875f45e786598272ecace9818d870000000000000000226a20000000000000000000000000000000000000000000000000589ea7610000000000000000000000000a6a08bf7f0234cf0300000000000051ffffffff0000000000000000020000000000000000000000000000000000000000000000000000000000017d784000007d6303ad000b20d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b90000149eac001049d5c38ece8996485418421f4a01e2d7206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000b467029000b275a914aafdf837b48134e18b7d6be3a8b29cb6f6e1aa1887680000000000000000000000000000000000000000000000000000077568dc36bc1c000037206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000149eac001049d5c38ece8996485418421f4a01e2d7b300000000 
{
“txid” : “2f7abb3d4dee1183ce7d85a488cef8e0692926879672ffd57b1db8b3dbd4d2f9”,
“version” : 1,
“locktime” : 0,
“fee” : 0.00000000,
“vin” : [
{
“txid” : “4a466058a8754698a95ff29bc8bece97e1e131dfda29f76d30c958903fd85eb0”,
“vout” : 1,
“scriptSig” : {
“asm” : “75029000a1 81 503253482452357eb5e1e471378ebda207e4305baafdf837b48134e18b7d6be3a8b29cb6f6e1aa18 0400000098e20e338800cd917efcf4e2609571eadc6f6e3d37dd2d81572c000000000000e9517719b85d5bd50f352c1c6f13f68390f1cd659e182069abb8f65265eddf32eaafce56c0ff3f1ad4fc19483b00000009a4f870e9e88b6a4a96782dac161292d4995873901e8c77980291fd9b16d31de8e27ec97035649207e35c81ef76fe54c90e03554cbbbb548eaeb993455fca90f5a9e7e2d352c623073853335b0b0175073a22a3dd6c684fb71ff56a0e1f19def5b9521daeb29fe36e006c9d4e3566add30ebdd5429eac9c9bb77169b830eb3bd9437dfe584b23aadd7ef87f20091635b2c103c25f54f2b9f2cb625fd0f7aebcdc8516c3f2899a9d30799a34ba0b15e9be5857ea87e374fea382198b5cdbc14c72637c3c0826c54294fc9ffef94c229333f9de85eb42183159e2c3c06e8d2f11793c66e87d9743628af4c252d22895a0fa49863ee3868e6000a4b5195579785f382161011021bacb2b1c88cc744c2dfab6a9338303fae257036c6f009cc6eb501b037f0e00 1 0100000001b9636e0be8c05da39a4bcc93249582c2a3af864507a72c0f80e484012bca3497000000006b483045022100b7fb3f55063c3cf678db4385460ba93cbcdcbe007fec90be4a738335f4d72ba302202f7051cca79b057df6b58d4e45b81edbcbe0c04d9dd43f87e3ba28232568ca200121022ca1cc72f06578ae084f802286398608c1cc5f165e183240e1267002843682b2feffffff0240787d010000000017a914119e47f3209297c306b5ccbfbaa97f339f837328879d19c323000000001976a914a63d1c27021d954d7dbd2c0b960bd412a251771d88ac00000000 1 0 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0403ad000bffffffff04a3f46c230000000017a914349ef962198fcc875f45e786598272ecace9818d873f50dd010000000017a914349ef962198fcc875f45e786598272ecace9818d870000000000000000226a20000000000000000000000000000000000000000000000000589ea7610000000000000000000000000a6a08bf7f0234cf03000000000000 1”,
“hex” : “0575029000a1015128503253482452357eb5e1e471378ebda207e4305baafdf837b48134e18b7d6be3a8b29cb6f6e1aa184d79010400000098e20e338800cd917efcf4e2609571eadc6f6e3d37dd2d81572c000000000000e9517719b85d5bd50f352c1c6f13f68390f1cd659e182069abb8f65265eddf32eaafce56c0ff3f1ad4fc19483b00000009a4f870e9e88b6a4a96782dac161292d4995873901e8c77980291fd9b16d31de8e27ec97035649207e35c81ef76fe54c90e03554cbbbb548eaeb993455fca90f5a9e7e2d352c623073853335b0b0175073a22a3dd6c684fb71ff56a0e1f19def5b9521daeb29fe36e006c9d4e3566add30ebdd5429eac9c9bb77169b830eb3bd9437dfe584b23aadd7ef87f20091635b2c103c25f54f2b9f2cb625fd0f7aebcdc8516c3f2899a9d30799a34ba0b15e9be5857ea87e374fea382198b5cdbc14c72637c3c0826c54294fc9ffef94c229333f9de85eb42183159e2c3c06e8d2f11793c66e87d9743628af4c252d22895a0fa49863ee3868e6000a4b5195579785f382161011021bacb2b1c88cc744c2dfab6a9338303fae257036c6f009cc6eb501b037f0e00514ce00100000001b9636e0be8c05da39a4bcc93249582c2a3af864507a72c0f80e484012bca3497000000006b483045022100b7fb3f55063c3cf678db4385460ba93cbcdcbe007fec90be4a738335f4d72ba302202f7051cca79b057df6b58d4e45b81edbcbe0c04d9dd43f87e3ba28232568ca200121022ca1cc72f06578ae084f802286398608c1cc5f165e183240e1267002843682b2feffffff0240787d010000000017a914119e47f3209297c306b5ccbfbaa97f339f837328879d19c323000000001976a914a63d1c27021d954d7dbd2c0b960bd412a251771d88ac0000000051004cb501000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0403ad000bffffffff04a3f46c230000000017a914349ef962198fcc875f45e786598272ecace9818d873f50dd010000000017a914349ef962198fcc875f45e786598272ecace9818d870000000000000000226a20000000000000000000000000000000000000000000000000589ea7610000000000000000000000000a6a08bf7f0234cf0300000000000051”
},
“sequence” : 4294967295
}
],
“vout” : [
{
“value” : 0.25000000,
“serValue” : “0000000000000000000000000000000000000000000000000000000000017d78400000”,
“n” : 0,
“scriptPubKey” : {
“asm” : “OP_IF 721069 d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b9 0 0 9eac001049d5c38ece8996485418421f4a01e2d7 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 OP_REORGPROOFVERIFY OP_ELSE 144 OP_NOP3 OP_DROP OP_HASH160 aafdf837b48134e18b7d6be3a8b29cb6f6e1aa18 OP_EQUAL OP_ENDIF”,
“hex” : “6303ad000b20d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b90000149eac001049d5c38ece8996485418421f4a01e2d7206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000b467029000b275a914aafdf837b48134e18b7d6be3a8b29cb6f6e1aa188768”,
“type” : “withdrawout”
}
},
{
“value” : 20994180.68597788,
“serValue” : “0000000000000000000000000000000000000000000000000000077568dc36bc1c0000”,
“n” : 1,
“scriptPubKey” : {
“asm” : “6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 9eac001049d5c38ece8996485418421f4a01e2d7 OP_WITHDRAWPROOFVERIFY”,
“hex” : “206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000149eac001049d5c38ece8996485418421f4a01e2d7b3”,
“type” : “withdraw”
}
}
]
}
  • We can see the values both on the mainchain and the sidechain sides.

WARNING!
 The Alpha Sidechain has been down since Feb 22, last block reported is 130238, so the next steps are not tested on a live network. (we need the 144 confirmations)

Step 9 — Spend funds from the claim

  • We will use the spend-from-claim command, as arguments it takes the transaction id we got when we claimed coins to the sidechain, and our sidechain address (starting with 22)
spend-from-claim <tx id> <sidechain address>

In our case we do the following:
 spend-from-claim 2f7abb3d4dee1183ce7d85a488cef8e0692926879672ffd57b1db8b3dbd4d2f9 22E8UzLXiZrtSZfqqmEdjqJsk1RBqdpnPmbXYkDVHxrveGb2DVNcic9ksGGS2xiXAE2hvqGNEJp3zoijb

./elements/contrib/sidechain-manipulation.py spend-from-claim 2f7abb3d4dee1183ce7d85a488cef8e0692926879672ffd57b1db8b3dbd4d2f9 22E8UzLXiZrtSZfqqmEdjqJsk1RBqdpnPmbXYkDVHxrveGb2DVNcic9ksGGS2xiXAE2hvqGNEJp3zoijb
//we have no output as the network is down

Step 10 Transfer the sidechain tokens back to the mainchain

  • First we generate a mainchain wallet address
     ./contrib/sidechain-manipulation.py generate-one-of-one-multisig mainchain-wallet
     The output will be a one-of-one address and a P2SH address
./contrib/sidechain-manipulation.py generate-one-of-one-multisig mainchain-wallet
One-of-one address: mm…
P2SH address: 2…
//we have no output as the network is down
  • Now we use the P2SH we received with the send-to-mainchain command to move the coins back. We can send back any amount, up to the original amount transferred

send-to-mainchain <P2SH mainchain address> <amount>

./contrib/sidechain-manipulation.py send-to-mainchain P2SH 0.25O
//we have no output as the network is down

That completes the loop.

Conclusion
 In this tutorial we examined the Elements project. We showed how to install both a mainchain node and an Alpha sidechain node. Then we acquired the necessary tools to accomplish transfers between the chains. We transferred funds from the mainchain to the sidechain. Sadly the Alpha sidechain is currently down so we could not complete the tutorial on a live network. We did however, include the steps necessary to spend the claim on the sidechains network and to transfer the coins back to the mainchain from the sidechain. We have only encountered one error which we describe in Appendix A. We hope that you find this tutorial useful. Sidechains may prove to be an important part of the blockchain ecosystem.

Appendix A
 Error while trying to claim-on-sidechain

./elements/contrib/sidechain-manipulation.py <strong>claim-on-sidechain 2N8qM71fbG1DiWcuDCLP7negcKq3X1rmhyE</strong> 2452357eb5e1e471378ebda207e4305b d93beb30b86971b79b9cac9e42d5bd0ed3ad66354e9d6c006ee39fb2ae1d52b9
Redeeming from utxo 4a466058a8754698a95ff29bc8bece97e1e131dfda29f76d30c958903fd85eb0:1 (value 20994180.93597788, refund 20994180.68597788)
ERROR:
[libsecp256k1] illegal argument: *outputlen >= ((flags & SECP256K1_FLAGS_BIT_COMPRESSION) ? 33 : 65)

Fix the error by modifying elements/src/script/interpreter.cpp
 as shown here: https://github.com/ElementsProject/elements/pull/84/files

References
 [1] https://blockstream.com/sidechains.pdf
 [2] https://www.elementsproject.org/
 [3] https://www.elementsproject.org/sidechains/alpha/
 [4] http://tbtc.blockr.io/
 [5] https://alpha-explorer.elementsproject.org/

https://test.elementsproject.org/sidechains/alpha/getting-started.html
 https://github.com/ElementsProject/elements/issues/59
 https://github.com/ElementsProject/elements/pull/84/files