Author

Topic: Create a transaction with BitcoinJS (Read 2504 times)

newbie
Activity: 57
Merit: 0
April 28, 2017, 02: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.
member
Activity: 149
Merit: 22
🔴🔵 FoxMixer.com 🔵🔴
April 27, 2017, 04: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.
member
Activity: 84
Merit: 10
April 26, 2017, 07:44:31 PM
#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.
hero member
Activity: 882
Merit: 533
April 18, 2017, 04:41:39 AM
#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
full member
Activity: 212
Merit: 100
April 17, 2017, 04: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
hero member
Activity: 882
Merit: 533
April 17, 2017, 03: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.
newbie
Activity: 13
Merit: 0
April 16, 2017, 01: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!
hero member
Activity: 882
Merit: 533
April 15, 2017, 09:51:35 AM
#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.
hero member
Activity: 896
Merit: 500
April 15, 2017, 08:13:30 AM
#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.
hero member
Activity: 882
Merit: 533
April 15, 2017, 05: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 ?
hero member
Activity: 896
Merit: 500
April 15, 2017, 05: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
hero member
Activity: 882
Merit: 533
April 15, 2017, 05:18:55 AM
#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.
member
Activity: 70
Merit: 11
April 14, 2017, 02:25:21 PM
#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
hero member
Activity: 882
Merit: 533
April 12, 2017, 07:31:29 AM
#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.
member
Activity: 70
Merit: 11
April 12, 2017, 06:04:52 AM
#4
What data are you referring to? Thanks

Blockchain data. Information about previous transactions.
newbie
Activity: 13
Merit: 0
April 11, 2017, 01:45:58 PM
#3
What data are you referring to? Thanks
member
Activity: 70
Merit: 11
April 10, 2017, 07:03:02 AM
#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.
newbie
Activity: 13
Merit: 0
April 06, 2017, 12: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!
Jump to: