Atomic exchange transactions with addresses whose private key is not imported on that wallet?

+2 votes

Hi there, is it possible to create a atomic exchange between two node addresses which private key is not imported on that wallet?

I tried https://www.multichain.com/qa/4868/exchange-transactions-imported-addresses-managed-wallet but it didn't complete. Can you show it exactly with step by step follow https://www.multichain.com/developers/atomic-exchange-transactions/ ?

Regard,

Thanh.

asked Aug 31, 2017 by thanhpt

2 Answers

0 votes

The basic idea is to follow the regular instructions for atomic exchanges but replace a number of stages as follows:

  1. On the first side, instead of preparelockunspentfrom use createrawsendfrom + signrawtransaction (with the private key passed as a parameter) + sendrawtransaction to create an unspent transaction output (UTXO) with the desired amount. Use the lock keyword with createrawsendfrom to protect the UTXOs used during this process.
  2. On the first side, instead of createrawexchange use createrawtransaction (with the transaction output made in the step described above) + signrawtransaction (again with the private key passed) to create the offer of exchange. Set the sighashtype of signrawtransaction to SINGLE|ANYONECANPAY here, to ensure the transaction is not finalized and can be added to on the second side.
  3. On the second side, instead of preparelockunspentfrom use the same steps described in step 1 above.
  4. On the second side, instead of appendrawexchange (or completerawexchange) use appendrawtransaction (with the transaction output created in step 3) + signrawtransaction (again passing the private key) to accept the offer of exchange before transmitting it in the usual way via sendrawtransaction.

We'll aim to produce some actual step-by-step documentation for this shortly.

answered Sep 1, 2017 by MultiChain
0 votes
We've now added step-by-step instructions for doing this in the 'Exchanging with external private keys' section at the end of the 'Atomic exchange transactions' page:

https://www.multichain.com/developers/atomic-exchange-transactions/

You need to at least complete the first section of the tutorial before jumping down to the section you want.
answered Sep 4, 2017 by MultiChain
Hi, thank for your instruction. I did it. But I have a question? How to disable exchange when i exchange with external private key. Thank you.
Using external keys, if the creator of an exchange offer thinks it may want to disable that offer in future, they should keep a record of the (txid,vout) values that were used to create the offer. Then to actually disable it, use createrawtransaction to create a transaction spending that (txid,vout) pair, with no outputs, then use appendrawchange to add the output going back to the original address, then sign externally and transmit with sendrawtransaction.
I have a question, after i call createrawtransaction and sign it , i have a hexdata. So can I disable with hexdata or i have to use txid of sendrawtransaction and vout = 0. Can you talk clearly for me, please? This is my flow:
A want to exchange with B so A create hexdata (from call createrawtransaction and sign it) and send hexdata to B. If B accept, B will call appendrawtransaction sign and send. But when B reject, how to disable exchange. Thank you.  

https://www.multichain.com/developers/atomic-exchange-transactions/
If you want to cancel an offer of exchange, you need to spend one of its inputs. The disablerawtransaction API will take care of that for you, but it won't work if the required private key is not in the node's wallet. In that case, you should use createrawtransaction + signrawtransaction + sendrawtransaction to spend the (txid,vout) pair that was entered into the exchange transaction from your side. That will make the offer of exchange now unusable.
Thank for your answer. It very helpful for me.
Taking advantage of the topic, you can make an example of what this rawtransaction would be like, anyway I'm trying here to give this error.
...