0

I am having trouble to sign a transaction on Blockcypher Test Network (using python):

import requests
from blockcypher (
    import send_faucet_coins, create_unsigned_tx, 
    make_tx_signatures, broadcast_signed_transaction
)

1. Create two new addresses

url = 'https://api.blockcypher.com/v1/bcy/test'
address_input = requests.post('%s/%s' % (url, 'addrs'), json={'token': api_key}).json()
'''
{'address': 'C45nBYCjNx1f9YVvSoXrS9uj21cJZCqdRP',
 'private': 'dde71ff0e59daa55ab9db6fc99b0c060d1d2b7948aa4fece27b876696e7a369d',
 'public': '027a4e91b0720d8820c78408ac7f3278b447efa03c5c21342d7086efacc0c43536',
 'wif': 'BvmP3YKzHW8BVaJ3RjrVh6zCDg9DhCHP4LqYVX6s3HxvPUpnSSUF'}
'''

address_output = requests.post('%s%s' % (url, 'addrs'), json={'token': api_key}).json()
'''
{'address': 'BtfkLhMMSJunX3CA43BAE1zmGnruabeDxs',
 'private': 'f4250bf0f077d11c38813ff6353f2d6750e24f3bc52b371760a397663069f31a',
 'public': '0245f4be87a2bd036abae729da25db58e2cfed964fdd385874aa71595c30c1339e',
 'wif': 'BwWch8gMhu37j9d73JMN7Gj5FvDjkpMGseyLnuxmGe4SKByR8Ljc'}
'''

2. Send some faucet coins to the address_input

send_faucet_coins(
    address_to_fund=address_input['address'], 
    satoshis=100000000, 
    coin_symbol='bcy', 
    api_key=api_key)
'''
{u'tx_ref': u'0de7b2b73de2d8b6588202b129ea96dfe1890adcd7fb174f75398b4ed1dd0728'}
'''

3. Create unsigned transaction

inputs = [{'address': address_input['address']}, ]
outputs = [{'address': address_output['address'], 'value': 900000}]
unsigned_tx = create_unsigned_tx(
    inputs=inputs, 
    outputs=outputs, 
    coin_symbol='bcy', 
    include_tosigntx=True, verify_tosigntx=True,
    api_key=api_key)
'''
{'tosign': ['7f7f02da6565f3409fef83cad257324e9fe3f4e85444d8afafa5521d7dea6570'],
 'tx': {'addresses': ['C45nBYCjNx1f9YVvSoXrS9uj21cJZCqdRP','BtfkLhMMSJunX3CA43BAE1zmGnruabeDxs'],
 'hash': '275ddde93ee1b85ce5583a09c4d69667a546df3dd4dc79623690857d6594e580',
  'inputs': [{'addresses': ['C45nBYCjNx1f9YVvSoXrS9uj21cJZCqdRP'],
     ...}],
  'outputs': [{u'addresses': [u'BtfkLhMMSJunX3CA43BAE1zmGnruabeDxs'],
    ...
    'value': 900000},
   ...],
  ...}}
'''

Then I have to sign the unsigned transaction and that where the error halts:

###4. Sign the unsigned transaction###

tx_signatures = make_tx_signatures(
    txs_to_sign=unsigned_tx['tosign'], 
    privkey_list=[address_input['private']], 
    pubkey_list=[address_input['public']])

AssertionError: Bad Signature: sig 30440220588709fa21ea1b9c019e71a74ce1994f10c2c20560f160debf37da8de439942802202841dc452ee04af690e0fba97d304cc98cf84c47f435946197a0c50900c9bda7 for tx 7f7f02da6565f3409fef83cad257324e9fe3f4e85444d8afafa5521d7dea6570 with pubkey 027a4e91b0720d8820c78408ac7f3278b447efa03c5c21342d7086efacc0c43536

I tried to sign the transaction with btcutils/signer, it shows me the same signature, which works perfectly:

signer [transaction_tosign] [private_key]

./signer 7f7f02da6565f3409fef83cad257324e9fe3f4e85444d8afafa5521d7dea6570 dde71ff0e59daa55ab9db6fc99b0c060d1d2b7948aa4fece27b876696e7a369d

The result of signatures identical: 30440220588709fa21ea1b9c019e71a74ce1994f10c2c20560f160debf37da8de439942802202841dc452ee04af690e0fba97d304cc98cf84c47f435946197a0c50900c9bda7

5. Now I could actually successfully broadcat it to Blockcypher Network

tx_signatures = ['30440220588709fa21ea1b9c019e71a74ce1994f10c2c20560f160debf37da8de439942802202841dc452ee04af690e0fba97d304cc98cf84c47f435946197a0c50900c9bda7']
broadcast_signed_transaction(
    unsigned_tx=unsigned_tx, 
    signatures=tx_signatures, 
    pubkeys=[address_input['public']], 
    coin_symbol='bcy', 
    api_key=api_key)
'''
{'tosign': [''],
 'tx': {'addresses': ['C45nBYCjNx1f9YVvSoXrS9uj21cJZCqdRP', 'BtfkLhMMSJunX3CA43BAE1zmGnruabeDxs'],
  'hash': 'b954b6d225d84d77e65f22490b09409cf77d245e82b023181c1dac9f48b8f45d',
  'inputs': [{'addresses': ['C45nBYCjNx1f9YVvSoXrS9uj21cJZCqdRP'],
    ...
    }],
  'outputs': [{'addresses': ['BtfkLhMMSJunX3CA43BAE1zmGnruabeDxs'],
    ...
    'value': 900000},
   ...}],
  ...}}
'''

What is wrong with Blockcypher.make_tx_signatures ?
Could that be an issue using BCY symbol for Blockcypher TestNetintead of BTC for Bitcoin TestNet?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.