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
588 stars 199 forks source link

error transaction #272

Closed Shantaramm closed 1 year ago

Shantaramm commented 1 year ago

I insert output_n, such as it is necessary, I indicate all the necessary information. The transaction does not go through, what did I do wrong?

from bitcoinlib.keys import Key
from bitcoinlib.services.services import Service
from bitcoinlib.transactions import Transaction

k = Key("wif", network="testnet")

srv = Service(network="testnet")

print(srv.getutxos("mjBQGdooSmck8M2kcWHphTMPaxxm1HLA5V"))

txid = "086f43a299e00496a3717dd63cee92a77a3a367e76c05651dc1cbd8b420b16a9"

t = Transaction(network="testnet")

t.add_input(txid, 1)
t.add_output(10000, "mgM5Sg4cXYT9GzYK9RVyMkKhzzSxEw3Gtp")
t.sign(k)
tx = Service(network="testnet").sendrawtransaction(t.raw_hex())
print(t.verify())
print(tx)

изображение

mccwdev commented 1 year ago

Could you check in the logs, too see if there are any specific provider errors? Are you using the latest version? And are you sure the fees is sufficient and the outputs unspent?

Shantaramm commented 1 year ago

Could you check in the logs, too see if there are any specific provider errors? Are you using the latest version? And are you sure the fees is sufficient and the outputs unspent?

And what should be done to check if the transaction was spent? I used the send_to() method, where I did not choose which transaction to take from utxo. How to make send_to not take spent transactions? (issue 274)

Shantaramm commented 1 year ago

And one more question, when I send a transaction using the send / send_to method, from the wallet, how can I specify the change address? :)

mccwdev commented 1 year ago

With a Wallet object you can just use the scan(), utxos_update() method to get the unspent outputs. If you create a Transaction object yourself you use the Service.getutxos() like in the example above. It could be that there is some problem with the service providers or a mismatch of keys/utxos. If you could send me the complete code and outputs in the logs I can take a look into it.

The Wallet.send() method pick the next available unused change_address from the wallet. However if you specify a complete output_arr and fee which adds up as the same amounts of the total of the inputs, then no change output is generated. So you specify the change output yourself.

Shantaramm commented 1 year ago

I figured out the first one, it was my mistake, I sent transactions with a small commission, so utxo were involved, but not spent, since the transaction was not confirmed. Thank you!

Regarding the second question, should I just specify the second output as: [(addr, amount), (addr_change, amount_imput-amount-fee)]?

Shantaramm commented 1 year ago

P.s And I also wanted to say that litecoin_testnet service providers do not behave correctly, or maybe I'm doing something wrong, there are no such problems with other networks.

изображение

mccwdev commented 1 year ago

Regarding the second question, should I just specify the second output as: [(addr, amount), (addr_change, amount_imput-amount-fee)]?

Yes correct

At the moment only bitaps and chain.so offer a litecoin_testnet api, and both providers do not have fee estimation data. So unfortunately the only workaround would be to install a litecoin testnet node locally.

Shantaramm commented 1 year ago

Okay, thanks for the replies!

Shantaramm commented 1 year ago

And I also wanted to ask) When I do srv.getutxo(addr), the director sometimes returns outdated information or an empty array to me, can this only happen in the testnet or is it also possible in the normal litecoin / bitcoin network?

Even when I make a transaction in testnet for 50000 Sat, it goes through (I have fee=10000 by default), if the amount I send is 200000, then the transaction does not go through, fee = 10000. Is 10,000 a small commission? How can I look for a specific transaction error if I use Transaction()?

Thank you for your time!!!

mccwdev commented 1 year ago

That fee should be sufficient. The getutxos() method depends on external service providers, if they return incorrect or incomplete results, the method does as well. Please check the logs and let me know which provider causes this issue, to see if it fixable.

Shantaramm commented 1 year ago

Okay thanks! Can you tell me how I can check the logs?

mccwdev commented 1 year ago

You can find the logs in ./bitcoinlib/bitoinlib.log in your user directory