0

I'm developing a client on nodejs which connect to a bitcoin core node through JSON-RPC.

I want the user to be able to select the fee they want based on the time (the same way bitcoin core GUI does it).

enter image description here

I have done some research and it seems that estimatesmartfee RPC method can be used.

I'm facing two problems.

  1. I've created a standalone endpoint to test estimatesmartfee method and the estimated fee is the same no matter how many blocks I have selected (2,4,6,...).
  2. I'm using createrawtransaction RPC method to build the transaction but I cannot find a point where I can specify to the transaction to be added in that block I have specified in the previous step.

Side notes.

  • I'm using testnet.
  • I have tried with sendtoaddress method as well but I don't know how to calculate fee_rate parameter to establish the transaction's fee.

1 Answer 1

1
  1. I've created a standalone endpoint to test estimatesmartfee method and the estimated fee is the same no matter how many blocks I have selected (2,4,6,...).

This is expected on testnet. It has very irregular and bursty transaction activity, as well as inconsistent fees due to a lack of market pressure. As fee estimation is based on observing the time it takes for transactions to confirm based on their feerate, there simply isn't useful data on testnet to create reasonably-looking fee estimates.

If you'd do this on mainmet you would get useful numbers. A rule of thumb is that your node needs to be running about twice as long as the target confirmation window you want.

  1. I'm using createrawtransaction RPC method to build the transaction but I cannot find a point where I can specify to the transaction to be added in that block I have specified in the previous step.

You cannot control which block it goes into - you can offer a fee, and hope it incentivizes mimers to pick it up. Furter, createrawtransaction is more low-level than what you want to do. Bitcoin transactions do not have an explicit fee; rather, the fee is the difference between the value of the UTXOs being spent in its inputs, and the value of the UTXOs being created in its outputs. With createrawtransaction you have to manually specify the inputs and outputs, and the fee is just the resulting difference. In general, you'll want to add an output back to an address you control yourself for "change".

It is inadvisable to do this manually. You can use the fundrawtransaction RPC to do this for you, if you are using the Bitcoin Core wallet functionality. You give it a raw transaction with just the output(s) you want, and it will select inputs from your own wallet to fund it, as well as add a change output back to itself when necessary.

Note: using the PSBT RPCs is generally a lot more convenient than using the raw transaction RPCs (see createpsbt, walletcreatefundedpsbt, walletprocesspsbt, finalizepsbt, ...).

I have tried with sendtoaddress method as well but I don't know how to calculate fee_rate parameter to establish the transaction's fee.

Using estimatesmartfee.

3
  • Hi, Pieter. Thanks for answering. The process I follow to execute the transaction is; createrawtransaction, fundrawtransaction, walletpassphrase, signrawtransaction, and finally sendrawtransaction. I fix a fee_rate in fundrawtransaction. But as I Commented I do not want to do it in that way anymore. The sendtoaddress method seems to be better because you can specify the target_block, estimate_mode,... It seems that estimatesmartfee is included in sendtoaddress method already. The other thing is, How can I use bitcoin core in testnet but with real values?
    – Simon
    Aug 12, 2021 at 16:05
  • The main thing I want to is to be able to use bitcoin core in testnet mode but with real values, Is there a way I can set some flag in bitcoin.conf file or something?
    – Simon
    Aug 12, 2021 at 16:16
  • You may be better off using regtest mode where you can jusg construct your own artificial transaction volume to feed the fee estimator. Aug 12, 2021 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.