Bitcoin Forum
April 25, 2024, 02:28:42 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Tranfer BTC using API or using node modules  (Read 123 times)
rushabhmadhu (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
June 29, 2018, 07:34:45 AM
 #1

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?
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714012122
Hero Member
*
Offline Offline

Posts: 1714012122

View Profile Personal Message (Offline)

Ignore
1714012122
Reply with quote  #2

1714012122
Report to moderator
bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
June 29, 2018, 02:33:52 PM
 #2

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

HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
June 30, 2018, 09:17:48 AM
 #3

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

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
DIGNIDAD
Jr. Member
*
Offline Offline

Activity: 43
Merit: 1

Solid - the right step towards the goal!


View Profile WWW
July 14, 2018, 07: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

Solid Sources is a technology based blockchain That allows to decentralize the collection of statistical data in a free and safe way
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!