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
614 stars 204 forks source link

Transaction spending more fee than provided #263

Closed hammersharkfish closed 2 years ago

hammersharkfish commented 2 years ago
f = open('config.json')
config = json.load(f)
print(config)
f.close()

w = Wallet.create('segwit_p2wpkh-btc', witness_type='segwit',keys=config["sender"], network="bitcoin",encoding = "bech32")
t = w.send_to(config["reciever"], '0.00005000 BTC', fee=config["fee"], network="bitcoin", min_confirms=1,
     offline=False)
print("resulting transaction\n",t)
print("info",t.info(),t.verified,)

^Code

{'reciever': 'bc1qzahswgq9jttzmxsy9gqrty9pw5h8s0xgajee23', 'sender': 'private key', 'fee': 3000}

resulting transaction
 8dcbfc79316ab357ee39a41d02d4ab7e941de1cdd8d0c7f5a8cc33033596b5ee
Transaction 8dcbfc79316ab357ee39a41d02d4ab7e941de1cdd8d0c7f5a8cc33033596b5ee
Date: None
Network: bitcoin
Version: 1
Witness type: segwit
Status: unconfirmed
Verified: True
Inputs
- bc1qrvz9sss33yly2p2rcrdk6s9fthnl060twc034t 0.00008552 BTC 970db4536517243a0b0297e322eeccfe7f4ca298f9fbd633b851d77c20687644 0
  segwit sig_pubkey; sigs: 1 (1-of-1) valid
Outputs
- bc1qzahswgq9jttzmxsy9gqrty9pw5h8s0xgajee23 0.00005000 BTC p2wpkh U
Size: 191
Vsize: 110
Fee: 3552
Confirmations: 0
Block: None
Pushed to network: True
Wallet: segwit_p2wpkh-btc

^ Prints

Its showing Fee: 3552 which is incorrect I only provided fee:3000 . Shouldn't 552 satoshi go to change wallet ?

https://www.blockchain.com/btc/tx/8dcbfc79316ab357ee39a41d02d4ab7e941de1cdd8d0c7f5a8cc33033596b5ee

mccwdev commented 2 years ago

This is by design. The change output would have an amount lower than the dust amount. The extra output could cost more fees than the 552 satoshi.

You can change the dust amount in the network settings file (networks.json)

See code in https://github.com/1200wd/bitcoinlib/blob/777e06695cd9d963796afa5ab890e58d140de784/bitcoinlib/wallets.py#L3639

hammersharkfish commented 2 years ago

Oh.Thanks .