<blockquote>
  <p><code>size = 180 * len(inputs) * 34 * len(outputs) + 10</code></p>
</blockquote>

<p>Unless you are using uncompressed keys (which very few wallets do today), this formula is wrong. It should be 148 instead of 180 as compressed keys are 32 bytes shorter than uncompressed keys.</p>

<blockquote>
  <p>My question is that can I use bitcoin-cli estimatefee for weight?</p>
</blockquote>

<p>No, you cannot. Bitcoin Core's fee estimation works on virtual size which is just the weight divided by 4. So instead you calculate the virtual size instead of the block weight and then you can use the fee estimate.</p>

CC BY-SA 3.0
2018-01-14T01:12:28.667Z
2018-01-14T01:12:28.667Z
Ava Chow
<p>I'm using estimatefee API to calculate transaction fee for Non-Segwit.</p>

<p>I'm using this formula now.</p>

<pre><code>size = 180 * len(inputs) * 34 * len(outputs) + 10
necessary_fee = int(size / 1000 * fee_per_kb)
</code></pre>

<p>Example (1 inputs, 2 outputs. They are all p2pkh)</p>

<pre><code>fee_per_kb = 25000 // result of bitcoin-cli estimatefee
size = 180 * 1 * 34 * 2 + 10
necessary_fee = int(size / 1000 * 25000)

// necessary_fee =&gt; 306250 satoshi
</code></pre>

<p>Now I need to calculate fee for Segwit. My question is that can I use bitcoin-cli estimatefee for weight? My expectation is this like below.</p>

<pre><code>fee_per_kb = 25000 // result of bitcoin-cli estimatefee
virtual_size = (Something calculation logic including segwit discount)
necessary_fee = int(virtual_size / 1000 * 25000)
</code></pre>

CC BY-SA 3.0
2018-01-09T09:39:25.687Z
Use `estimatesmartfee` instead.
MCCCS
<bitcoin-core><transaction-fees><segregated-witness>
Can I use bitcoin-cli estimatefee API for Segwit?
zono
# Can I use bitcoin-cli estimatefee API for Segwit?

(Asked by: username_0 on 2018-01-09)

I'm using estimatefee API to calculate transaction fee for Non-Segwit.

I'm using this formula now.

```
size = 180 * len(inputs) * 34 * len(outputs) + 10
necessary_fee = int(size / 1000 * fee_per_kb)

```

Example (1 inputs, 2 outputs. They are all p2pkh)

```
fee_per_kb = 25000 // result of bitcoin-cli estimatefee
size = 180 * 1 * 34 * 2 + 10
necessary_fee = int(size / 1000 * 25000)

// necessary_fee => 306250 satoshi

```

Now I need to calculate fee for Segwit. My question is that can I use bitcoin-cli estimatefee for weight? My expectation is this like below.

```
fee_per_kb = 25000 // result of bitcoin-cli estimatefee
virtual_size = (Something calculation logic including segwit discount)
necessary_fee = int(virtual_size / 1000 * 25000)

```

**Tags:** bitcoin-core, transaction-fees, segregated-witness

> **Comments:**
> **username_1**: Use `estimatesmartfee` instead.  

---

## 1 answers

### Answer by username_2 on 2018-01-14. Score: 1

> `size = 180 * len(inputs) * 34 * len(outputs) + 10`

Unless you are using uncompressed keys (which very few wallets do today), this formula is wrong. It should be 148 instead of 180 as compressed keys are 32 bytes shorter than uncompressed keys.

> My question is that can I use bitcoin-cli estimatefee for weight?

No, you cannot. Bitcoin Core's fee estimation works on virtual size which is just the weight divided by 4. So instead you calculate the virtual size instead of the block weight and then you can use the fee estimate.


---

