<p>I'm using <code>bitcoind</code> and for the transfer of tokens from one account to other, I'm using <code>sendFrom</code> method. but there is a transaction fee calculation and on the bitcoin-qt panel, In the transactions screen, it is showing an fee amount(-0.00001215) was deducted. </p>

<pre><code>Status: 2/unconfirmed, broadcast through 3 nodes
Date: 23-10-2017 11:25
To: EVR purchase
Total debit: -0.10000000 BTC
Total credit: 0.10000000 BTC
Transaction fee: -0.00001215 BTC
Net amount: -0.00001215 BTC

Comment:
addr
Transaction ID: c9f7c16c2f61818a6c6180ea2242e2139e4bb4400ab199e7c9f2b93802d6ed52
Transaction total size: 373 bytes
Output index: 0  
</code></pre>

<p>Currently, I'm following <a href="http://bitcoinfees.21.co/api/v1/fees/recommended" rel="nofollow noreferrer">http://bitcoinfees.21.co/api/v1/fees/recommended</a> and getting the fastest fee from that api and then using bitcoin-cli commands, to set the transaction fee(<code>settxfee</code>) and then doing the transfer. But instead of the given txFee, some random txfee is getting deducted from the wallet.</p>

<p>Can anyone help me, how to calculate the txFee properly?</p>

<p>My Code :</p>

<pre><code>client.walletPassphrase(config.BTCWalletPassword, 600)
.then(function (transactionHash) {

    client.setTxFee(txFee).then(function (successdata) {

        client.sendFrom(fromAccountName, toAccountAddress, totalAmount, 0, 'comment1', 'comment2')
        .then(function (transactionHash) {
            console.log(transactionHash);

            client.walletLock()
            .then(function (locked) {
                process.exit();
            })
            .catch(function (err) {
                process.exit();
            });
        })
        .catch(function (err) {
            console.log(err);
            process.exit();
        });
    })
    .catch(function (err) {
        console.log('settxfee error :'+ err);
        process.exit();
    });    
})
.catch(function (err) {
    console.log(err);
    process.exit();
});
</code></pre>

CC BY-SA 3.0
2017-10-23T08:07:25.620Z
You're aware that settxfee sets the fee **per kilobyte** of vsize, as you can't predict the size of a transaction in advance. Could that explain what you're seeing?
Pieter Wuille
CC BY-SA 3.0
2017-10-26T04:28:23.857Z
@PieterWuille : Thanks for the reply. is there anyway we could get the size of the transaction?  
for now, I'm making my transaction size to be 250 bytes (average transaction size)
RealSteel
CC BY-SA 3.0
2017-10-26T07:21:19.240Z
Yes, if you use the create/fund/sign/sendrawtransactions suite of functions. But you really shouldn't care about total fee - it isn't relevant.
Pieter Wuille
CC BY-SA 3.0
2017-10-26T07:22:36.067Z
But please just answer my question. The comments section is not for answering. I'm asking for clarification on what is going on to write an appropriate response.
Pieter Wuille
CC BY-SA 3.0
2017-10-26T07:24:19.223Z
@PieterWuille : so, instead of sendFrom, I need to first create a raw transaction and then do the process as you have mentioned here: 
https://bitcoin.stackexchange.com/a/43601/60371
RealSteel
CC BY-SA 3.0
2017-10-26T07:31:09.223Z
@PieterWuille : yeah.. now, I understood what the problem is. you can post an answer here.
RealSteel
<transactions><bitcoin-core><bitcoind><transaction-fees><bitcoin-core-development>
bitcoind transaction fee calculation
RealSteel
# bitcoind transaction fee calculation

(Asked by: username_0 on 2017-10-23)

I'm using `bitcoind` and for the transfer of tokens from one account to other, I'm using `sendFrom` method. but there is a transaction fee calculation and on the bitcoin-qt panel, In the transactions screen, it is showing an fee amount(-0.00001215) was deducted.

```
Status: 2/unconfirmed, broadcast through 3 nodes
Date: 23-10-2017 11:25
To: EVR purchase
Total debit: -0.10000000 BTC
Total credit: 0.10000000 BTC
Transaction fee: -0.00001215 BTC
Net amount: -0.00001215 BTC

Comment:
addr
Transaction ID: c9f7c16c2f61818a6c6180ea2242e2139e4bb4400ab199e7c9f2b93802d6ed52
Transaction total size: 373 bytes
Output index: 0  

```

Currently, I'm following <http://bitcoinfees.21.co/api/v1/fees/recommended> and getting the fastest fee from that api and then using bitcoin-cli commands, to set the transaction fee(`settxfee`) and then doing the transfer. But instead of the given txFee, some random txfee is getting deducted from the wallet.

Can anyone help me, how to calculate the txFee properly?

My Code :

```
client.walletPassphrase(config.BTCWalletPassword, 600)
.then(function (transactionHash) {

    client.setTxFee(txFee).then(function (successdata) {

        client.sendFrom(fromAccountName, toAccountAddress, totalAmount, 0, 'comment1', 'comment2')
        .then(function (transactionHash) {
            console.log(transactionHash);

            client.walletLock()
            .then(function (locked) {
                process.exit();
            })
            .catch(function (err) {
                process.exit();
            });
        })
        .catch(function (err) {
            console.log(err);
            process.exit();
        });
    })
    .catch(function (err) {
        console.log('settxfee error :'+ err);
        process.exit();
    });    
})
.catch(function (err) {
    console.log(err);
    process.exit();
});

```

**Tags:** transactions, bitcoin-core, bitcoind, transaction-fees, bitcoin-core-development

> **Comments:**
> **username_1**: You're aware that settxfee sets the fee **per kilobyte** of vsize, as you can't predict the size of a transaction in advance. Could that explain what you're seeing?  
> **username_0**: @username_1 : Thanks for the reply. is there anyway we could get the size of the transaction?   for now, I'm making my transaction size to be 250 bytes (average transaction size)  
> **username_1**: Yes, if you use the create/fund/sign/sendrawtransactions suite of functions. But you really shouldn't care about total fee - it isn't relevant.  
> **username_1**: But please just answer my question. The comments section is not for answering. I'm asking for clarification on what is going on to write an appropriate response.  
> **username_0**: @username_1 : so, instead of sendFrom, I need to first create a raw transaction and then do the process as you have mentioned here:  https://bitcoin.stackexchange.com/a/43601/60371  
> **username_0**: @username_1 : yeah.. now, I understood what the problem is. you can post an answer here.  

---

## 0 answers

