10 votes

Create OP_RETURN tx with Bitcoinjs-lib

Here: var bitcoin = require('bitcoinjs-lib') data = new Buffer("Melons.") var tx = new bitcoin.TransactionBuilder() tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31", 0)...
user avatar
  • 28.8k
7 votes
Accepted

How to sweep a segwit bech32 private key?

Use Electrum 3.1.1 and prepend "p2wpkh:" to the private key before importing or sweeping it. For example: p2wpkh:5Kkzs8XrJNAmf9VQDFeGBfaRvSByAvPK6DbDXw5BVqswWaXSG2Y
user avatar
  • 2,560
7 votes
Accepted

How do you validate a bitcoin address using bitcoinjs library in javascript?

If you call bitcoin.address.toOutputScript(address, bitcoin.networks.bitcoin) It will throw an error if the address cannot be parsed as P2SH or P2PKH, or if the checksum is not valid. Replace the ...
user avatar
  • 28.8k
4 votes
Accepted

Do all implementation of Deterministic RFC6979-compliant ECDSA signatures generate the same signed transaction given the same data?

So if I were to create the same transaction using bitcoinjs and bitcoinj, the end result of the signed transaction would be the same with both libraries, is that correct? They certainly should. That'...
user avatar
  • 13.7k
3 votes
Accepted

Creating an OP_CSV transaction with bitcoinjs

In bitcoin-js you could do something like this aliceToBobRedeemScript = bitcoin.script.compile([, bitcoin.opcodes.OP_IF, bitcoin.opcodes.OP_HASH160, aliceSecretHash, bitcoin.opcodes....
user avatar
3 votes
Accepted

How to push a raw transaction using BitcoinJS (and Request)?

Body must be a string. You can use form instead of body. Reference: https://www.npmjs.com/package/request#forms
user avatar
  • 46
3 votes

How to use bitcoinjs-lib with Regtest?

Oops! Noob mistake. I thought that testnet and regtest had different version prefixes (not compatible) but they are (the bitcoin wiki and bitcoin developers page doesn't clarify this, though). So I ...
user avatar
  • 572
3 votes

How do you broadcast a transaction programatically?

You should not use an online service for broadcasting transaction. This online-service would have full control (censor?) over your transaction. The service could analyze your data behavior and/or ...
user avatar
3 votes
Accepted

How to get xpriv and xpub from keyPair with bitcoinjs-lib

The short answer is: you probably shouldn't. That is not a typical way to generate an xpriv/xpub. You are trying to convert a key pair to an extended key pair. The difference is the extended keys ...
user avatar
  • 7,090
3 votes

How to read the balance on a wallet address

To get a balance of the address you need a view of the blockchain's current utxo set. This is typically done by syncing a node. I don't believe bitcoinjs has the capability to be a node (nor it is ...
user avatar
2 votes
Accepted

Why am I unable to post two transactions (the second from the change address of the first) in the same block?

I think my issue was that I was accidentally trying to spend the output from my first transaction (which had insufficient funds for both the given fee and the given amount of change) instead of the ...
user avatar
  • 89
2 votes
Accepted

OP_EQUALVERIFY Problem

So... I found out what was wrong. The problem was in this part of the code when i was adding the inputs. I was adding an index to each input based on which number of input it was. for(var a = 0; a &...
user avatar
  • 93
2 votes

Specifying fee amount using bitcoinjs

The fee is the sum of unspent value in a Transaction. Aka the value NOT SENT by your outputs. fee = in - out For an example, if we assume the input ...
user avatar
2 votes
Accepted

How to decode transaction inputs from raw data using bitcoinjs-lib?

You will, by default, only see the values of the outputs and not the inputs. To gather all values for inputs, you will need to loop through your inputs and use an API to gather the transactions where ...
user avatar
  • 1,281
2 votes
Accepted

Understanding signing messages with bitcoinjs-lib

That particular line of code asserts that the private key fits into a 32 byte-sized byte array properly with the necessary zero paddings. As the private key is simply some random Big Integer between 0 ...
user avatar
  • 2,378
2 votes
Accepted

Using BitcoinJS - How do you verify a message using a segwit bech32 (bc1…) / P2SH (3…) addresses?

A Trezor signed message with a 3 address can be verified here: https://jhoenicke.github.io/brainwallet.github.io/#verify Or your can verify it with another Trezor wallet.
user avatar
  • 36
2 votes
Accepted

Can't generate same addresses as bitcoincore using xprv from bitcoin-core

looks like address from dump is multisig? It is not multisig. Bitcoin Core does not generate multisig addresses. That address is a P2SH wrapped Segwit address. The same private key can be associated ...
user avatar
  • 62.5k
1 vote
Accepted

Where does the entropy of BitcoinJS' makeRandom() come from?

This code calls this code, which calls crypto.getRandomValues, which is a trustworthy cryptographically secure random number generator. It's secure enough to compete with bitaddress.org, as long as ...
user avatar
  • 9,849
1 vote
Accepted

ScriptHash from bitcoin address with BitcoinJS

Got the answer via github let script = bitcoin.address.toOutputScript(address) let hash = bitcoin.crypto.sha256(script) let reversedHash = new Buffer(hash.reverse()) console.log(address, ' maps to ',...
user avatar
  • 246
1 vote

Creating an OP_CSV transaction with bitcoinjs

following the link https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki: 1.) the timeDelay in your example represents two possibilities: // There are two kinds of nSequence: lock-by-...
user avatar
  • 5,026
1 vote

HD wallet implementation

I'm doing something similar but using segwit addresses (BIP49). If you are using BIP32 with a standard derivation of m/0'/0/0 you could do something like this - See: https://github.com/bitcoinjs/...
user avatar
1 vote

How to decode transaction inputs from raw data using bitcoinjs-lib?

How should I process this data so I can get total in and out amounts and calculate transaction fee? Each in contains a (hash, index) to a previous output in the blockchain. Assuming you have a full ...
user avatar
  • 2,378
1 vote
Accepted

How BitcoinJS sync bitcoin blockchain/transaction data?

BitcoinJS does not link directly to the bitcoin network, it is simply a collection of bitcoin-related functions. Taking your example above, if we wanted to create a transaction with BitcoinJS' ...
user avatar
1 vote

Creating an OP_CSV transaction with bitcoinjs

To answer the question: What does the timeDelay value represent? How can I e.g. lock the funds for 2 blocks? Please see the following example using bitcoinjs: let bip68 = require('bip68') bip68....
user avatar
1 vote

How to create a deterministic wallet using bitcoinjs-lib

See Blockchain.info wallet source code https://github.com/blockchain/My-Wallet-V3 Also check the bitcoinjs-lib's list of projects
user avatar
  • 119
1 vote

How to convert a keyPair to JSON and back?

Wallet Import Format can be used in a Javascript String, which is JSON compatible. For bitcoinjs-lib@^2.0.0: var prv = keyPair.toWIF() To recover, use bitcoin.ECPair.fromWIF(prv) Caution: if ...
user avatar
1 vote
Accepted

How to develop an ownership tracking service based on bitcoin blockchain

There are a lot of different projects that are looking to solve this problem. Almost all of them use something like colored coins to track an asset on the blockchain. Essentially, what your plan is ...
user avatar
  • 7,639
1 vote

Which language has better Bitcoin API experience, C# or Node.js?

API selection with other technology selection is having major dependencies on final goal. so you have to select the best suit of technology as per the business requirement.
user avatar
  • 41
1 vote

How do you broadcast a transaction programatically?

I found what I was looking for. Blockr.io has a good service for publishing transactions to the network. This is the url that you would send a post request to http://btc.blockr.io/api/v1/tx/push Make ...
user avatar
1 vote

Error pushing hex of tx, generated with bitcoinjs 1.0, on testnet

Everything is fine with your tx. Here it is: http://test.webbtc.com/tx/034dfa392aa7ea46bc0917cdaa2794a5f03e6f935b6518a103cb0f5e923a05be I've pushed it to the network with this form: http://test....
user avatar
  • 6,650

Only top scored, non community-wiki answers of a minimum length are eligible