<blockquote>
<ol>
<li>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,...).</li>
</ol>
</blockquote>
<p>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.</p>
<p>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.</p>
<blockquote>
<ol start="2">
<li>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.</li>
</ol>
</blockquote>
<p>You cannot control which block it goes into - you can offer a fee, and hope it incentivizes mimers to pick it up. Furter, <code>createrawtransaction</code> 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 <code>createrawtransaction</code> 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 &quot;change&quot;.</p>
<p>It is inadvisable to do this manually. You can use the <code>fundrawtransaction</code> 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.</p>
<p>Note: using the PSBT RPCs is generally a lot more convenient than using the raw transaction RPCs (see <code>createpsbt</code>, <code>walletcreatefundedpsbt</code>, <code>walletprocesspsbt</code>, <code>finalizepsbt</code>, ...).</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>Using <code>estimatesmartfee</code>.</p>

CC BY-SA 4.0
2021-08-12T16:05:51.577Z
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
CC BY-SA 4.0
2021-08-12T16:16:34.473Z
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
CC BY-SA 4.0
2021-08-12T16:33:12.010Z
You may be better off using regtest mode where you can jusg construct your own artificial transaction volume to feed the fee estimator.
Pieter Wuille
CC BY-SA 4.0
2021-08-12T15:07:33.730Z
2021-08-12T15:07:33.730Z
Pieter Wuille
<p>I'm developing a client on nodejs which connect to a bitcoin core node through JSON-RPC.</p>
<p>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).</p>
<p><a href="https://i.sstatic.net/cDnTb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cDnTb.png" alt="enter image description here" /></a></p>
<p>I have done some research and it seems that <strong>estimatesmartfee</strong> RPC method can be used.</p>
<p>I'm facing two problems.</p>
<ol>
<li>I've created a standalone endpoint to test <strong>estimatesmartfee</strong> method and the estimated fee is the same no matter how many blocks I have selected (2,4,6,...).</li>
<li>I'm using <strong>createrawtransaction</strong> 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.</li>
</ol>
<p>Side notes.</p>
<ul>
<li>I'm using testnet.</li>
<li>I have tried with <strong>sendtoaddress</strong> method as well but I don't know how to calculate fee_rate parameter to establish the transaction's fee.</li>
</ul>

<bitcoin-core><transaction-fees><testnet><node.js>
Select a fee based on confirmation time. How to implement it?
Simon
# Select a fee based on confirmation time. How to implement it?

(Asked by: username_0 on 2021-08-12)

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](https://i.sstatic.net/cDnTb.png)](https://i.sstatic.net/cDnTb.png)

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.

**Tags:** bitcoin-core, transaction-fees, testnet, node.js


---

## 1 answers

### Answer by username_1 on 2021-08-12. Score: 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.

> 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.

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`.

> **Comments:**
> **username_0**: Hi, username_1. 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?  
> **username_0**: 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?  
> **username_1**: You may be better off using regtest mode where you can jusg construct your own artificial transaction volume to feed the fee estimator.  

---

