Signrawtransaction with private key

I could send my asset by using Python script. The sender address was generated on my own bitcoind. The receiver address was generated on counterwallet.io. How can I send my asset from another address which was generated on counterwallet.io? I think I should use the private key explicitly at signing.

I have 3 addresses.

X: generated by my node
Y: generated by counterwallet.io
Z: generated by counterwallet.io

[X] --> [Y] is OK.
[Y] --> [Z] is what I want.

[X] --> [Y]

#! /usr/bin/env python3

import sys

from counterpartylib.lib import util
from counterpartylib.lib import config
from counterpartylib.lib.backend import addrindex

config.BACKEND_URL = 'http://xxx:xxx@localhost:8332'
config.RPC = 'http://xxx:xxx@localhost:4000'
config.BACKEND_SSL_NO_VERIFY = True
config.REQUESTS_TIMEOUT = 20

def counterparty_api(method, params):
    return util.api(method, params)

def bitcoin_api(method, params):
    return addrindex.rpc(method, params)

def do_send(source, destination, asset, quantity, fee = 0, encoding = 'UTF-8'):
    validateaddress = bitcoin_api('validateaddress', [source])
    assert validateaddress['ismine']
    pubkey = validateaddress['pubkey']
    unsigned_tx = counterparty_api('create_send', {'source': source, 'destination': destination, 'asset': asset, 'quantity': int(quantity), 'pubkey': pubkey, 'allow_unconfirmed_inputs': True})
    signed_tx = bitcoin_api('signrawtransaction', [unsigned_tx])['hex']
    tx_hash = bitcoin_api('sendrawtransaction', [signed_tx])
    return tx_hash

# Send to one 
do_send(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

I’m doing trial and error.

[Y] --> [Z]

def do_send(source, destination, asset, quantity, fee = 0, encoding = 'UTF-8'):
    #validateaddress = bitcoin_api('validateaddress', [source])
    #assert validateaddress['ismine']
    #pubkey = validateaddress['pubkey']
    pubkey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' ← I got pubkey from private key
    unsigned_tx = counterparty_api('create_send', {'source': source, 'destination': destination, 'asset': asset, 'quantity': int(quantity), 'pubkey': pubkey, 'allow_unconfirmed_inputs': True})
    #signed_tx = bitcoin_api('signrawtransaction', [unsigned_tx])['hex']
    signed_tx = bitcoin_api('signrawtransaction', [unsigned_tx] ['xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'])['hex'] ← Not sure this point
    tx_hash = bitcoin_api('sendrawtransaction', [signed_tx])
    return tx_hash

Maybe @brighton36 can give you a good answer.

You can obtain private key, but then you’d have to have it stored on your computer which is obviously not a good idea. There are utilities that can help you get private key for a given Counterwallet address. You could add the address to your Bitcoin Qt wallet. I don’t know how to do that “on the fly”.

Thank you so much. It worked after repeated trial and error. I used the Javascript example in documents page as reference. http://counterparty.io/docs/api/ I agree with you that using Javascript is more secure. It doesn’t need to store and transfer private key. I got some Javascript error when I run the Javascript example. I added some libraries and then it worked.

My Javascript import statement is this below.

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-md5.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha256.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha512.js"></script>
<script src="/js/vendor/bundle.js"></script>
<script src="/js/vendor/util.bitcore.js"></script>
<script src="/js/vendor/mnemonic.js"></script>
<script src="/js/vendor/util.bitcore.cw.js"></script>
1 Like

This topic was automatically closed after 17 days. New replies are no longer allowed.