6

I was trying to use the bitcoinjs-lib (1) with my regtest network. More specifically I was trying to build a tx with TransactionBuilder but it gave me a 'transaction has no matching Script' exception.

In a closed github issue (2) I find out that it's possible to specify the network (network.testnet), but I can't find any documentation related to regtest. I just want to create and broadcast a raw tx created with bitcoinjs to my regtest network.

So, has anyone talked to a regtest network with bitcoinjs-lib successfully? If not, what other libs would you recommend for the satoshi client? Thanks.

(1) https://github.com/bitcoinjs/bitcoinjs-lib

(2) https://github.com/bitcoinjs/bitcoinjs-lib/issues/500

joe.js
  • 582
  • 3
  • 14

1 Answers1

3

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 went into a npm package that added dogecoin and litecoin testnets compatibility with bitcoinjs-lib (it's called bitcoinjs-testnets).

But the solution in the second Github link that I posted works.

Here I repost the text:

Just want to give some feedback that may help new users in the future. I lost a lot of time debugging an issue that is probably extremely obvious to some, but it was not directly obvious to me.

var bitcoin = require("bitcoinjs-lib");
var keyPair = bitcoin.ECPair.fromWIF("mywif", bitcoin.networks.testnet);
var txb = new bitcoin.TransactionBuilder(); txb.addOutput("myaddress", satoshis);  // <---- this will fail with "has no matching Script"

Because of the error message I came to the conclusion that I was doing something fundamentally wrong creating the transaction. In the end, it turns out I just needed

var txb = new bitcoin.TransactionBuilder(bitcoin.networks.testnet);

Feel free to close this, just wanted to share my experience

I wish my noob experience has helped you! (pardon for my english).

Shabahat M. Ayubi
  • 1,479
  • 10
  • 25
joe.js
  • 582
  • 3
  • 14