Bitcoin Forum
May 12, 2024, 03:13:06 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Create a transaction with BitcoinJS  (Read 2479 times)
finales (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 0


View Profile
April 06, 2017, 05:09:09 PM
 #1

Do you need to be running that code on a server that also acts as a Bitcoin Core Node in order to broadcast the transaction? Or am I misthinking how this works? Thanks!
"Your bitcoin is secured in a way that is physically impossible for others to access, no matter for what reason, no matter how good the excuse, no matter a majority of miners, no matter what." -- Greg Maxwell
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
dannon
Member
**
Offline Offline

Activity: 70
Merit: 11


View Profile
April 10, 2017, 12:03:02 PM
 #2

You do not need to be running a node to create and sign transactions. You need to be running a node to have the data to put in the transaction or be able to get that data from somewhere else.

Sad Sad Anyone else sick of trying to join signature campaigns and being denied after you have worn their signature for a week? Sad Sad
finales (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 0


View Profile
April 11, 2017, 06:45:58 PM
 #3

What data are you referring to? Thanks
dannon
Member
**
Offline Offline

Activity: 70
Merit: 11


View Profile
April 12, 2017, 11:04:52 AM
 #4

What data are you referring to? Thanks

Blockchain data. Information about previous transactions.

Sad Sad Anyone else sick of trying to join signature campaigns and being denied after you have worn their signature for a week? Sad Sad
nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
April 12, 2017, 12:31:29 PM
 #5

Do you need to be running that code on a server that also acts as a Bitcoin Core Node in order to broadcast the transaction? Or am I misthinking how this works? Thanks!


I suppose that you did this :

Code:
var tx = new bitcoin.TransactionBuilder()

// Add the input (who is paying):
// [previous transaction hash, index of the output to use]
var txId = 'aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31' //
tx.addInput(txId, 0)

// Add the output (who to pay to):
// [payee's address, amount in satoshis]
tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000)

// Initialize a private key using WIF
var privateKeyWIF = 'L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy'
var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF)

// Sign the first input with the new key
tx.sign(0, keyPair);

/*-------------------------------------------Look here ---------------------------------------------*/
// Print transaction serialized as hex
var hexTX = tx.build().toHex();

$.post('http://btc.blockr.io/api/v1/tx/push',{"hex":hexTX},function(data){
console.log(data);
});

You just need to push it like in the example, but you should use $.Ajax instead of $.post because you iwll have more options to manage the transmission and secure it.
dannon
Member
**
Offline Offline

Activity: 70
Merit: 11


View Profile
April 14, 2017, 07:25:21 PM
Merited by ABCbits (1)
 #6

Do you need to be running that code on a server that also acts as a Bitcoin Core Node in order to broadcast the transaction? Or am I misthinking how this works? Thanks!


I suppose that you did this :

Code:
var tx = new bitcoin.TransactionBuilder()

// Add the input (who is paying):
// [previous transaction hash, index of the output to use]
var txId = 'aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31' //
tx.addInput(txId, 0)

// Add the output (who to pay to):
// [payee's address, amount in satoshis]
tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000)

// Initialize a private key using WIF
var privateKeyWIF = 'L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy'
var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF)

// Sign the first input with the new key
tx.sign(0, keyPair);

/*-------------------------------------------Look here ---------------------------------------------*/
// Print transaction serialized as hex
var hexTX = tx.build().toHex();

$.post('http://btc.blockr.io/api/v1/tx/push',{"hex":hexTX},function(data){
console.log(data);
});

You just need to push it like in the example, but you should use $.Ajax instead of $.post because you iwll have more options to manage the transmission and secure it.

You don't need jQuery. Just make an xmlhttprequest

Sad Sad Anyone else sick of trying to join signature campaigns and being denied after you have worn their signature for a week? Sad Sad
nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
April 15, 2017, 10:18:55 AM
Last edit: April 15, 2017, 11:16:20 AM by nemgun
 #7

Do you need to be running that code on a server that also acts as a Bitcoin Core Node in order to broadcast the transaction? Or am I misthinking how this works? Thanks!


I suppose that you did this :

Code:
var tx = new bitcoin.TransactionBuilder()

// Add the input (who is paying):
// [previous transaction hash, index of the output to use]
var txId = 'aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31' //
tx.addInput(txId, 0)

// Add the output (who to pay to):
// [payee's address, amount in satoshis]
tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000)

// Initialize a private key using WIF
var privateKeyWIF = 'L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy'
var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF)

// Sign the first input with the new key
tx.sign(0, keyPair);

/*-------------------------------------------Look here ---------------------------------------------*/
// Print transaction serialized as hex
var hexTX = tx.build().toHex();

$.post('http://btc.blockr.io/api/v1/tx/push',{"hex":hexTX},function(data){
console.log(data);
});

You just need to push it like in the example, but you should use $.Ajax instead of $.post because you iwll have more options to manage the transmission and secure it.

You don't need jQuery. Just make an xmlhttprequest

I said he "should" use jquery, because it is easier then using xhr, because is can be tricky, while using jQuery you can simply send Data, debug, customise the result, use promises or callbacks. While doing these using xhr will end with a 100 line of code, which is not the aim of developers i guess.
Kolder
Hero Member
*****
Offline Offline

Activity: 896
Merit: 500


View Profile
April 15, 2017, 10:24:31 AM
 #8

Anybody here can help me on installing bitcoinjs on my laptop. I'm using windows 10 OS. I succesfully installed the bitcoinjs exe file but i can't install the npm by using the command
Code:
npm install npm

I hope somebody can help me.  Undecided

nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
April 15, 2017, 10:30:27 AM
 #9

Anybody here can help me on installing bitcoinjs on my laptop. I'm using windows 10 OS. I succesfully installed the bitcoinjs exe file but i can't install the npm by using the command
Code:
npm install npm

I hope somebody can help me.  Undecided

yes, it is normall as you are asking npm to install npm, which is not really possible.
use : npm install bitcoinjs-lib

By the way, have you installed nodeJS ?
Kolder
Hero Member
*****
Offline Offline

Activity: 896
Merit: 500


View Profile
April 15, 2017, 01:13:30 PM
 #10

Anybody here can help me on installing bitcoinjs on my laptop. I'm using windows 10 OS. I succesfully installed the bitcoinjs exe file but i can't install the npm by using the command
Code:
npm install npm

I hope somebody can help me.  Undecided

yes, it is normall as you are asking npm to install npm, which is not really possible.
use : npm install bitcoinjs-lib

By the way, have you installed nodeJS ?

Yeah. I watch the tutorial on youtube regarding creating vanity address using bitcoinJS. In the tutorial. He used that code to install npm which is necessary to do your your suggested code. I saw that code on instruction on BitcoinJS but it has a $ symbol at the beginning. I try that code with $ sign at beginning but it didn't work out.

nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
April 15, 2017, 02:51:35 PM
Merited by ABCbits (2)
 #11

Anybody here can help me on installing bitcoinjs on my laptop. I'm using windows 10 OS. I succesfully installed the bitcoinjs exe file but i can't install the npm by using the command
Code:
npm install npm

I hope somebody can help me.  Undecided

yes, it is normall as you are asking npm to install npm, which is not really possible.
use : npm install bitcoinjs-lib

By the way, have you installed nodeJS ?

Yeah. I watch the tutorial on youtube regarding creating vanity address using bitcoinJS. In the tutorial. He used that code to install npm which is necessary to do your your suggested code. I saw that code on instruction on BitcoinJS but it has a $ symbol at the beginning. I try that code with $ sign at beginning but it didn't work out.

ok, so, you are new to coding.

$ is displayed in a terminal, these terminals are used bu Unix and MacOSX, so you don't have it in cmd, so i suppose you are using windows.
When you have installed nodejs, create a directory and open a cmd inside the directory.
then do
Code:
npm init
then enter the informations, next to this do
Code:
npm install --save bitcoinjs-lib jquery
create a .txt file and rename it to main.js or index.js as you specified when npm init.
Then open this file with a software like notepad2 or sublimetext, and add :
Code:
var bitcoin = require('bitcoinjs-lib');
var $ = require('jquery'); // yes, we are in 2017, it had been solved

var tx = new bitcoin.TransactionBuilder();

// Add the input (who is paying):
// [previous transaction hash, index of the output to use]
var txId = 'aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31' ;
tx.addInput(txId, 0);

// Add the output (who to pay to):
// [payee's address, amount in satoshis]
tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000);

// Initialize a private key using WIF
var privateKeyWIF = 'L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy';
var keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF);

// Sign the first input with the new key
tx.sign(0, keyPair);

/*-------------------------------------------Look here ---------------------------------------------*/
// Print transaction serialized as hex
var hexTX = tx.build().toHex();

$.post('http://btc.blockr.io/api/v1/tx/push',{"hex":hexTX},function(data){
console.log(data);
});

And you are done.
finales (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 0


View Profile
April 16, 2017, 06:19:03 PM
 #12

Is there a way to know on that same server when the transaction has been processed and added to the Blockchain? Thanks!
nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
April 17, 2017, 08:45:24 AM
 #13

Is there a way to know on that same server when the transaction has been processed and added to the Blockchain? Thanks!

It is not related to the thread, but you can get these informations using APIs from block explorers, if you want to have a live feed of transaction confirmations, or reception, you  can use blockcypher's websocket, subscribe and you will get all of these informations.
alexsamudra
Full Member
***
Offline Offline

Activity: 212
Merit: 100


View Profile
April 17, 2017, 09:05:30 AM
 #14

enough with the data that you've got it, do not need to sign the transaction.
you simply enter the data and any further instructions ikutin into the transaction
nemgun
Hero Member
*****
Offline Offline

Activity: 882
Merit: 533



View Profile WWW
April 18, 2017, 09:41:39 AM
Merited by ABCbits (1)
 #15

enough with the data that you've got it, do not need to sign the transaction.
you simply enter the data and any further instructions ikutin into the transaction

Signing a transaction is an important security measure, unsigned transactions are maleable. You should check this : https://bitcoin.org/en/developer-guide#transactions
And revise some of the informations you have about bitcoin transactions.
If you are too lazy to read the Transaction of the developper guide, maybe this post will interest you : https://bitcoin.stackexchange.com/questions/7253/signing-bitcoin-transactions
iDice_io
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile WWW
April 27, 2017, 12:44:31 AM
 #16

Do you need to be running that code on a server that also acts as a Bitcoin Core Node in order to broadcast the transaction? Or am I misthinking how this works? Thanks!
Create the transaction in BitcoinJS, which can then be broadcasted to a node (local, or not local). I believe Blockchain has a service for this.

▬▬▬▬▬▬  [CROWDSALE] [THREAD] [BETA]  ▬▬▬▬▬▬ iDice ▬▬▬▬▬▬  [BETA] [THREAD] [CROWDSALE]  ▬▬▬▬▬▬
◊                                                         CROWDSALE JUNE 16 - 30 (UTC 00:00)                                                         ◊
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ WORLD'S FIRST MOBILE GAMBLING DAPP ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Casy
Member
**
Offline Offline

Activity: 149
Merit: 22

🔴🔵 FoxMixer.com 🔵🔴


View Profile WWW
April 27, 2017, 09:06:18 AM
 #17

As you are new to coding, whatever you do, try it on the testnet first in order to prevent losing btc.

BluePoppy
Newbie
*
Offline Offline

Activity: 57
Merit: 0


View Profile
April 28, 2017, 07:36:48 AM
 #18

Do you need to be running that code on a server that also acts as a Bitcoin Core Node in order to broadcast the transaction? Or am I misthinking how this works? Thanks!
Create the transaction in BitcoinJS, which can then be broadcasted to a node (local, or not local). I believe Blockchain has a service for this.

Here's the link: https://blockchain.info/pushtx

Yup, BitcoinJS should be used here and then you can paste it manually. Or you can use Blockchain's API, which will be helpful if you're creating an application for users.
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!