bitcoind transaction fee calculation

1

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();
});

RealSteel

Posted 2017-10-23T07:04:59.193

Reputation: 169

1You'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 2017-10-23T08:07:25.620

@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 2017-10-26T04:28:23.857

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 2017-10-26T07:21:19.240

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 2017-10-26T07:22:36.067

@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 2017-10-26T07:24:19.223

@PieterWuille : yeah.. now, I understood what the problem is. you can post an answer here.RealSteel 2017-10-26T07:31:09.223

No answers