1200wd / bitcoinlib

Bitcoin and other Cryptocurrencies Library for Python. Includes a fully functional wallet, Mnemonic key generation and management and connection with various service providers to receive and send blockchain and transaction information.
http://bitcoinlib.readthedocs.io/
GNU General Public License v3.0
596 stars 199 forks source link

Error in transaction (sign and send): Please help. #384

Closed kernaldpark closed 5 months ago

kernaldpark commented 5 months ago

The address '2N5taVmftLF2VU4Phr4rJRvQuDMisej9K1R' has 50362 satosi but the sendrawtransaction() function returns false and bitcoin has not been sent

[source]

pk = 'uprv8tXDerPXZ1QsUAnKL1dTT6QzoFG8sqJ6siX2zM7NFouAggug37Z7ahbaBYgomKSMUH7tUL5QzjRA3PngFdr9SA6dxRvhnn4E4kVVbvr5BUG'
k = HDKey(pk)
addr = k.address()
print('addr: ', addr) # 2N5taVmftLF2VU4Phr4rJRvQuDMisej9K1R

print("Private Key wif_key(): " + k.wif_key())      # cUHF38Fi2AqQqQJbycDW6GEmeUJzu4HgqY9CnL4Sv7R6siKUYovT
print("Private Key private_hex: " + k.private_hex)  # c7e15b73b9786ad2665ab18e5d3ef246744f4ab066e2505432cadc51869d6f88
print("Public Key public_hex: " + k.public_hex)     # 03228a48d9f5c8b2156ed8e9810d7e85b8282fd8c9cd038cd49afb68cecfea7ebb
print("Public Key address(): " + k.address())       # 2N5taVmftLF2VU4Phr4rJRvQuDMisej9K1R

fee = 2000
value = 0
addr_to = 'tb1q6v2tn4k7j9w5xxvwepkhdjrdpuwlwjcw3par5r'

utxos = Service(network='testnet').getutxos(addr)
t = Transaction(network='testnet', fee=fee, witness_type='segwit')
for utxo in utxos:
    t.add_input(utxo['txid'], utxo['output_n'], value=utxo['value'], witness_type='segwit')
    value += utxo['value']
    print(utxo)
t.add_output(value-fee, addr_to)
print('*'*100)
t.sign(k)
t.verify()
t.info()
rtx = Service(network='testnet').sendrawtransaction(t.raw_hex())
print('rtx : ', rtx)

[log]

addr: 2N5taVmftLF2VU4Phr4rJRvQuDMisej9K1R Private Key wif_key(): cUHF38Fi2AqQqQJbycDW6GEmeUJzu4HgqY9CnL4Sv7R6siKUYovT Private Key private_hex: c7e15b73b9786ad2665ab18e5d3ef246744f4ab066e2505432cadc51869d6f88 Public Key public_hex: 03228a48d9f5c8b2156ed8e9810d7e85b8282fd8c9cd038cd49afb68cecfea7ebb Public Key address(): 2N5taVmftLF2VU4Phr4rJRvQuDMisej9K1R


Transaction d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43 Date: None Network: testnet Version: 1 Witness type: segwit Status: new Verified: True Inputs

rtl : False

kernaldpark commented 5 months ago

OOOPS....My mistake

jahvi commented 5 months ago

@kernaldpark Do you mind sharing what the issue was? I'm running into a similar problem

kernaldpark commented 5 months ago

The "pk" used in the source mentioned above was the master pk. This was an error because it was not the PK of the address "2N5taVmftLF2VU4Phr4rJRvQuDMisej9K1R".

Conclusion: This error occurred because it was not the PK of the address.

jahvi commented 5 months ago

@kernaldpark Thanks, it's not the same issue for me then 🥲