ofek / bit

Bitcoin made easy.
https://ofek.dev/bit/
MIT License
1.25k stars 216 forks source link

Transaction broadcast failed #167

Closed mrx23dot closed 2 years ago

mrx23dot commented 2 years ago

I'm trying the main example on mainnet with minimal values:

from bit import Key

key = Key.from_hex('..')

print('bal',key.get_balance('satoshi'),'sat')
print('unspents', key.unspents) 
# got: unspents [Unspent(amount=18485, confirmations=6, script='..', txid='..', txindex=30, segwit=False, sequence=..)]

outputs = [
  ('1EH.., 1, 'satoshi'),
]

key.send(outputs, fee=5, absolute_fee=True) # will take long time to verify, only for testing
key.send(outputs, fee=10, absolute_fee=False) 

# expecting getting back the remaining

All of them give:

Traceback (most recent call last):
  File "test_transf_single.py", line 19, in <module>
    txid = key.send(outputs, fee=5, absolute_fee=False)
  File "C:\py38_64\lib\site-packages\bit\wallet.py", line 385, in send
    NetworkAPI.broadcast_tx(tx_hex)
  File "C:\py38_64\lib\site-packages\bit\network\services.py", line 1226, in broadcast_tx
    raise ConnectionError('Transaction broadcast failed, or Unspents were already used.')
ConnectionError: Transaction broadcast failed, or Unspents were already used.

I've got confirmed unspents so no idea why getting this.

Vers bit==0.8.0 Python 3.8.8

mrx23dot commented 2 years ago

API https://mempool.space/api/v1/fees/recommended says: "minimumFee": 1 so key.send(outputs, fee=1, absolute_fee=True) or worst case absolute_fee=False should work.

mrx23dot commented 2 years ago

Turns out the smallest amount transferable is 1000sat. A warning would have been nicer.