0

I want to transfer Bitcoin from one individual address to another using API. But I want to set Transaction fees as per my requirement. So How can I do it ?

Right now I am using blockchain-transaction - npm api for transfer bitcoin from one address to another. So please shade some lights on this.

var bitcoinTransaction = require('bitcoin-transaction');
//Send all my money from wallet1 to wallet2 on the bitcoin testnet
var from = "mm3gdVh8n6YtcNyaTKYkveB6yTME7aDWNJ";
var to = "mgPUfqJk4X6gE4P5Do5RfpkTFsYmsSjCya";
var privKeyWIF = "cNZi8iySqBToXMpcsQaHKD5uv7HExBQJBSi4dTg3ZPaEzeNAzvbj";    //Private key in WIF form (Can generate this from bitcoinlib-js)
bitcoinTransaction.getBalance(from, { network: "testnet" }).then((balanceInBTC) => {
    return bitcoinTransaction.sendTransaction({
from: from,
to: to,
privKeyWIF: privKeyWIF,
btc: balanceInBTC,
network: "testnet"
});
});

2 Answers 2

0

I have not tried this myself but having a look through the documentation on blockchain-transaction - npm api it looks like you can query fees, under the advanced section:

fees - Gets a list of current fees based on the BitCoin network going rate.

https://www.npmjs.com/package/bitcoin-transaction

Looks like you can select a 'fastest' option or others:

Set the fee for the transaction. Can be either one of "fastest", "halfHour" or "hour" in which case the actual fee numbers are fetched from the fees provider. Or it can be just a plain number in which case that will be used as the Fee per Byte value in Satoshis. It is recommended to use one of the string aliases unless you know what you are doing.

You might have to specify a feesProvider, not sure if they have a default selected when nothing set.

3
  • I have try it in my code but it's not working. It shows me same error. First of all I try Fees=3(as integer) after that Fees="3"(as string) and also I have try for FeesProvider. but no luck. Jun 29, 2018 at 12:11
  • "It is recommended to use one of the string aliases unless you know what you are doing."
    – Fuzzybear
    Jun 29, 2018 at 12:45
  • "Can be either one of "fastest", "halfHour" or "hour" in which case the actual fee numbers are fetched from the fees provider."
    – Fuzzybear
    Jun 29, 2018 at 12:45
0

Finally I get answer for this question by surfing very much for this topic.

I found source code for transfer Bitcoin from one individual account to another.

"https://github.com/Blank101/bitcoin-transaction/blob/master/index.js"

and there I set feePerByte = 3 as per my requirement. So by set this Transaction fees My transaction does not deduct much more fees.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.