{"id":1071,"date":"2023-02-16T14:51:45","date_gmt":"2023-02-16T19:51:45","guid":{"rendered":"https:\/\/sunapi386.ca\/wordpress\/?p=1071"},"modified":"2023-02-19T16:27:11","modified_gmt":"2023-02-19T21:27:11","slug":"convert-cardano-wallet-address-to-stake-address-key","status":"publish","type":"post","link":"https:\/\/sunapi386.ca\/wordpress\/convert-cardano-wallet-address-to-stake-address-key\/","title":{"rendered":"Convert Cardano Wallet Address to Stake Address Key"},"content":{"rendered":"\n<p>If someone provides me with a payment address, how can I derive the staking address from the payment address?<\/p>\n\n\n\n<p>Cardano uses&nbsp;<a href=\"https:\/\/github.com\/input-output-hk\/bech32\">bech32<\/a>. Install bech32 instead and decode\/encode the address.<\/p>\n\n\n\n<p>Download the bech32 tool as part of <a href=\"https:\/\/github.com\/input-output-hk\/cardano-wallet\">cardano-wallet from github<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/github.com\/input-output-hk\/cardano-wallet\/releases\/download\/v2022-12-14\/cardano-wallet-v2022-12-14-linux64.tar.gz\n# or if on mac\nhttps:&#47;&#47;github.com\/input-output-hk\/cardano-wallet\/releases\/download\/v2022-12-14\/cardano-wallet-v2022-12-14-macos-intel.tar.gz\n\ntar -xf cardano-wallet-v2022-12-14-linux64.tar.gz\nrm cardano-wallet-v2022-12-14-linux64.tar.gz\ncd cardano-wallet-v2022-12-14-linux64\n.\/bech32<\/code><\/pre>\n\n\n\n<p>Let&#8217;s say you have address <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ set addr addr1q9f2prypgqkrmr5497d8ujl4s4qu9hx0w6kruspdkjyudc2xjgcagrdn0jxnf47yd96p7zdpfzny30l2jh5u5vwurxasjwukdr\n$ echo \"e1$(echo $addr | .\/bech32 | tail -c 57)\" | .\/bech32 stake\nstake1u9rfyvw5pkeherf56lzxjaqlpxs53fjghl4ft6w2x8wpnwchfeam3<\/code><\/pre>\n\n\n\n<p>If you wanted to do the equivalent in python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def resolve_addr2stake(address: str) -&gt; str:\n    \"\"\"\n     same as 'echo \"e1$(echo {address} | .\/bech32 | tail -c 57)\" |.\/bech32 stake'\n     It may be quicker to cache the address, result in a lookup table\n    :param address: wallet address, such as\n    addr1qxdvcswn0exwc2vjfr6u6f6qndfhmk94xjrt5tztpelyk4yg83zn9d4vrrtzs98lcl5u5q6mv7ngmg829xxvy3g5ydls7c76wu\n    to\n    019acc41d37e4cec299248f5cd27409b537dd8b53486ba2c4b0e7e4b54883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f\n    then last 56 bytes\n    883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f\n    then convert to bech32\n    stake1uxyrc3fjk6kp343gznlu06w2qddk0f5d5r4znrxzg52zxlclk0hlq\n\n    :return: stake key, such as\n    stake1uxyrc3fjk6kp343gznlu06w2qddk0f5d5r4znrxzg52zxlclk0hlq\n    \"\"\"\n    absolute_path = os.path.dirname(__file__)\n    relative_path = \"cardano-wallet\/bech32\"\n    full_path = os.path.join(absolute_path, relative_path)\n\n    p1 = subprocess.Popen(&#91;\"echo\", address], stdout=subprocess.PIPE)\n    p2 = subprocess.run(&#91;full_path], stdin=p1.stdout, capture_output=True)\n    s = p2.stdout.strip().decode('utf-8')\n    p3 = subprocess.Popen(&#91;\"echo\", f\"e1{s&#91;-56:]}\"], stdout=subprocess.PIPE)\n    p4 = subprocess.run(&#91;full_path, 'stake'], stdin=p3.stdout, capture_output=True)\n    return p4.stdout.strip().decode('utf-8')\n<\/code><\/pre>\n\n\n\n<p><strong>Update: <\/strong>There is a better way with direct python code, no need for the command line sys calls. <\/p>\n\n\n\n<p>See this post <a href=\"https:\/\/sunapi386.ca\/wordpress\/convert-cardano-bech32-address-to-stake-key\/\">https:\/\/sunapi386.ca\/wordpress\/convert-cardano-bech32-address-to-stake-key\/<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If someone provides me with a payment address, how can I derive the staking address from the payment address? Cardano uses&nbsp;bech32. Install bech32 instead and decode\/encode the address. Download the bech32 tool as part of cardano-wallet from github Let&#8217;s say you have address If you wanted to do the equivalent in python: Update: There is &hellip; <a href=\"https:\/\/sunapi386.ca\/wordpress\/convert-cardano-wallet-address-to-stake-address-key\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Convert Cardano Wallet Address to Stake Address Key<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1071","post","type-post","status-publish","format-standard","hentry","category-thoughts"],"_links":{"self":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=1071"}],"version-history":[{"count":5,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1071\/revisions"}],"predecessor-version":[{"id":1085,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1071\/revisions\/1085"}],"wp:attachment":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=1071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=1071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=1071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}