{"id":29560929,"url":"https://github.com/decred/atomicswap","last_synced_at":"2025-07-18T15:39:26.490Z","repository":{"id":46668603,"uuid":"102893389","full_name":"decred/atomicswap","owner":"decred","description":"On-chain atomic swaps for Decred and other cryptocurrencies.","archived":false,"fork":false,"pushed_at":"2024-02-27T20:28:36.000Z","size":188,"stargazers_count":506,"open_issues_count":15,"forks_count":230,"subscribers_count":63,"default_branch":"master","last_synced_at":"2024-04-13T16:25:26.657Z","etag":null,"topics":["cryptocurrencies","cryptocurrency","decred","exchange","go"],"latest_commit_sha":null,"homepage":"https://blog.decred.org/2017/09/20/On-Chain-Atomic-Swaps/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/decred.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-08T18:40:24.000Z","updated_at":"2024-06-19T05:08:37.805Z","dependencies_parsed_at":"2024-06-19T05:08:19.264Z","dependency_job_id":"ba21975c-abcc-46a8-b1a8-62623d555174","html_url":"https://github.com/decred/atomicswap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/decred/atomicswap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decred%2Fatomicswap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decred%2Fatomicswap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decred%2Fatomicswap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decred%2Fatomicswap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/decred","download_url":"https://codeload.github.com/decred/atomicswap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decred%2Fatomicswap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265787606,"owners_count":23828458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptocurrencies","cryptocurrency","decred","exchange","go"],"created_at":"2025-07-18T15:39:25.900Z","updated_at":"2025-07-18T15:39:26.479Z","avatar_url":"https://github.com/decred.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"**NOTICE Mar 1 2018:** The atomic swap contract has been updated to specify the\nsecret sizes to prevent fraudulent swaps between two cryptocurrencies with\ndifferent maximum data sizes.  Old contracts will not be usable by the new tools\nand vice-versa.  Please rebuild all tools before conducting new atomic swaps.\n\n# Decred-compatible cross-chain atomic swapping\n\nThis repository contains utilities to manually perform cross-chain atomic swaps\nbetween various supported pairs of cryptocurrencies.  At the moment, support\nexists for the following coins and wallets:\n\n* Bitcoin ([Bitcoin Core](https://github.com/bitcoin/bitcoin))\n* Bitcoin Cash ([Bitcoin ABC](https://github.com/Bitcoin-ABC/bitcoin-abc), [Bitcoin Unlimited](https://github.com/BitcoinUnlimited/BitcoinUnlimited), [Bitcoin XT](https://github.com/bitcoinxt/bitcoinxt))\n* Decred ([dcrwallet](https://github.com/decred/dcrwallet))\n* Litecoin ([Litecoin Core](https://github.com/litecoin-project/litecoin))\n* Monacoin ([Monacoin Core](https://github.com/monacoinproject/monacoin))\n* Particl ([Particl Core](https://github.com/particl/particl-core))\n* Qtum ([Qtum Core](https://github.com/qtumproject/qtum))\n* Vertcoin ([Vertcoin Core](https://github.com/vertcoin/vertcoin))\n* Viacoin ([Viacoin Core](https://github.com/viacoin/viacoin))\n* Zcoin ([Zcoin Core](https://github.com/zcoinofficial/zcoin))\n\nExternal support exists for the following coins and wallets:\n\n* ThreeFold Token ([ThreeFold Chain](https://github.com/threefoldfoundation/tfchain))\n\nPull requests implementing support for additional cryptocurrencies and wallets\nare encouraged.  See [GitHub project\n1](https://github.com/decred/atomicswap/projects/1) for the status of coins\nbeing considered.  Implementing support for a new cryptocurrency provides atomic\nswap compatibility between all current and future supported coins.\n\nThese tools do not operate solely on-chain.  A side-channel is required between\neach party performing the swap in order to exchange additional data.  This\nside-channel could be as simple as a text chat and copying data.  Until a more\nstreamlined implementation of the side channel exists, such as the Lightning\nNetwork, these tools suffice as a proof-of-concept for cross-chain atomic swaps\nand a way for early adopters to try out the technology.\n\nDue to the requirements of manually exchanging data and creating, sending, and\nwatching for the relevant transactions, it is highly recommended to read this\nREADME in its entirety before attempting to use these tools.  The sections\nbelow explain the principles on which the tools operate, the instructions for\nhow to use them safely, and an example swap between Decred and Bitcoin.\n\n## Build instructions\n\nRequires [Go 1.11](https://golang.org/dl/) or later\n\n- Clone atomicswap somewhere outside `$GOPATH`:\n  ```\n  $ git clone https://github.com/decred/atomicswap \u0026\u0026 cd atomicswap\n  ```\n\n- To install a single tool:\n  ```\n  $ cd cmd/dcratomicswap \u0026\u0026 go install\n  ```\n\n## Theory\n\nA cross-chain swap is a trade between two users of different cryptocurrencies.\nFor example, one party may send Decred to a second party's Decred address, while\nthe second party would send Bitcoin to the first party's Bitcoin address.\nHowever, as the blockchains are unrelated and transactions can not be reversed,\nthis provides no protection against one of the parties never honoring their end\nof the trade.  One common solution to this problem is to introduce a\nmutually-trusted third party for escrow.  An atomic cross-chain swap solves this\nproblem without the need for a third party.\n\nAtomic swaps involve each party paying into a contract transaction, one contract\nfor each blockchain.  The contracts contain an output that is spendable by\neither party, but the rules required for redemption are different for each party\ninvolved.\n\nOne party (called counterparty 1 or the initiator) generates a secret and pays\nthe intended trade amount into a contract transaction.  The contract output can\nbe redeemed by the second party (called counterparty 2 or the participant) as\nlong as the secret is known.  If a period of time (typically 48 hours) expires\nafter the contract transaction has been mined but has not been redeemed by the\nparticipant, the contract output can be refunded back to the initiator's wallet.\n\nFor simplicity, we assume the initiator wishes to trade Bitcoin for Decred with\nthe participant.  The initiator can also trade Decred for Bitcoin and the steps\nwill be the same, but with each step performed on the other blockchain.\n\nThe participant is unable to spend from the initiator's Bitcoin contract at this\npoint because the secret is unknown by them.  If the initiator revealed their\nsecret at this point, the participant could spend from the contract without ever\nhonoring their end of the trade.\n\nThe participant creates a similar contract transaction to the initiator's but on\nthe Decred blockchain and pays the intended Decred amount into the contract.\nHowever, for the initiator to redeem the output, their own secret must be\nrevealed.  For the participant to create their contract, the initiator must\nreveal not the secret, but a cryptographic hash of the secret to the\nparticipant.  The participant's contract can also be refunded by the\nparticipant, but only after half the period of time that the initiator is\nrequired to wait before their contract can be refunded (typically 24 hours).\n\nWith each side paying into a contract on each blockchain, and each party unable\nto perform their refund until the allotted time expires, the initiator redeems\nthe participant's Decred contract, thereby revealing the secret to the\nparticipant.  The secret is then extracted from the initiator's redeeming Decred\ntransaction providing the participant with the ability to redeem the initiator's\nBitcoin contract.\n\nThis procedure is atomic (with timeout) as it gives each party at least 24 hours\nto redeem their coins on the other blockchain before a refund can be performed.\n\nThe image below provides a visual of the steps each party performs and the\ntransfer of data between each party.\n\n\u003cimg src=\"workflow.svg\" width=\"100%\" height=650 /\u003e\n\n## Command line\n\nSeparate command line utilities are provided to handle the transactions required\nto perform a cross-chain atomic swap for each supported blockchain.  For a swap\nbetween Bitcoin and Decred, the two utilities `btcatomicswap` and\n`dcratomicswap` are used.  Both tools must be used by both parties performing\nthe swap.\n\nDifferent tools may require different flags to use them with the supported\nwallet.  For example, `btcatomicswap` includes flags for the RPC username and\npassword while `dcratomicswap` requires flags for TLS client authentication.\nRunning a tool without any parameters will show the full usage help.\n\nAll of the tools support the same six commands.  These commands are:\n\n```\nCommands:\n  initiate \u003cparticipant address\u003e \u003camount\u003e\n  participate \u003cinitiator address\u003e \u003camount\u003e \u003csecret hash\u003e\n  redeem \u003ccontract\u003e \u003ccontract transaction\u003e \u003csecret\u003e\n  refund \u003ccontract\u003e \u003ccontract transaction\u003e\n  extractsecret \u003credemption transaction\u003e \u003csecret hash\u003e\n  auditcontract \u003ccontract\u003e \u003ccontract transaction\u003e\n```\n\n**`initiate \u003cparticipant address\u003e \u003camount\u003e`**\n\nThe `initiate` command is performed by the initiator to create the first\ncontract.  The contract is created with a locktime of 48 hours in the future.\nThis command returns the secret, the secret hash, the contract script, the\ncontract transaction, and a refund transaction that can be sent after 48 hours\nif necessary.\n\nRunning this command will prompt for whether to publish the contract\ntransaction.  If everything looks correct, the transaction should be published.\nThe refund transaction should be saved in case a refund is required to be made\nlater.\n\nFor dcratomicswap, this step prompts for the wallet passphrase.  For the\nbtcatomicswap and ltcatomicswap tools the wallet must already be unlocked.\n\n**`participate \u003cinitiator address\u003e \u003camount\u003e \u003csecret hash\u003e`**\n\nThe `participate` command is performed by the participant to create a contract\non the second blockchain.  It operates similarly to `initiate` but requires\nusing the secret hash from the initiator's contract and creates the contract\nwith a locktime of 24 hours.\n\nRunning this command will prompt for whether to publish the contract\ntransaction.  If everything looks correct, the transaction should be published.\nThe refund transaction should be saved in case a refund is required to be made\nlater.\n\nFor dcratomicswap, this step prompts for the wallet passphrase.  For the\nbtcatomicswap and ltcatomicswap tools the wallet must already be unlocked.\n\n**`redeem \u003ccontract\u003e \u003ccontract transaction\u003e \u003csecret\u003e`**\n\nThe `redeem` command is performed by both parties to redeem coins paid into the\ncontract created by the other party.  Redeeming requires the secret and must be\nperformed by the initiator first.  Once the initiator's redemption has been\npublished, the secret may be extracted from the transaction and the participant\nmay also redeem their coins.\n\nRunning this command will prompt for whether to publish the redemption\ntransaction. If everything looks correct, the transaction should be published.\n\nFor dcratomicswap, this step prompts for the wallet passphrase.  For the\nbtcatomicswap and ltcatomicswap tools the wallet must already be unlocked.\n\n**`refund \u003ccontract\u003e \u003ccontract transaction\u003e`**\n\nThe `refund` command is used to create and send a refund of a contract\ntransaction.  While the refund transaction is created and displayed during\ncontract creation in the initiate and participate steps, the refund can also be\ncreated after the fact in case there was any issue sending the transaction (e.g.\nthe contract transaction was malleated or the refund fee is now too low).\n\nRunning this command will prompt for whether to publish the redemption\ntransaction. If everything looks correct, the transaction should be published.\n\n**`extractsecret \u003credemption transaction\u003e \u003csecret hash\u003e`**\n\nThe `extractsecret` command is used by the participant to extract the secret\nfrom the initiator's redemption transaction.  With the secret known, the\nparticipant may claim the coins paid into the initiator's contract.\n\nThe secret hash is a required parameter so that \"nonstandard\" redemption\ntransactions won't confuse the tool and the secret can still be discovered.\n\n**`auditcontract \u003ccontract\u003e \u003ccontract transaction\u003e`**\n\nThe `auditcontract` command inspects a contract script and parses out the\naddresses that may claim the output, the locktime, and the secret hash.  It also\nvalidates that the contract transaction pays to the contract and reports the\ncontract output amount.  Each party should audit the contract provided by the\nother to verify that their address is the recipient address, the output value is\ncorrect, and that the locktime is sensible.\n\n## Example\n\nThe first step is for both parties to exchange addresses on both blockchains. If\nparty A (the initiator) wishes to trade Bitcoin for Decred, party B (the\nparticipant) must provide their Bitcoin address and the initiator must provide\nthe participant their Decred address.\n\n_Party A runs:_\n```\n$ dcrctl --testnet --wallet getnewaddress\nTsfWDVTAcsLaHUhHnLLKkGnZuJz2vkmM6Vr\n```\n\n_Party B runs:_\n```\n$ bitcoin-cli -testnet getnewaddress \"\" \"legacy\"\nn31og5QGuS28dmHpDH6PQD5wmVQ2K2spAG\n```\n\n*Note:* It is normal for neither of these addresses to show any activity on\nblock explorers.  They are only used in nonstandard scripts that the block\nexplorers do not recognize.\n\nA initiates the process by using `btcatomicswap` to pay 1.0 BTC into the Bitcoin\ncontract using B's Bitcoin address, sending the contract transaction, and\nsharing the secret hash (*not* the secret), contract, and contract transaction\nwith B.  The refund transaction can not be sent until the locktime expires, but\nshould be saved in case a refund is necessary.\n\n_Party A runs:_\n```\n$ btcatomicswap --testnet --rpcuser=user --rpcpass=pass initiate n31og5QGuS28dmHpDH6PQD5wmVQ2K2spAG 1.0\nSecret:      3e0b064c97247732a3b345ce7b2a835d928623cb2871c26db4c2539a38e61a16\nSecret hash: 29c36b8dd380e0426bdc1d834e74a630bfd5d111\n\nContract fee: 0.0000744 BTC (0.00020000 BTC/kB)\nRefund fee:   0.00000281 BTC (0.00001018 BTC/kB)\n\nContract (2MwQAMPeRGdCzFzPy7DmCnQudDVGNBFJK8S):\n63a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a914ebcf822c4a2cdb5f6a6b9c4a59b74d66461da5816704d728bd59b17576a91406fb26221375b1cbe2c17c14f1bc2510b9f8f8ff6888ac\n\nContract transaction (346f4901dff1d69197850289b481f4331913126a8886861e7d5f27e837e0fe88):\n010000000267864c7145e43c84d13b514518cfdc7ca5cf2b04764ed2672caa9c8f6338a3e3010000006b483045022100901602e523f25e9659951d186eec7e8b9df9d194e8013fb6d7a05e4eafdbb61602207b66e0179a42c54d4fcfca2b1ccd89d56253cc83724593187713f6befb37866201210288ef714849ce7735b64ed886d056b80d0a384ca299090f684820d31e7682825afeffffff3ac58ce49bcef3d047ea80281659a78cd7ef8537ca2bfce336abdce41450d2d7000000006b483045022100bd1246fc18d26a9cc85c14fb60655da2f2e845af906504b8ba3acbb1b0ebf08202201ec2cd5a0c94e9e6b971ec3198be0ff57e91115342cd98ccece98d8b18294d86012103406e35c37b3b85481db7b7f7807315720dd6486c25e4f3af93d5d5f21e743881feffffff0248957e01000000001976a914c1925e7398d325820bba18726c387e9d80047ef588ac00e1f5050000000017a9142d913627b881255c417787cc255ccad9a33ce48d8700000000\n\nRefund transaction (45c7c175f333981508229f6fa637410fbbf4f086b657035c07adda6a49207e03):\n000000000188fee037e8275f7d1e8686886a12131933f481b48902859791d6f1df01496f3401000000bf4830450221009344b17316054eae5d293b34683177fa5e7c7ba9b0001ebb2b3deca83bef552e022067088b7342bed0155b2ccef69d97cd293faa687f589d2a351aa6e154953c0c65012103a3a9f2c0492a40b134363e82959fa6132b86e0969e0b25109beb53b1debc4324004c5163a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a914ebcf822c4a2cdb5f6a6b9c4a59b74d66461da5816704d728bd59b17576a91406fb26221375b1cbe2c17c14f1bc2510b9f8f8ff6888ac0000000001e7dff505000000001976a914f5261c9e58aaa9461923c3f78f8f12f0eec22ed388acd728bd59\n\nPublish contract transaction? [y/N] y\nPublished contract transaction (346f4901dff1d69197850289b481f4331913126a8886861e7d5f27e837e0fe88)\n```\n\nOnce A has initialized the swap, B must audit the contract and contract\ntransaction to verify:\n\n1. The recipient address was the BTC address that was provided to A\n2. The contract value is the expected amount of BTC to receive\n3. The locktime was set to 48 hours in the future\n\n_Party B runs:_\n```\n$ btcatomicswap --testnet auditcontract 63a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a914ebcf822c4a2cdb5f6a6b9c4a59b74d66461da5816704d728bd59b17576a91406fb26221375b1cbe2c17c14f1bc2510b9f8f8ff6888ac 010000000267864c7145e43c84d13b514518cfdc7ca5cf2b04764ed2672caa9c8f6338a3e3010000006b483045022100901602e523f25e9659951d186eec7e8b9df9d194e8013fb6d7a05e4eafdbb61602207b66e0179a42c54d4fcfca2b1ccd89d56253cc83724593187713f6befb37866201210288ef714849ce7735b64ed886d056b80d0a384ca299090f684820d31e7682825afeffffff3ac58ce49bcef3d047ea80281659a78cd7ef8537ca2bfce336abdce41450d2d7000000006b483045022100bd1246fc18d26a9cc85c14fb60655da2f2e845af906504b8ba3acbb1b0ebf08202201ec2cd5a0c94e9e6b971ec3198be0ff57e91115342cd98ccece98d8b18294d86012103406e35c37b3b85481db7b7f7807315720dd6486c25e4f3af93d5d5f21e743881feffffff0248957e01000000001976a914c1925e7398d325820bba18726c387e9d80047ef588ac00e1f5050000000017a9142d913627b881255c417787cc255ccad9a33ce48d8700000000\nContract address:        2MwQAMPeRGdCzFzPy7DmCnQudDVGNBFJK8S\nContract value:          1 BTC\nRecipient address:       n31og5QGuS28dmHpDH6PQD5wmVQ2K2spAG\nAuthor's refund address: mg9sDLhfByfAWFo4zq3JZ7nsLfsN59XPue\n\nSecret hash: 29c36b8dd380e0426bdc1d834e74a630bfd5d111\n\nLocktime: 2017-09-16 13:36:23 +0000 UTC\nLocktime reached in 47h56m54s\n```\n\nAuditing the contract also reveals the hash of the secret, which is needed for\nthe next step.\n\nOnce B trusts the contract, they may participate in the cross-chain atomic swap\nby paying the intended Decred amount (1.0 in this example) into a Decred\ncontract using the same secret hash.  The contract transaction may be published\nat this point.  The refund transaction can not be sent until the locktime\nexpires, but should be saved in case a refund is necessary.\n\n_Party B runs:_\n```\n$ dcratomicswap --testnet --clientcert=client.cert --clientkey=client.key participate TsfWDVTAcsLaHUhHnLLKkGnZuJz2vkmM6Vr 1.0 29c36b8dd380e0426bdc1d834e74a630bfd5d111\nPassphrase:\n\nContract fee: 0.000251 DCR (0.00100400 DCR/kB)\nRefund fee:   0.000301 DCR (0.00100669 DCR/kB)\n\nContract (TcZpybEVDVTuoE3TCBxW3ui12YEZWrw5ccS):\n63a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a9149ee19833332a04d2be97b5c99c970191221c070c6704e6dabb59b17576a914b0ec0640c89cf803b8fdbd6e0183c354f71748c46888ac\n\nContract transaction (a51a7ebc178731016f897684e8e6fbbd65798a84d0a0bd78fe2b53b8384fd918):\n010000000137afc6c25b027cb0a1db19a7aac365854796260c4c1077e3e8accae5e4c300e90300000001ffffffff02441455980100000000001976a9144d7c96b6d2360e48a07528332e537d81e068f8ba88ac00e1f50500000000000017a914195fb53333e61a415e9fda21bb991b38b5a4e1c387000000000000000001ffffffffffffffff00000000ffffffff6b483045022100b30971448c93be84c28b98ae159963e9521a84d0c3849821b6e8897d59cf4e6c0220228785cb8d1dba40752e4bd09d99b92b27bc3837b1c547f8b4ee8aba1dfec9310121035a12a086ecd1397f7f68146f4f251253b7c0092e167a1c92ff9e89cf96c68b5f\n\nRefund transaction (836288fa26bbce52342c8569ca4e0db7dec81b2187eb453c1fd5c5d06838f60a):\n000000000118d94f38b8532bfe78bda0d0848a7965bdfbe6e88476896f01318717bc7e1aa5010000000000000000016c6bf5050000000000001976a9140b4dae42b84dbad7b7e35f61602cb6a2393f0ae088ace6dabb590000000001ffffffffffffffff00000000ffffffffbe47304402201bd55803eae6de4ea19c618060f82c38e9ca04047c346dc7025f54d8276f13f602205cdf104db74563559e570f186cbc68549d623618b96c7ec971d1a996dab78fbd01210244e4e75a9318ac06656d145c3d3205b2f4f25615698f458e80233c4bb78c91ac004c5163a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a9149ee19833332a04d2be97b5c99c970191221c070c6704e6dabb59b17576a914b0ec0640c89cf803b8fdbd6e0183c354f71748c46888ac\n\nPublish contract transaction? [y/N] y\nPublished contract transaction (a51a7ebc178731016f897684e8e6fbbd65798a84d0a0bd78fe2b53b8384fd918)\n```\n\nB now informs A that the Decred contract transaction has been created and\npublished, and provides the contract details to A.\n\nJust as B needed to audit A's contract before locking their coins in a contract,\nA must do the same with B's contract before withdrawing from the contract.  A\naudits the contract and contract transaction to verify:\n\n1. The recipient address was the DCR address that was provided to B\n2. The contract value is the expected amount of DCR to receive\n3. The locktime was set to 24 hours in the future\n4. The secret hash matches the value previously known\n\n_Party A runs:_\n```\n$ dcratomicswap --testnet auditcontract 63a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a9149ee19833332a04d2be97b5c99c970191221c070c6704e6dabb59b17576a914b0ec0640c89cf803b8fdbd6e0183c354f71748c46888ac 010000000137afc6c25b027cb0a1db19a7aac365854796260c4c1077e3e8accae5e4c300e90300000001ffffffff02441455980100000000001976a9144d7c96b6d2360e48a07528332e537d81e068f8ba88ac00e1f50500000000000017a914195fb53333e61a415e9fda21bb991b38b5a4e1c387000000000000000001ffffffffffffffff00000000ffffffff6b483045022100b30971448c93be84c28b98ae159963e9521a84d0c3849821b6e8897d59cf4e6c0220228785cb8d1dba40752e4bd09d99b92b27bc3837b1c547f8b4ee8aba1dfec9310121035a12a086ecd1397f7f68146f4f251253b7c0092e167a1c92ff9e89cf96c68b5f\nContract address:        TcZpybEVDVTuoE3TCBxW3ui12YEZWrw5ccS\nContract value:          1 DCR\nRecipient address:       TsfWDVTAcsLaHUhHnLLKkGnZuJz2vkmM6Vr\nAuthor's refund address: Tsh9c9aytRaDcbLLxDRcQDRx66aXATh28R3\n\nSecret hash: 29c36b8dd380e0426bdc1d834e74a630bfd5d111\n\nLocktime: 2017-09-15 13:51:34 +0000 UTC\nLocktime reached in 23h58m10s\n```\n\nNow that both parties have paid into their respective contracts, A may withdraw\nfrom the Decred contract.  This step involves publishing a transaction which\nreveals the secret to B, allowing B to withdraw from the Bitcoin contract.\n\n_Party A runs:_\n```\n$ dcratomicswap --testnet --clientcert=client.cert --clientkey=client.key redeem 63a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a9149ee19833332a04d2be97b5c99c970191221c070c6704e6dabb59b17576a914b0ec0640c89cf803b8fdbd6e0183c354f71748c46888ac 010000000137afc6c25b027cb0a1db19a7aac365854796260c4c1077e3e8accae5e4c300e90300000001ffffffff02441455980100000000001976a9144d7c96b6d2360e48a07528332e537d81e068f8ba88ac00e1f50500000000000017a914195fb53333e61a415e9fda21bb991b38b5a4e1c387000000000000000001ffffffffffffffff00000000ffffffff6b483045022100b30971448c93be84c28b98ae159963e9521a84d0c3849821b6e8897d59cf4e6c0220228785cb8d1dba40752e4bd09d99b92b27bc3837b1c547f8b4ee8aba1dfec9310121035a12a086ecd1397f7f68146f4f251253b7c0092e167a1c92ff9e89cf96c68b5f 3e0b064c97247732a3b345ce7b2a835d928623cb2871c26db4c2539a38e61a16\nPassphrase:\n\nRedeem fee: 0.000334 DCR (0.00100300 DCR/kB)\n\nRedeem transaction (53c2e8bafb8fe36d54bbb1884141a39ea4da83db30bdf3c98ef420cdb332b0e7):\n000000000118d94f38b8532bfe78bda0d0848a7965bdfbe6e88476896f01318717bc7e1aa50100000000ffffffff01885ef5050000000000001976a9149551ab760ba64b7e573f54d34c53506676e8145888ace6dabb590000000001ffffffffffffffff00000000ffffffffe0483045022100a1a3b37a67f3ed5d6445a0312e825299b54d91a09e0d1b59b5c0a8baa7c0642102201a0d53e9efe7db8dc47210b446fde6425be82761252ff0ebe620efc183788d86012103395a4a3c8c96ef5e5af6fd80ae42486b5d3d860bf3b41dafc415354de8c7ad80203e0b064c97247732a3b345ce7b2a835d928623cb2871c26db4c2539a38e61a16514c5163a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a9149ee19833332a04d2be97b5c99c970191221c070c6704e6dabb59b17576a914b0ec0640c89cf803b8fdbd6e0183c354f71748c46888ac\n\nPublish redeem transaction? [y/N] y\nPublished redeem transaction (53c2e8bafb8fe36d54bbb1884141a39ea4da83db30bdf3c98ef420cdb332b0e7)\n```\n\nNow that A has withdrawn from the Decred contract and revealed the secret, B\nmust extract the secret from this redemption transaction.  B may watch a block\nexplorer to see when the Decred contract output was spent and look up the\nredeeming transaction.\n\n_Party B runs:_\n```\n$ dcratomicswap --testnet extractsecret 000000000118d94f38b8532bfe78bda0d0848a7965bdfbe6e88476896f01318717bc7e1aa50100000000ffffffff01885ef5050000000000001976a9149551ab760ba64b7e573f54d34c53506676e8145888ace6dabb590000000001ffffffffffffffff00000000ffffffffe0483045022100a1a3b37a67f3ed5d6445a0312e825299b54d91a09e0d1b59b5c0a8baa7c0642102201a0d53e9efe7db8dc47210b446fde6425be82761252ff0ebe620efc183788d86012103395a4a3c8c96ef5e5af6fd80ae42486b5d3d860bf3b41dafc415354de8c7ad80203e0b064c97247732a3b345ce7b2a835d928623cb2871c26db4c2539a38e61a16514c5163a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a9149ee19833332a04d2be97b5c99c970191221c070c6704e6dabb59b17576a914b0ec0640c89cf803b8fdbd6e0183c354f71748c46888ac 29c36b8dd380e0426bdc1d834e74a630bfd5d111\nSecret: 3e0b064c97247732a3b345ce7b2a835d928623cb2871c26db4c2539a38e61a16\n```\n\nWith the secret known, B may redeem from A's Bitcoin contract.\n\n_Party B runs:_\n```\n$ btcatomicswap --testnet --rpcuser=user --rpcpass=pass redeem 63a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a914ebcf822c4a2cdb5f6a6b9c4a59b74d66461da5816704d728bd59b17576a91406fb26221375b1cbe2c17c14f1bc2510b9f8f8ff6888ac 010000000267864c7145e43c84d13b514518cfdc7ca5cf2b04764ed2672caa9c8f6338a3e3010000006b483045022100901602e523f25e9659951d186eec7e8b9df9d194e8013fb6d7a05e4eafdbb61602207b66e0179a42c54d4fcfca2b1ccd89d56253cc83724593187713f6befb37866201210288ef714849ce7735b64ed886d056b80d0a384ca299090f684820d31e7682825afeffffff3ac58ce49bcef3d047ea80281659a78cd7ef8537ca2bfce336abdce41450d2d7000000006b483045022100bd1246fc18d26a9cc85c14fb60655da2f2e845af906504b8ba3acbb1b0ebf08202201ec2cd5a0c94e9e6b971ec3198be0ff57e91115342cd98ccece98d8b18294d86012103406e35c37b3b85481db7b7f7807315720dd6486c25e4f3af93d5d5f21e743881feffffff0248957e01000000001976a914c1925e7398d325820bba18726c387e9d80047ef588ac00e1f5050000000017a9142d913627b881255c417787cc255ccad9a33ce48d8700000000 3e0b064c97247732a3b345ce7b2a835d928623cb2871c26db4c2539a38e61a16\nRedeem fee: 0.00000314 BTC (0.00001016 BTC/kB)\n\nRedeem transaction (c49e6fd0057b601dbb8856ad7b3fcb45df626696772f6901482b08df0333e5a0):\n000000000188fee037e8275f7d1e8686886a12131933f481b48902859791d6f1df01496f3401000000e0483045022100f43430384ca5ecfc9ca31dd074d223836cef4801b3644c651c3a30d80fbf63b8022017dae9e7ec6f3f5ee0e0b60d146963ba85d9b31003d7f60852126f2a35492759012103b10e3690bcaf0eae7098ec794666963803bcec5acfbe6a112bc8cdc93797f002203e0b064c97247732a3b345ce7b2a835d928623cb2871c26db4c2539a38e61a16514c5163a61429c36b8dd380e0426bdc1d834e74a630bfd5d1118876a914ebcf822c4a2cdb5f6a6b9c4a59b74d66461da5816704d728bd59b17576a91406fb26221375b1cbe2c17c14f1bc2510b9f8f8ff6888acffffffff01c6dff505000000001976a914e1fce397007bad3ce051f0b1c3c7587f016cd76a88acd728bd59\n\nPublish redeem transaction? [y/N] y\nPublished redeem transaction (c49e6fd0057b601dbb8856ad7b3fcb45df626696772f6901482b08df0333e5a0)\n```\n\nThe cross-chain atomic swap is now completed and successful.  This example was\nperformed on the public Bitcoin and Decred testnet blockchains.  For reference,\nhere are the four transactions involved:\n\n| Description | Transaction |\n| - | - |\n| Bitcoin contract created by A | [346f4901dff1d69197850289b481f4331913126a8886861e7d5f27e837e0fe88](https://blockstream.info/testnet/tx/346f4901dff1d69197850289b481f4331913126a8886861e7d5f27e837e0fe88) |\n| Decred contract created by B | a51a7ebc178731016f897684e8e6fbbd65798a84d0a0bd78fe2b53b8384fd918 \u003cbr /\u003e _(Decred testnet has been reset, link no longer available)_ |\n| A's Decred redemption | 53c2e8bafb8fe36d54bbb1884141a39ea4da83db30bdf3c98ef420cdb332b0e7 \u003cbr /\u003e _(Decred testnet has been reset, link no longer available)_ |\n| B's Bitcoin redemption | [c49e6fd0057b601dbb8856ad7b3fcb45df626696772f6901482b08df0333e5a0](https://blockstream.info/testnet/tx/c49e6fd0057b601dbb8856ad7b3fcb45df626696772f6901482b08df0333e5a0) |\n\nIf at any point either party attempts to fraud (e.g. creating an invalid\ncontract, not revealing the secret and refunding, etc.) both parties have the\nability to issue the refund transaction created in the initiate/participate step\nand refund the contract.\n\n## Discovering raw transactions\n\nSeveral steps require working with a raw transaction published by the other\nparty.  While the transactions can sometimes be looked up from a local node\nusing the `getrawtransaction` JSON-RPC, this method can be unreliable since the\nset of queryable transactions depends on the current UTXO set or may require a\ntransaction index to be enabled.\n\nAnother method of discovering these transactions is to use a public blockchain\nexplorer.  Not all explorers expose this info through the main user interface so\nthe API endpoints may need to be used instead.\n\nFor Insight-based block explorers, such as the Bitcoin block explorer on\n[test-]insight.bitpay.com, the Litecoin block explorer on\n{insight,testnet}.litecore.io, and the Decred block explorer on\n{mainnet,testnet}.decred.org, the API endpoint `/api/rawtx/\u003ctxhash\u003e` can be used\nto return a JSON object containing the raw transaction.  For example, here are\nlinks to the four raw transactions published in the example:\n\n| Description | Link to raw transaction |\n| - | - |\n| Bitcoin contract created by A | [346f4901dff1d69197850289b481f4331913126a8886861e7d5f27e837e0fe88](https://test-insight.bitpay.com/api/rawtx/346f4901dff1d69197850289b481f4331913126a8886861e7d5f27e837e0fe88) |\n| Decred contract created by B | a51a7ebc178731016f897684e8e6fbbd65798a84d0a0bd78fe2b53b8384fd918 \u003cbr /\u003e _(Decred testnet has been reset, link no longer available)_ |\n| A's Decred redemption | 53c2e8bafb8fe36d54bbb1884141a39ea4da83db30bdf3c98ef420cdb332b0e7 \u003cbr /\u003e _(Decred testnet has been reset, link no longer available)_ |\n| B's Bitcoin redemption | [c49e6fd0057b601dbb8856ad7b3fcb45df626696772f6901482b08df0333e5a0](https://test-insight.bitpay.com/api/rawtx/c49e6fd0057b601dbb8856ad7b3fcb45df626696772f6901482b08df0333e5a0) |\n\n## First mainnet DCR-LTC atomic swap\n\n| Description | Link to raw transaction |\n| - | - |\n| Decred contract created by A | [fdd72f5841414a9c8b4a188a98a4d484df98f84e1c120e1ed59a66e51e8ae90c](https://dcrdata.decred.org/tx/fdd72f5841414a9c8b4a188a98a4d484df98f84e1c120e1ed59a66e51e8ae90c) |\n| Litecoin contract created by B | [550d1b2851f6f104e380aa3c2810ac272f8b6918140547c9717a78b1f4ff3469](https://insight.litecore.io/tx/550d1b2851f6f104e380aa3c2810ac272f8b6918140547c9717a78b1f4ff3469) |\n| A's Litecoin redemption | [6c27cffab8a86f1b3be1ebe7acfbbbdcb82542c5cfe7880fcca60eab36747037](https://insight.litecore.io/tx/6c27cffab8a86f1b3be1ebe7acfbbbdcb82542c5cfe7880fcca60eab36747037) |\n| B's Decred redemption | [49245425967b7e39c1eb27d261c7fe972675cccacff19ae9cc21f434ccddd986](https://dcrdata.decred.org/tx/49245425967b7e39c1eb27d261c7fe972675cccacff19ae9cc21f434ccddd986) |\n\n## License\n\nThese tools are licensed under the [copyfree](http://copyfree.org) ISC License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecred%2Fatomicswap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdecred%2Fatomicswap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecred%2Fatomicswap/lists"}