Bitcoin Forum
November 18, 2024, 11:17:15 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Looking for some help regarding a transaction issue with Bitcoin - CLI  (Read 229 times)
ramt1 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
November 02, 2021, 12:50:45 AM
Merited by RickDeckard (2), Pmalek (1)
 #1

Hey everyone.

I just came across this blog looking for some help about the issue that i'm having developing a payment gateway via BTC, so, jumping into it:

I'm creating (listing the address available txs outputs), signing and sending tx's via btc-cli, using the legacy commands. Even for the wallet creations (bech32) i'm using the cli, however wheh i send a transaction to the network and get it's details it always returns a JSON like this:

Code:
{
  "amount": 0.00000000,
  "fee": 0.00000000,
  "confirmations": 0,
  "trusted": true,
  "txid": "48c67f340414a3e8beb74aa20fa282c9f8b47dab5c8f6a2b8331c58302d746fe",
  "walletconflicts": [
  ],
  "time": 1635813636,
  "timereceived": 1635813636,
  "bip125-replaceable": "no",
  "details": [
    {
      "address": "tb1qkvf2k3yd5mc46gf7znwnpx7vty2pfmt9ezrg6m",
      "category": "send",
      "amount": -0.00041105,
      "label": "",
      "vout": 0,
      "fee": 0.00000000,
      "abandoned": false
    },
    {
      "address": "tb1qydzefuvmycm2sx5ngjy6ayjnudu3r2ezu62gnx",
      "category": "send",
      "amount": -0.00028895,
      "label": "",
      "vout": 1,
      "fee": 0.00000000,
      "abandoned": false
    },
    {
      "address": "tb1qkvf2k3yd5mc46gf7znwnpx7vty2pfmt9ezrg6m",
      "category": "receive",
      "amount": 0.00041105,
      "label": "",
      "vout": 0
    },
    {
      "address": "tb1qydzefuvmycm2sx5ngjy6ayjnudu3r2ezu62gnx",
      "category": "receive",
      "amount": 0.00028895,
      "label": "",
      "vout": 1
    }
  ],
  "hex": "02000000000101561b05e6ea871cf34b1bce09a623138b558a13b17cb82387be4613b09a0e95b60100000000ffffffff0291a0000000000000160014b312ab448da6f15d213e14dd309bcc591414ed65df70000000000000160014234594f19b2636a81a934489ae9253e37911ab2202473044022012ecb312379eaed3d45b83ca31447be1e59eb3f70bd4a2eab1a45d417400a049022036e790e564897d9c975f81bbeeb5225b54cac81effe619817f88a10a403755ca0121023325d7e56c02f2ddac211972c140b4c004f690ef995cc8fc7be4fdadf320faa000000000"
}


I'm setting a fee of 0.00280 BTC/KvB but it doesn't matter which fee i'm using on the node, it never gets confirmed or even broadcasted so i can't find neither tx on a explorer.
I don't really know what might causing this behaviour so i'd be grateful for any help.


Greetings!
Quickseller
Copper Member
Legendary
*
Offline Offline

Activity: 2996
Merit: 2374


View Profile
November 02, 2021, 01:05:22 AM
Last edit: November 02, 2021, 01:27:15 AM by Quickseller
 #2

You are sending to trstnet addresses (is this intentional?).

The transaction fee your transaction includes is less than what is required for nodes to relay your transaction.

Is this the only input that you have in your testnet wallet?

★ ★ ██████████████████████████████[█████████████████████
██████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
★ ★ 
ramt1 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
November 02, 2021, 01:56:56 AM
 #3

Yes, firstly i'm working in testnet for dev purposes, and i'm calculating the inputs according to the tx amount i.e. if i'm sending $50 ~
0,00081519 BTC, then I'll use the minimum UTXO to satisfy this amount.


I'm not quite sure how to calculate the fees dynamically in the network or even to set a static fee that satisfies every (or almost) tx
j2002ba2
Full Member
***
Offline Offline

Activity: 206
Merit: 447


View Profile
November 02, 2021, 09:16:11 AM
Last edit: November 02, 2021, 12:28:14 PM by j2002ba2
Merited by ABCbits (1)
 #4

Looks like you are trying to spend non-existent UTXO. Address tb1qkvf2k3yd5mc46gf7znwnpx7vty2pfmt9ezrg6m never received coins.

Edit:
My bad, the input is tb1qydzefuvmycm2sx5ngjy6ayjnudu3r2ezu62gnx. For some reason, blockstream.info/testnet just shows mainnet, and of course, didn't find it.

This transaction has zero fee, that's the problem. Nodes refuse to relay it.
Quickseller
Copper Member
Legendary
*
Offline Offline

Activity: 2996
Merit: 2374


View Profile
November 02, 2021, 12:09:43 PM
Merited by ABCbits (2)
 #5

Looks like you are trying to spend non-existent UTXO. Address tb1qkvf2k3yd5mc46gf7znwnpx7vty2pfmt9ezrg6m never received coins.
tb1qkvf2k3yd5mc46gf7znwnpx7vty2pfmt9ezrg6m is an output, not an input.

If you are getting an error message when trying to broadcast the transaction to the bitcoin network that says there are missing or invalid inputs, it is because this is a testnet transaction (the same thing happened to me before I noticed this is not a bitcoin mainnet tx).

I'm not quite sure how to calculate the fees dynamically in the network or even to set a static fee that satisfies every (or almost) tx
You can see this stackexchange discussion. You can also view this online calculator.

★ ★ ██████████████████████████████[█████████████████████
██████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
★ ★ 
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
November 02, 2021, 12:43:17 PM
Last edit: November 02, 2021, 02:11:26 PM by TheArchaeologist
Merited by ABCbits (3), Quickseller (1), nc50lc (1)
 #6

Here's my analysis:
So you created a transaction with a single input: spending the output with index 1 from txid b6950e9ab01346be8723b87cb1138a558b1323a609ce1b4bf31c87eae6051b56.

Looking up this transaction on testnet shows there are two outputs in this transaction. You are trying to spent the second output (index=1), 0.00070000 BTC linked to address tb1qydzefuvmycm2sx5ngjy6ayjnudu3r2ezu62gnx. This transaction seems to be unspent at the moment so: so far so good Smiley

Let's look at the outputs of your transaction:
Code:
0.00028895 to tb1qkvf2k3yd5mc46gf7znwnpx7vty2pfmt9ezrg6m
0.00041105 to tb1qydzefuvmycm2sx5ngjy6ayjnudu3r2ezu62gnx
-----------+
0.00070000
So the input of your transaction is equal to your outputs (meaning no fee is used). As pointed out by others this is a problem.

In order to test your transaction I tried submitting the transaction and it was accepted with txid 48c67f340414a3e8beb74aa20fa282c9f8b47dab5c8f6a2b8331c58302d746fe (the same as in your JSON under txid). Although since it has no fee it might actually never get confirmed. See https://live.blockcypher.com/btc-testnet/tx/48c67f340414a3e8beb74aa20fa282c9f8b47dab5c8f6a2b8331c58302d746fe/

My conclusion:
You scuccesfully created a transaction (although you should look into the fee). However to send your transaction you need the actual rawtransaction, which is in your json-output labeled "hex".

So the last step for you from the cli would be:
Code:
bitcoin-cli -testnet sendrawtransaction 02000000000101561b05e6ea871cf34b1bce09a623138b558a13b17cb82387be4613b09a0e95b60100000000ffffffff0291a0000000000000160014b312ab448da6f15d213e14dd309bcc591414ed65df70000000000000160014234594f19b2636a81a934489ae9253e37911ab2202473044022012ecb312379eaed3d45b83ca31447be1e59eb3f70bd4a2eab1a45d417400a049022036e790e564897d9c975f81bbeeb5225b54cac81effe619817f88a10a403755ca0121023325d7e56c02f2ddac211972c140b4c004f690ef995cc8fc7be4fdadf320faa000000000

In other words, the output you showed in JSON-format is from createrawtransaction. It justs create a signed transaction ready for broadcast. To actual broadcast the transaction you should use sendrawtransaction.

Hope this helps!

Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
ramt1 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
November 02, 2021, 05:20:45 PM
Last edit: November 02, 2021, 05:32:29 PM by ramt1
 #7

Thanks everyone.

Basically this is what i'm doing to build the TX:

1) Get a list of unspents that satisfies the tx amount.

2) Createrawtransaction using UTXO's list, the amount, the destiny address and the bitcoins change back to the owner address.
3)  Sign the raw hex resulted from the previous step.

4) sendrawtransaction.


These steps are all made via bitcoin-cli, however the issue is that none node is relying my transaction and as i can tell, it's due the transactions fee.

So, I've tried using the command settxfee to set a ridiculous high fee in order to see if my tx's are pickable for any node but still has no results.

Isn't this command what sets the fee for every transaction coming out of my node?

Also, i'm using Bitcoin core version 21.99...


Hope this information helps you to help me to make a successful transaction Sad
Quickseller
Copper Member
Legendary
*
Offline Offline

Activity: 2996
Merit: 2374


View Profile
November 02, 2021, 05:41:21 PM
 #8

Thanks everyone.

Basically this is what i'm doing to build the TX:

1) Get a list of unspents that satisfies the tx amount.
You need unspent outputs that satisfies the sum of the outputs plus the tx fee. You can see my previous post to calculate the size/weight of a transaction so you can calculate the fee amount based on the fee rate.

It is possible this will result in you having to loop multiple times to find the best inputs to use.

★ ★ ██████████████████████████████[█████████████████████
██████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
★ ★ 
ramt1 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
November 02, 2021, 06:06:53 PM
 #9


You need unspent outputs that satisfies the sum of the outputs plus the tx fee. You can see my previous post to calculate the size/weight of a transaction so you can calculate the fee amount based on the fee rate.

It is possible this will result in you having to loop multiple times to find the best inputs to use.

I can't see this post. What's the subject or the url?
Quickseller
Copper Member
Legendary
*
Offline Offline

Activity: 2996
Merit: 2374


View Profile
November 02, 2021, 06:23:59 PM
 #10


You need unspent outputs that satisfies the sum of the outputs plus the tx fee. You can see my previous post to calculate the size/weight of a transaction so you can calculate the fee amount based on the fee rate.

It is possible this will result in you having to loop multiple times to find the best inputs to use.

I can't see this post. What's the subject or the url?
https://bitcointalk.org/index.php?topic=5368740.msg58328381#msg58328381

★ ★ ██████████████████████████████[█████████████████████
██████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████
██████████████████████████████████████████████████████████████████
█████████████████████████████████████████████████████████████
████████████████████████████████████████████████████████████
███████████████████████████████████████████████████████████████████
★ ★ 
ramt1 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
November 02, 2021, 08:08:37 PM
 #11

So fundamentally, the idea is to send the tx amount plus the estimated fee in the same transfer?
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4361

<insert witty quote here>


View Profile
November 03, 2021, 12:21:03 AM
Merited by Quickseller (1)
 #12

You don't explicitly set a fee value when creating transactions like this... the fee is implicitly set as the different between sum(inputs) and sum(outputs).

So, if you have:
InputA + InputB + ... + InputN = 0.01 BTC
and
OutputA + OutputB + ... + OutputN = 0.00999500 BTC

0.01 - 0.00999500 = 0.00000500

Then you have effectively set the fee to be 0.00000500 BTC... the hard part is that it isn't "total fee" that generally determines your transactions chances of being picked up and included in a block... it's the fee rate... ie. (total fee / transaction "size"[1]).

Unfortunately, the estimation tools available (estimatefee and estimaterawfee) give answers in fee rate... and not total fee, so you'll need to do some maths on how big your transaction is going to be, to work out what the "total fee" should be.

Theoretically, you could just do what you've done, and create the transaction with Sum(Inputs) == Sum(Outputs), then check what the transaction size is... then use that value along with the estimated fee rates to calculate how much to reduce the "change" output by... then recreate the transaction using the newly calculated change value and hope for the best Tongue



[1] We'll ignore the size vs. weight for the minute.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
November 03, 2021, 07:07:47 PM
 #13

Did you consider using regtest instead of testnet? On regtest you can do as many tests/transfers as you want since you can mine your own coin. Then whenever you are satisfied with your results you could move on to testnet or live.

Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
ramt1 (OP)
Newbie
*
Offline Offline

Activity: 6
Merit: 3


View Profile
November 03, 2021, 07:31:08 PM
 #14

Did you consider using regtest instead of testnet? On regtest you can do as many tests/transfers as you want since you can mine your own coin. Then whenever you are satisfied with your results you could move on to testnet or live.
Yes, i did. However for demo purposes the testnet I was required to use testnet...

Beside that, I was able to successfully create a transaction that was relied by my peer, the difference was that I didn't set a fund address neither amount. So what i'm thinking is that the funded amount was too high that gave no room to fees. Does this makes sense?
nc50lc
Legendary
*
Offline Offline

Activity: 2604
Merit: 6424


Self-proclaimed Genius


View Profile
November 05, 2021, 02:43:32 AM
 #15

-snip-
I'm setting a fee of 0.00280 BTC/KvB but it doesn't matter which fee i'm using on the node, it never gets confirmed or even broadcasted so i can't find neither tx on a explorer.
-snip-
So, I've tried using the command settxfee to set a ridiculous high fee in order to see if my tx's are pickable for any node but still has no results.

Isn't this command what sets the fee for every transaction coming out of my node?
settxfee is under "wallet RPC" and wont be used by createrawtransaction,
it's only for wallet RPC commands such as send, sendtoaddress and sendmany.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!