8 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
  • 2,629
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 ...
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'...
  • 13.9k
4 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 ...
  • 7,228
3 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.
  • 46
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
  • 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 ...
  • 582
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....
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 ...
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 ...
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 ...
  • 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 &...
  • 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 ...
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 ...
  • 1,336
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 ...
  • 2,388
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 ...
  • 65.7k
2 votes

How to retrieve readable private key from bitcoinjs-lib

use .toString('hex') instead. Don't export / import individual private keys when you are using BIP32 HD keys. IT IS DANGEROUS. .toString('hex') and .toString('base64') are readable string ...
  • 131
2 votes

bitcoinjs-lib is installed but cannot use its functions

You seem to be using an old version of bitcoinjs-lib. The payments interface was added in version 4.0.0 which was released in 2018. Note that the ECPair interface was removed in 6.0.0 so this code won'...
1 vote

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

There is no established standard (yet) for signatures with addresses other than P2PKH (1...) addresses. So whatever signature you created, it will only verify against the corresponding P2PKH address. ...
1 vote

How to sweep a segwit bech32 private key?

Instructions for Bitcoin Core 23.0 You will need: the private key in WIF format to know the context in which this key was used (for what type of scripts) optionally, the approximate date at which you ...
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 ...
  • 10k
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 ',...
  • 246
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 ...
  • 2,388
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' ...
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....
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-...
  • 5,076
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/...
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
  • 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 ...
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 ...
  • 7,699

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