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();
});
  • 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? – Pieter Wuille Oct 23 '17 at 8:07
  • @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 Oct 26 '17 at 4:28
  • 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 Oct 26 '17 at 7:21
  • 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 Oct 26 '17 at 7:22
  • @PieterWuille : so, instead of sendFrom, I need to first create a raw transaction and then do the process as you have mentioned here: bitcoin.stackexchange.com/a/43601/60371 – RealSteel Oct 26 '17 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.