Author

Topic: Tranfer BTC using API or using node modules (Read 155 times)

jr. member
Activity: 43
Merit: 1
Solid - the right step towards the goal!
July 14, 2018, 02:39:48 PM
#4
hello,
I have created bitcoin addresses dynamically using nodejs module. I have private key and address.
we want to tranfer BTC received in those dynamically generated address we have private key for it.
At present we are using below nodejs code to send BTC

var bitcoinTransaction = require('bitcoin-transaction');
var to = "12zyHTgqfm3XT5K9afmaPjhcwvbAYuBBHk";
var from ="1DnqKVAPB9JUxQxuc6xe9jycyvhWhu7NzS";
var privKeyWIF = "XXXX-Privatekey-XXXXXXX";

bitcoinTransaction.getBalance(from, { network: "mainnet" }).then((balanceInBTC) => {
      var btcToSend=parseFloat(0.0001);
         bitcoinTransaction.sendTransaction({
                from: from,
                to: to,
                privKeyWIF: privKeyWIF,
                btc: 0.00000547,
                network: "mainnet",
                fees: 3,
        }).catch((error) => {
                console.log(error);
        }).then((result)=> {
                console.log(result);
        });
        console.log(balanceInBTC);

}).catch((error) => { console.log(error); });


As we have done the transaction using this code it cost me fees as 206 satoshi per byte
Here is the tx :  https://www.[Suspicious link removed]/en/btc/tx/2d4639266d3af9416b1f022193a3587df501a678a794744dbf8f4fddcecc3564

What i have to change to specify fixed fees for transaction. Is there any other API or node module that i can use for transfering BTC from one address to another using private key of address?

Hi, i think that changing the parameter fees could solve that, and if you are looking for other library i specially use bitcore-wallet-client there you can use the private key of address, that lets me specify the priority of transactions and many other specifications
HCP
legendary
Activity: 2086
Merit: 4363
At present we are using below nodejs code to send BTC

var bitcoinTransaction = require('bitcoin-transaction');
var to = "12zyHTgqfm3XT5K9afmaPjhcwvbAYuBBHk";
var from ="1DnqKVAPB9JUxQxuc6xe9jycyvhWhu7NzS";
var privKeyWIF = "XXXX-Privatekey-XXXXXXX";

bitcoinTransaction.getBalance(from, { network: "mainnet" }).then((balanceInBTC) => {
      var btcToSend=parseFloat(0.0001);
         bitcoinTransaction.sendTransaction({
                from: from,
                to: to,
                privKeyWIF: privKeyWIF,
                btc: 0.00000547,
                network: "mainnet",
                fees: 3,
        }).catch((error) => {
                console.log(error);
        }).then((result)=> {
                console.log(result);
        });
        console.log(balanceInBTC);

}).catch((error) => { console.log(error); });


What i have to change to specify fixed fees for transaction. Is there any other API or node module that i can use for transfering BTC from one address to another using private key of address?
You've set the fee wrong... as per the documentation here: https://www.npmjs.com/package/bitcoin-transaction#bitcointransactionsendtransactionoptions

You need to set the "fee" option... your code has it as "fees" Wink
legendary
Activity: 1624
Merit: 2509
Is there any other API or node module that i can use for transfering BTC from one address to another using private key of address?

Well, you might start with telling us the current module you are using.

Usually you always can set a fee (or all the outputs including change output).


https://github.com/bitcoinjs/bitcoinjs-lib does give you the option:

Code:
const txb = new bitcoin.TransactionBuilder(regtest)
        txb.addInput(unspent0.txId, unspent0.vout) // alice1 unspent
        txb.addInput(unspent1.txId, unspent1.vout) // alice2 unspent
        txb.addOutput('mwCwTceJvYV27KXBc3NJZys6CjsgsoeHmf', 8e4) // the actual "spend"
        txb.addOutput(aliceCpkh.address, 1e4) // Alice's change
// (in)(4e4 + 2e4) - (out)(1e4 + 3e4) = (fee)2e4 = 20000, this is the miner fee

Source: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.js#L55
newbie
Activity: 1
Merit: 0
hello,
I have created bitcoin addresses dynamically using nodejs module. I have private key and address.
we want to tranfer BTC received in those dynamically generated address we have private key for it.
At present we are using below nodejs code to send BTC

var bitcoinTransaction = require('bitcoin-transaction');
var to = "12zyHTgqfm3XT5K9afmaPjhcwvbAYuBBHk";
var from ="1DnqKVAPB9JUxQxuc6xe9jycyvhWhu7NzS";
var privKeyWIF = "XXXX-Privatekey-XXXXXXX";

bitcoinTransaction.getBalance(from, { network: "mainnet" }).then((balanceInBTC) => {
      var btcToSend=parseFloat(0.0001);
         bitcoinTransaction.sendTransaction({
                from: from,
                to: to,
                privKeyWIF: privKeyWIF,
                btc: 0.00000547,
                network: "mainnet",
                fees: 3,
        }).catch((error) => {
                console.log(error);
        }).then((result)=> {
                console.log(result);
        });
        console.log(balanceInBTC);

}).catch((error) => { console.log(error); });


As we have done the transaction using this code it cost me fees as 206 satoshi per byte
Here is the tx :  https://www.[Suspicious link removed]/en/btc/tx/2d4639266d3af9416b1f022193a3587df501a678a794744dbf8f4fddcecc3564

What i have to change to specify fixed fees for transaction. Is there any other API or node module that i can use for transfering BTC from one address to another using private key of address?
Jump to: