{"id":585,"date":"2017-09-08T16:06:57","date_gmt":"2017-09-09T00:06:57","guid":{"rendered":"http:\/\/blog.richardkiss.com\/?p=585"},"modified":"2021-02-05T17:30:13","modified_gmt":"2021-02-06T01:30:13","slug":"get-your-bcash-in-under-ten-minutes-with-pycoin","status":"publish","type":"post","link":"https:\/\/blog.richardkiss.com\/?p=585","title":{"rendered":"Get Your BCash in Under Ten Minutes with pycoin"},"content":{"rendered":"<p>BCash, or Bitcoin Cash is a hard fork of Bitcoin as of August 1, 2017, so it&#8217;s pretty new. Recently, <a href=\"http:\/\/richardkiss.com\/\" target=\"_blank\" rel=\"noopener\">I&#8217;ve<\/a> been working on a big refactor of <a href=\"http:\/\/github.com\/richardkiss\/pycoin\">pycoin<\/a> to make it more flexible in handling altcoins. Creating BCash transactions seems to work now.<\/p>\n<p>If you had bitcoin on August 1, you now have bcash. Here&#8217;s how you can create transactions with BCash with nothing but the private keys and a few calls to web services.<\/p>\n<p>First, switch to a throwaway environment. I like to use a RAM disk.<\/p>\n<p>On Mac OS X:<\/p>\n<p><code>$ diskutil erasevolume HFS+ RAMDISK `hdiutil attach -nomount ram:\/\/81920`<br \/>\n$ cd \/Volumes\/RAMDISK\/<\/code><\/p>\n<p>Set up your service providers and a place to cache the source transactions. The service providers will be used to get spendables for the addresses you&#8217;re querying, as well as the source transactions.<\/p>\n<p><code>$ export PYCOIN_BCH_PROVIDERS=insight:http:\/\/blockdozer.com\/insight-api<br \/>\n$ export PYCOIN_CACHE_DIR=.\/tx-cache<\/code><\/p>\n<p>This example will query <a href=\"http:\/\/blockdozer.com\/\">blockdozer.com<\/a> to get spendables and transactions.<\/p>\n<p>Copy all your relevant WIFs to a file here. It&#8217;s okay for the file to have WIFs that aren&#8217;t used, but you will obviously need all the WIFs you wish to spend from.<\/p>\n<p><code>$ cat &gt; wifs.txt<br \/>\n(paste to terminal, one WIF per line)<\/code><\/p>\n<p>Alternatively, you can use a GPG-encrypted file.<\/p>\n<p><code>$ gpg -e &gt; wifs.gpg<br \/>\n(specify recipients, then paste to terminal, one WIF per line)<\/code><\/p>\n<p>We&#8217;ll be using python 3. Install pycoin into a virtual environment.<\/p>\n<p><code>$ python3 -m venv env<br \/>\n$ . env\/bin\/activate<br \/>\n$ pip install -e git+git@github.com:richardkiss\/pycoin.git@57b508d5208f98a304b9bd3a491c3f0049aed96b#egg=pycoin<\/code><\/p>\n<p>Verify that an address has coins to spend from.<\/p>\n<p><code>$ tx -n BCH -i 16NgXiMwRimMcSXLTf4KFwoW968btQ1GmZ<br \/>\n62263e20a70ec98cd52452ffca6f5c54fa02a45cc0a70aca14b99f2445407678\/0\/76a9143af25c9925ad4d20e1df648a82268d44445430ec88ac\/1990000\/0\/0\/0<br \/>\nb0011baf07830ec04d5adb66b1503ad6c9498dfe6c5590f05c8226c9f83fa0df\/0\/76a9143af25c9925ad4d20e1df648a82268d44445430ec88ac\/1185613\/0\/0\/0<\/code><\/p>\n<p>Create an unsigned transaction that contains just the inputs.<\/p>\n<p><code>$ tx -n BCH -a -i 16NgXiMwRimMcSXLTf4KFwoW968btQ1GmZ -o inputs.bin<br \/>\nwarning: transaction has no outputs<\/code><\/p>\n<p>Replace the address above with the address you want to send coins from.<\/p>\n<p>Add an output. I&#8217;m sending all coins to 1HeJ94rPmgSWbPTQqAyB2Vp7ZDqyPvyXsz. You should use your own address.<\/p>\n<p><code>$ tx -n BCH -a inputs.bin 1HeJ94rPmgSWbPTQqAyB2Vp7ZDqyPvyXsz -o utx.bin<br \/>\nall incoming transaction values validated<\/code><\/p>\n<p>Sign the transaction, using BCH rules.<\/p>\n<p><code>$ tx -n BCH utx.bin -f wifs.gpg -o tx.hex<br \/>\nsigning...<br \/>\nall incoming transaction values validated<\/code><\/p>\n<p>You could do all this in one line (fetch the inputs, add the output, sign), as follows:<\/p>\n<p><code>$ tx -n BCH `tx -n BCH -i 16NgXiMwRimMcSXLTf4KFwoW968btQ1GmZ | xargs` 1HeJ94rPmgSWbPTQqAyB2Vp7ZDqyPvyXsz -f wifs.gpg<\/code><\/p>\n<p>but it&#8217;s long and a bit confusing, and causes word wrap in the blog.<\/p>\n<p>View the transaction. Note that the transaction does NOT validate on the bitcoin (BTC) network. This is due to the replay protection in BCH (the hash type of the signature is 0x41, which is invalid in BTC).<\/p>\n<p><code>$ tx -a -n BTC tx.hex<br \/>\n(lots of output)<\/code><\/p>\n<p>It does validate on the BCH network.<\/p>\n<p><code>$ tx -a -n BCH tx.hex<br \/>\n(lots of output)<\/code><\/p>\n<p>Add -d to disassemble it (just for fun).<\/p>\n<p><code>$ tx -ad -n BCH tx.hex<br \/>\n(lots of output)<\/code><\/p>\n<p>View the hex.<\/p>\n<p><code>$ cat tx.hex<br \/>\n0100000002dfa03ff8c926825cf090556cfe8d49c9d63a50b166db5a4dc00e8307af1b01b0000000008b483045022100879c1b9cb199865bb77892b3ccdddc1f52102aa3da3024556f864e34d380108e02205b3f17c412df05ebb7984f472dcbe574fb0472bee3fa9ac3032e90ab05e33691414104712ace3646c43b8f03662cd00d9b0cc24c17b530484bd4c377ea61dd044eca8227fb4415762fc4af5c3bc979a0d64e8d7348e6bab376efab527df65feebc634dffffffff78764045249fb914ca0aa7c05ca402fa545c6fcaff5224d58cc90ea7203e2662000000008b483045022100fb13941b3d32aa33139a1d73da7affdcb805a5e435ec307daaf3a9497c8b549e02205df9d8c729af25429b8c09940eab858324c0e91f7992961d8d1586f5b3694a48414104712ace3646c43b8f03662cd00d9b0cc24c17b530484bd4c377ea61dd044eca8227fb4415762fc4af5c3bc979a0d64e8d7348e6bab376efab527df65feebc634dffffffff01ad4d3000000000001976a914b68fb5c98ece06e3f462fbaa7fc8cd559860f2ec88ac00000000<\/code><\/p>\n<p>Copy the hex transaction to the clipboard. Head to <a href=\"http:\/\/bcc.blockdozer.com\/insight\/tx\/send\" target=\"_blank\" rel=\"noopener\">http:\/\/bcc.blockdozer.com\/insight\/tx\/send<\/a> to paste it, and send it off!<\/p>\n<p>Ditch the RAM Disk.<\/p>\n<p><code>$ cd # can't unmount while we're in the directory<br \/>\n$ hdiutil unmount \/Volumes\/RAMDISK\/<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>BCash, or Bitcoin Cash is a hard fork of Bitcoin as of August 1, 2017, so it&#8217;s pretty new. Recently, I&#8217;ve been working on a big refactor of pycoin to make it more flexible in handling altcoins. Creating BCash transactions seems to work now. If you had bitcoin on August 1, you now have bcash. &hellip; <a href=\"https:\/\/blog.richardkiss.com\/?p=585\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Get Your BCash in Under Ten Minutes with pycoin<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-585","post","type-post","status-publish","format-standard","hentry","category-computers"],"_links":{"self":[{"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=\/wp\/v2\/posts\/585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=585"}],"version-history":[{"count":4,"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions"}],"predecessor-version":[{"id":597,"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=\/wp\/v2\/posts\/585\/revisions\/597"}],"wp:attachment":[{"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.richardkiss.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}