Author

Topic: bitcoinjs-lib without node.js (Read 185 times)

legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
November 25, 2023, 04:55:57 AM
#9
You can do that by open "Help" -> "Setting" or visit https://coinb.in/#settings and choose "Bitcoin (Testnet)" on Network option.

Not working at all, now trying another one: mm7BAhJKvL9FrAim1gCYoM3WJHGYYfcXLV

The address or redeem script you have entered is invalid

Is testnet working to you on coinb.in?

Yes, it's working for me. I set to "Bitcoin Testnet", then visit https://coinb.in/#newTransaction and fill using these data,

Input 1:
Transaction ID: 3e5576ceb27ad9a2b840503cb038b7a9817d89446cbe821f48343b73a4ecebad
N: 1
Script: 00148c2fa48a2fcffbb962b400ac5a9a1b11bc1f5e49
Amount: 0.00897859

Output 1:
Address: mm7BAhJKvL9FrAim1gCYoM3WJHGYYfcXLV
Amount: 0.0089

The result (unsigned TX):
Code:
0100000001adebeca4733b34481f82be6c44897d81a9b738b03c5040b8a2d97ab2ce76553e010000001600148c2fa48a2fcffbb962b400ac5a9a1b11bc1f5e49fdffffff0190940d00000000001976a9143d51847f5c49fdc2dc1792a5414481358405b69f88ac00000000

Screenshot:


legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
November 24, 2023, 04:48:13 AM
#7
ETFbitcoin, coinb.in is according to my goal: prepare an off-line Tx. However, a testnet addr is not accepted:
"The address or redeem script you have entered is invalid". That´s the message. My addr is fine and funded:

muKdpCX1tGhaREkY9foqSkPCCQqXbXB6QQ, but is not accepted, even after selecting bitcoin testnet at setting page. Any sugestion? I wanna test the wallet with fake btc before entering real money addr/key in mainnet.

Thank you all.

You can do that by open "Help" -> "Setting" or visit https://coinb.in/#settings and choose "Bitcoin (Testnet)" on Network option.
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
December 02, 2023, 03:48:31 AM
#7
ETFbitcoin, what did you exactly put in the first field of the tx, labeled
 Address, WIF key, Redeem Script or Transaction ID:, an address, a script, a TxID or a key?  I enter my address and it´s not accepted, and my goal is to use my address, if possible.

Actually i didn't enter any value on first field. I haven't personally test it, but you should copy unsigned TX which created by https://coinb.in/#newTransaction and visit https://coinb.in/#sign to sign it with your private key.
newbie
Activity: 4
Merit: 0
December 01, 2023, 09:27:27 AM
#6
ETFbitcoin, what did you exactly put in the first field of the tx, labeled
 Address, WIF key, Redeem Script or Transaction ID:, an address, a script, a TxID or a key?  I enter my address and it´s not accepted, and my goal is to use my address, if possible.
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
November 23, 2023, 05:55:13 AM
#5
Prepairing/Building a btc transaction in JS with "bitcoinjs-lib" takes a few more steps than generating a new public address/private key.
This include following steps: Create a new transaction, add in- and outputs, sign the transaction and build it to get the raw transaction hex to be able to broadcast the transaction.

First obvious step is to install the library.

--snip--

You forget one important thing asked by OP, which is how to run it without node/js where he imply he wants to run it only with browser. For example, you mention to install the library, but you never provide guide how to do it if OP use browser.
newbie
Activity: 4
Merit: 0
November 24, 2023, 11:56:17 AM
#5
You can do that by open "Help" -> "Setting" or visit https://coinb.in/#settings and choose "Bitcoin (Testnet)" on Network option.

Not working at all, now trying another one: mm7BAhJKvL9FrAim1gCYoM3WJHGYYfcXLV

The address or redeem script you have entered is invalid

Is testnet working to you on coinb.in?
newbie
Activity: 4
Merit: 0
November 23, 2023, 11:38:23 AM
#4
Thank you, guys, all answers add priceless info to my knowlege. Now, some details:

I´m cuban, so my connection is not the best to npm libraries; it takes too long. Is there a way to npm my already dowloaded lib instead?

Now some other considerations: if bitcoinjs-min.js can be used in an off-node manner, why not the same principle to build a Tx with same lib? Any special reason?

No matter whether bitcoinjs-lib.js or -min.js, as stated by me before, no matter if more -libs are needed, the matter is to manage a .js lib like any other .js file, just from the browser. If not possible, a reason could be indicated.

I´m aware that more steps are needed, of course, but the function to create a new public address/private key is in the same lib containing functions to build a transaction. No matter how many steps, npm installation doesn´t add functions to the library, and this is a .js file, not a special one that can only be read by node.js, I guess.

Hope you understand my concern.

ETFbitcoin, coinb.in is according to my goal: prepare an off-line Tx. However, a testnet addr is not accepted:
"The address or redeem script you have entered is invalid". That´s the message. My addr is fine and funded:

muKdpCX1tGhaREkY9foqSkPCCQqXbXB6QQ, but is not accepted, even after selecting bitcoin testnet at setting page. Any sugestion? I wanna test the wallet with fake btc before entering real money addr/key in mainnet.

Thank you all.
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
November 22, 2023, 05:15:51 AM
#3
@vv181 already provide good answer. But depending on your goal, you might want to use https://coinb.in/ instead. It's open source where you can run it locally on offline device. You can use https://coinb.in/#newTransaction to create the TX manually.
legendary
Activity: 1316
Merit: 2018
November 22, 2023, 07:32:43 AM
#3
Prepairing/Building a btc transaction in JS with "bitcoinjs-lib" takes a few more steps than generating a new public address/private key.
This include following steps: Create a new transaction, add in- and outputs, sign the transaction and build it to get the raw transaction hex to be able to broadcast the transaction.

First obvious step is to install the library.

Now import the library and setup the network configuration for the transaction:
Code:
const bitcoin = require('bitcoinjs-lib');
const network = bitcoin.networks.bitcoin;
If you want to use the testnet replace it with "bitcoin.networks.testnet"

Next step is to setup the variables of the sender adresses. You will need the private key in WIF-format to be able to sign the transaction later:
Code:
const privateKeyWIF = 'insert_privkey_here';
const keyPair = bitcoin.ECPair.fromWIF(privateKeyWIF, network);

Add the transaction ID and the output index of the UTXO you want to spend:
Code:
const txId = 'insert_txId_here';
const vout = 0;

Define the receiving address, the amount and the fee that you are using for the transaction:
Code:
const recipientAddress = 'insert_address_here';
const amountToSend = insert_amount_in_satoshi_here;
const fee = insert_fee_amount_in_satoshi_here;

We can finally build ur transaction by adding the input and output:
Code:
const txBuilder = new bitcoin.TransactionBuilder(network);

txBuilder.addInput(txId, vout);
txBuilder.addOutput(recipientAddress, amountToSend);

Now sign the transaction with the private key that we set up in the first step:
Code:
txBuilder.sign(0, keyPair);

Lets finish and compile it to get raw transaction hex:
Code:
const rawTx = txBuilder.build().toHex();

console.log("Raw Transaction Hex: ", rawTx);

With the output you are finally able to broadcast your transaction to the network. There are a few services that offer to push ur transaction by using the raw transaction hex.
One example would be Blockstream - just enter the raw transaction hex and the transaction will be broadcasted.  Wink
legendary
Activity: 1932
Merit: 1273
November 21, 2023, 09:13:59 PM
#2
You need to compile it first using node or reuse any available compiled code of the library, although I won't recommend that.

For the compilation process guide refer to: https://github.com/bitcoinjs/bitcoinjs-lib#browser
Code:
$ npm install bitcoinjs-lib browserify
$ npx browserify --standalone bitcoin - -o bitcoinjs-lib.js <<<"module.exports = require('bitcoinjs-lib');"

After it is compiled, you can call the library as a JavaScript module, and then do the transaction parts plainly in JS. I don't know if it already exists, but you can see the currently available examples for guidance: https://github.com/bitcoinjs/bitcoinjs-lib/tree/master#examples.
newbie
Activity: 4
Merit: 0
November 21, 2023, 10:07:02 AM
#1
Hello. This link leads to a solution posted by someguy123 with bitcoin-min.js to generate public addr/private key, just with 3 lines of code:
https://bitcointalksearch.org/topic/m.9974990

The method is:

First, for the head in html document:

Code:


Then the function to call is:

Code:
var key = Bitcoin.ECKey.makeRandom();
var PubKey = key.pub.getAddress().toString();
var PrivKey = key.toWIF();

And that's it. An elegant, "nodeless" solution.

My issue is this: How to use such a simple method, but for building a btc transaction instead? You know, a nodeless method, just a dir with bitcoinjs-lib inside (or -min, whatever) and pure javascript to call the corresponding functions.

Thank you in advance.
Jump to: