{"id":29023,"date":"2014-03-13T04:52:05","date_gmt":"2014-03-13T04:52:05","guid":{"rendered":"http:\/\/ci027cfe79e0012697"},"modified":"2014-03-13T04:52:05","modified_gmt":"2014-03-13T04:52:05","slug":"pybitcointools-multisig-tutorial-1394686325","status":"publish","type":"post","link":"https:\/\/bitcoinmagazine.com\/technical\/pybitcointools-multisig-tutorial-1394686325","title":{"rendered":"Pybitcointools Multisig Tutorial"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div><figure><img decoding=\"async\" src=\"https:\/\/bitcoinmagazine.com\/wp-content\/uploads\/2024\/11\/pybitcointools-multisig-tutorial.jpg\" title=\"\"><\/figure>\n<p>There has been a large amount of interest in multisignature transaction technology in the past year, especially with the recent announcement of <a href=\"http:\/\/cryptocorp.co\" target=\"_blank\" rel=\"noopener\">CryptoCorp<\/a>. If you want to play with multisig technology yourself on the command line, here are the gritty details of how to do it. First, run <code>sudo pip install bitcoin<\/code> to install the Python Bitcoin library. Then, to generate the three private keys, run the following:<\/p>\n<pre><code>&gt; k1=`pybtctool random_key`&gt; k2=`pybtctool random_key`&gt; k3=`pybtctool random_key`&gt; p1=`pybtctool privtopub $k1`&gt; p2=`pybtctool privtopub $k2`&gt; p3=`pybtctool privtopub $k3`<\/code><\/pre>\n<p>You now have three private keys and three public keys; run <code>echo $k1<\/code>, <code>echo $p3<\/code>, etc to see these values in the raw form. Now, we make the multisig script and address:<\/p>\n<pre><code>&gt; script=`pybtctool mk_multisig_script $p1 $p2 $p3 2 3`&gt; address=`pybtctool scriptaddr $script`<\/code><\/pre>\n<p>Let\u2019s see what these values are:<\/p>\n<pre><code>&gt; echo $script5241045f4af45e3a7a86393c4ab9540cca382d46f10345b3ffcbb058089788550d167b7c079870d00da9728f8589fa5bbe0a8d62eadd56d37f3be6bc8145fe9a27437b4104509394eade56d900e90146e4bdf14f567b845ab0da986476253fe438f12032a248bbf2c16d28409b2961b3a3f797832ad195a8cef96589371271e2df6195cf804104ef6c434a854996e63cf650c0ba813993e90eef564bc78ad14768de51ac6b1bb00c5fe3381a923567162e8821e86ee28fbe4a25325f59cf6ede87c15d5af2881e53ae&gt; echo $address3DDifvXMEQBEvn7dVR1wF5RXveA5MxEXek<\/code><\/pre>\n<p>Due to randomness, your values will be different, but of the same general form. Notice the <code>3<\/code> at the start of the address. Now, send some BTC to your address, and run the following to make sure you actually received the funds.<\/p>\n<pre><code>&gt; pybtctool unspent $address[{\"output\": \"9e123938b7625ef7807f31ad61c3b818484fed93eb951d981abd83413005080f:0\", \"value\": 20000}]<\/code><\/pre>\n<p>Now, we can make the transaction, sending the funds to the <a href=\"https:\/\/www.mfoundation.org\/\" target=\"_blank\" rel=\"noopener\">Methuselah Foundation<\/a>\u2018s donation address:<\/p>\n<pre><code>&gt; tx=`pybtctool mktx 9e123938b7625ef7807f31ad61c3b818484fed93eb951d981abd83413005080f:0 1GRF5cmvAqQPNVPRHe1TpMZGS1mYFHFQHu:10000`&gt; echo $tx01000000010f0805304183bd1a981d95eb93ed4f4818b8c361ad317f80f75e62b73839129e0000000000ffffffff0110270000000000001976a914a91f9f763b29340b7d15fddd8b6ee41ac56fc88d88ac00000000<\/code><\/pre>\n<p>Now, let\u2019s sign it with keys 1 and 3:<\/p>\n<pre><code>&gt; sig1=`pybtctool multisign $tx 0 $script $k1`&gt; sig2=`pybtctool multisign $tx 0 $script $k3`&gt; tx2=`pybtctool apply_multisignatures $tx 0 $script $sig1 $sig2`<\/code><\/pre>\n<p>The final transaction looks like this:<\/p>\n<pre><code>&gt; echo $tx201000000010f0805304183bd1a981d95eb93ed4f4818b8c361ad317f80f75e62b73839129e00000000fd5f01004930460221009e4cc93850d3d7ed6fcdd416f13b4f652d80c00d6c76f7594645540fb7ece79d022100f9cb6ec2ca973c2ef52aa541bbe28aa038189116de94df68fc29b0901b472f2f0148304502201bd655c130e6f47567f8e7d7b769d974d8b543ec53bf99d2232d07253af832c0022100f49d1f0564c9b0b192bd178b36ab04818ed1673feae380c46ce5c8dbaa622f1f014cc95241045f4af45e3a7a86393c4ab9540cca382d46f10345b3ffcbb058089788550d167b7c079870d00da9728f8589fa5bbe0a8d62eadd56d37f3be6bc8145fe9a27437b4104509394eade56d900e90146e4bdf14f567b845ab0da986476253fe438f12032a248bbf2c16d28409b2961b3a3f797832ad195a8cef96589371271e2df6195cf804104ef6c434a854996e63cf650c0ba813993e90eef564bc78ad14768de51ac6b1bb00c5fe3381a923567162e8821e86ee28fbe4a25325f59cf6ede87c15d5af2881e53aeffffffff0110270000000000001976a914a91f9f763b29340b7d15fddd8b6ee41ac56fc88d88ac00000000<\/code><\/pre>\n<p>And now we push:<\/p>\n<pre><code>&gt; pybtctool eligius_pushtx $tx277afa6140a678f4791e4566e2f15a41e7d9236c79b0abc6388e73e055af0aeec<\/code><\/pre>\n<p>And there we go, we\u2019re 0.0001 BTC closer to at least mitigating the effect of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Senescence\" target=\"_blank\" rel=\"noopener\">single most deadly disease<\/a> on the planet.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There has been a large amount of interest in multisignature transaction technology in the past year, especially with the recent announcement of CryptoCorp. If you want to play with multisig technology yourself on the command line, here are the gritty details of how to do it. First, run sudo pip install bitcoin to install the [&hellip;]<\/p>\n","protected":false},"author":3568,"featured_media":29022,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":{"0":"post-29023","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-technical"},"author_data":{"id":3568,"name":"Vitalik Buterin","nicename":"vitalik-buterin","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/f6c592ba748599b4838a2236cba15c741b5a9ea63f623ed1d745b82f22abf36b?s=96&d=robohash&r=g"},"featured_image_url":"https:\/\/bitcoinmagazine.com\/wp-content\/uploads\/2024\/11\/pybitcointools-multisig-tutorial.jpg","_links":{"self":[{"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/posts\/29023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/users\/3568"}],"replies":[{"embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/comments?post=29023"}],"version-history":[{"count":0,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/posts\/29023\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/media\/29022"}],"wp:attachment":[{"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/media?parent=29023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/categories?post=29023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitcoinmagazine.com\/wp-json\/wp\/v2\/tags?post=29023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}