"Prepared output should be pay-to-pubkeyhash" when attempting a raw exchange with a multisig

+2 votes
Should it be possible to have an atomic exchange between a regular address and a multisig? I keep encountering errors saying I need a pay-to-pubkeyhash. Example steps I'm doing below:

I have a multisig address that has signatories from both of my nodes. The multisig address is `381VVXe7NaeimsqQR3p3tAvVNd388dEcYs `. This address is fine, I'm able to do normal raw transactions with it.

I issue a custom asset USD to one of my addresses:

`issue 1BUArAafjtLBhWZru1sM6ZbQJ2rbXDn3RR USD 2000 0.01`

I lock some amount of USD:

`preparelockunspentfrom  1BUArAafjtLBhWZru1sM6ZbQJ2rbXDn3RR '{"USD": 100}'`

Txid b5fb8e75814ea5602e960700f90d5b9127cb32eb68441ee6437b63a759025786

I also prepare some amount of native currency on the multisig:

`createrawsendfrom 381VVXe7NaeimsqQR3p3tAvVNd388dEcYs '{"381VVXe7NaeimsqQR3p3tAvVNd388dEcYs": {"":9900}}' '[]' lock,sign`

I sign it on the 2nd node and send the transaction. This is fine. Txid 54e228a37769850f1ada2aa15a85a7497a915600d661462f1e526b9a99fbd127

I create a raw exchange using the 100 USD reserved above for 9900 native currency:

createrawexchange" b5fb8e75814ea5602e960700f90d5b9127cb32eb68441ee6437b63a759025786 0 '{"":9900}'

I call appendrawexchange, confirming I accept 100 USD in exchange:

`appendrawexchange <raw-exchange-from-above> 54e228a37769850f1ada2aa15a85a7497a915600d661462f1e526b9a99fbd127 0 '{"USD": 100}'`

At this point I get an error:

error code: -5
error message:
Prepared output should be pay-to-pubkeyhash

The error occurs no matter on which node I try to execute the above command.

I'm unsure what this error message means. Have I missed a step? Or is this simply not allowed?

Thank you
asked Aug 27 by anonymous
edited Aug 28

1 Answer

0 votes

I'm afraid you cannot use the high-level exchange APIs for multisig addresses, because part of creating or appending to an exchange is signing the transaction, and the full signature cannot be applied for a multisig if one of its required private keys is on another node.

Your solution here instead of using appendrawexchange is to use appendrawtransaction + signrawtransaction. There is documentation on this page for a case with a regular address that uses external private keys, rather than a multisig, but the principle is the same:


Search on that page for appendrawtransaction which is the stage where you see the problem.

answered Aug 28 by MultiChain
If the multisig address prepares the transaction, how does the following step change:

 signrawtransaction [paste-hex-blob] '[]' '["V..."]' SINGLE|ANYONECANPAY

If I try to add the SINGLE|ANYONECANPAY parameter to any of the multisig signing stages, the hex output is the same as the input (decoding shows that no signature was added)

If it matters, I am not passing the private keys in the 3rd parameter; the multisig signatories have their private keys stored in the nodes:

signrawtransaction <hex-blob> '[]' '[]' SINGLE|ANYONECANPAY

If I remove the SINGLE|ANYONECANPAY parameter, the raw transaction can be signed and completed (IDK what happens if I send it)
I'll re-post my followup as a separate question instead.