Signing transactions with counterpartyd (sign_tx method)

http://counterparty.io/docs/counterpartyd/#sign-tx


I always get “Invalid arguments” exception.
Does anybody know how to sign transactions using this method?

There’s an example above on the same page, did you use the same parameters (and have to try to pass “privkey” (togoether with its value) as the 2nd parameter?).  Also at the very bottom of the page: " If the private key you need to sign the raw transaction is not in the local bitcoind wallet.dat, you must first sign the transaction yourself (or, alternatively, you can call the sign_tx API method and specify the private key string to it, and counterpartyd will sign it for you). In either case, once you have the signed, hex-encoded transaction string, you can then call the broadcast_tx API method, which will then broadcast the transaction on the Bitcoin network for you.“



payload = {
“method”: “sign_tx”,
“params”: {‘unsigned_tx_hex’: unsigned_tx}, #could also specify an external private key to use for signing here
“jsonrpc”: “2.0”,
“id”: 0,
}
signed_tx = requests.post(url, data=json.dumps(payload), headers=headers, auth=auth)
print(
SIGN_TX RESULT: ", signed_tx)
</div></div></div></div>

Ah, looks like it’s a mistype in the API documentation. Thanks for a clue.


Param “tx_hex” should be “unsigned_tx_hex” like in the example.
Now I get annoying “Invalid request/response” error (private key in WIF format was provided).

Ah, no wonder, I was also confused by that. I submitted a bug report for that. Good catch.


Can you post a (testnet?) copy of the invalid transaction request here?
Can you post a (testnet?) copy of the invalid transaction request here?
Ok, this is a log of create_send and sign_tx commands. As you can check - privkey corresponds to given source address and pubkey.

[2015-01-12 09:02:49] Call to: http://localhost:14000/api/
[2015-01-12 09:02:49] Execute command "create_send"
[2015-01-12 09:02:49] Params: 
array (
  'asset' => 'TESET',
  'source' => 'msGLNXGXrXrcddBUKpGhCPN8tg3JXaPksT',
  'destination' => 'mn2dPT6sBPQ2wVXw3hGJqKwuEV4teHzQCx',
  'quantity' => 500000000,
  'allow_unconfirmed_inputs' => true,
  'encoding' => 'multisig',
  'pubkey' => '034749677842a136007700a713408fb1fc3324a2c2213081a3b99cd2505488704f',
)
[2015-01-12 09:02:49] Result: '0100000001ddd9275f52525c8fae0574e52f15486c8cd00d44600346878983fc388678ee93020000001976a91480ddb2ef94bcd7c3256b227b3831f87315b7dc5b88acffffffff0336150000000000001976a914476d736977f5a7372194a28c6c9974509b9ac82b88ac781e00000000000069512103232d0e7ee687012714c9eda5061f755406b7ec14532079f810fb8e23d11df83e2102607d3fabbc227e7e2e43bd13c73a73333e9a522d4a7b93ed38cbe5875c8dd39521034749677842a136007700a713408fb1fc3324a2c2213081a3b99cd2505488704f53ae0067e602000000001976a91480ddb2ef94bcd7c3256b227b3831f87315b7dc5b88ac00000000'

[2015-01-12 09:02:50] Call to: http://localhost:14000/api/
[2015-01-12 09:02:50] Execute command "sign_tx"
[2015-01-12 09:02:50] Params: 
array (
  'unsigned_tx_hex' => '0100000001ddd9275f52525c8fae0574e52f15486c8cd00d44600346878983fc388678ee93020000001976a91480ddb2ef94bcd7c3256b227b3831f87315b7dc5b88acffffffff0336150000000000001976a914476d736977f5a7372194a28c6c9974509b9ac82b88ac781e00000000000069512103232d0e7ee687012714c9eda5061f755406b7ec14532079f810fb8e23d11df83e2102607d3fabbc227e7e2e43bd13c73a73333e9a522d4a7b93ed38cbe5875c8dd39521034749677842a136007700a713408fb1fc3324a2c2213081a3b99cd2505488704f53ae0067e602000000001976a91480ddb2ef94bcd7c3256b227b3831f87315b7dc5b88ac00000000',
  'privkey' => 'cVuyRW2jVz2jqBC1EEXNrv2RmTFhDtYvEHwpuH5e9RsNdfHcgjb5',
)
[2015-01-12 09:02:50] ERROR: 'Invalid request/response'

A developer told me it could be the signature. 

You should probably try to sign the transaction externally with a known good external tool and compare output with this to make sure the signature is correct.
A developer told me it could be the signature. 
You should probably try to sign the transaction externally with a known good external tool and compare output with this to make sure the signature is correct.

Signing with bitcoinjs lib works good.

Thanks for letting us know!


There’s a KB with signing suggestion on the support site, but it’s difficult to make it prominent enough so unfortunately people still run into this issue. 

Maybe we should add this to API docs as well.

@sillywilly - I’m working through some of this now in the ruby gem (and thereafter the python gem) Transaction signing is a bit hard, but if you have access to a bicoind  server, who has your private key installed, it’s an easy thing to dispatch to bitcoind. Might that work for you until the client libs are out? What language are you developing in?

@brighton36 
Signing transactions on clientside suits me. I had a need in serverside signing to check the clientside signature (for some reason, time after time, I cannot broadcast signed transactions with added op_return output).

I will try to use bitcoind “signrawtransaction” instead of Counterparty’s sign_tx for now.

P.S. I am developing in PHP.
Now I need to sign transactions on server side.
sign_tx is not working for me (see above).
Any suggestions?