<p>Blockcypher seems to be using custom network with some of the things changed, as they dont mention anything about WIF I recommend not using it, they only mention 2 changes the ScriptHash and the Pubkeyhash, you can use those to create a custom network object and use that for ECPair and PSBT:</p>
<pre><code>const BLOCKCYPHER = {...bitcoin.networks.testnet}; // copy to not pollute original
BLOCKCYPHER.pubKeyHash = 0x1B;
BLOCKCYPHER.scriptHash = 0x1F;
BLOCKCYPHER.wif = 73;
bitcoin.networks.bcytestnet = BLOCKCYPHER; // add back as a new bitcoin.network
</code></pre>
<p>and it is implemented as follows</p>
<pre><code>var keyPair = ECPair.fromPrivateKey(Buffer.from('9125ea9f573e23ce178d98cc2ec2a78655bd030c14b525729a026d6570b411c8', 'hex'), bitcoin.networks.bcytestnet);
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: bitcoin.networks.bcytestnet});
console.log(address); //outputs correct address: C1E96vE5GvKd5kXU4T4hhF6QioZzACrmdD
const psbt = new bitcoin.Psbt({ network: bitcoin.networks.bcytestnet });
</code></pre>

CC BY-SA 4.0
2024-01-14T01:44:05.980Z
This certainly seems like the correct approach, but still gives 'Invalid network version' when used with `fromWIF`. Making a `KeyPair` from a privateKey instead seems to work, but it works regardless of which network is supplied. So now I'm even more confused. Shouldn't either method fail since the network is not fully correct for blockcypher?
1owk3y
CC BY-SA 4.0
2024-01-15T14:56:10.120Z
Doing some reverse engineering I found that adding `BLOCKCYPHER.wif = 73` to your answer might supress the error and hopefully fill any cryptographic holes in which case I will Accept your answer. Let me do some tests to see how well the revised answer works after being integrated. Thanks for your help!
1owk3y
CC BY-SA 4.0
2024-01-15T19:47:33.353Z
@1owk3y this approach should work unless they have changed any other parameters in their blockchain. They only mention 2 of them changed at: https://www.blockcypher.com/dev/bitcoin/#testing , but they have Wif changed as well. They don't seem to share the code for their private chain as well or else we could use that to find out all of the other parameters in the Network object.
protostargg
CC BY-SA 4.0
2024-01-16T01:20:12.790Z
Honestly I'm not entirely sure if adding `wif=73` does anything at all except for supressing the warning about the wif's 'version' not being expected... but after testing it looks like it stops enough warnings to let signings and keypair generation start happening and the transactions do indeed get processed by BlockCypher's blockchain correctly. Thanks again!
1owk3y
CC BY-SA 4.0
2024-01-13T19:35:52.060Z
2024-01-16T14:59:57.777Z
2024-01-16T14:59:57.777Z
protostargg
<p>Trying to make a PSBT via BitcoinJS-lib.</p>
<p><em>I'm using BlockCypher's internal testnet (bcy/test) because I have no choice: literally every other testnet faucet I tested was broken.</em></p>
<p>Using <a href="https://www.blockcypher.com/dev/bitcoin/#testing" rel="nofollow noreferrer">BlockCypher's API</a> to make new addresses, they give you an <code>address</code>, <code>private</code>, <code>public</code> and <code>wif</code></p>
<p><em>(their documentation doesn't mention the <code>wif</code>, but it does indeed give one...)</em></p>
<p>Here's an example response</p>
<pre><code>{
  &quot;private&quot;: &quot;9125ea9f573e23ce178d98cc2ec2a78655bd030c14b525729a026d6570b411c8&quot;,
  &quot;public&quot;: &quot;03f1fbc34305c61d7638c449030c32a66eb36726c208fca9962923a98ca75d77fe&quot;,
  &quot;address&quot;: &quot;C1E96vE5GvKd5kXU4T4hhF6QioZzACrmdD&quot;,
  &quot;wif&quot;: &quot;BtCBNtS2noEXwm4rJi9nyiVbmZJMR9CEBMbF5Uz6JTSaR9EQn8jS&quot;
}
</code></pre>
<p>However none of this information is usable on it's own because the <code>sign</code> functions of BitcoinJS-lib expect a Signer (<code>KeyPair</code>) class object.. giving it a private key on it's own doesn't work.</p>
<p>i.e. <code>psbt.signInput(0, privateKey);</code> results in: <code>Error: Need Signer to sign input</code></p>
<p>I tried to make a <code>KeyPair</code> out of a WIF, but because BitcoinJS-lib lacks the <code>bitcoin.networks</code> configuration appropriate for <code>bcy/test</code> it always fails to resolve..</p>
<pre><code>ECPair.fromWIF(wif, bitcoin.networks.testnet); // Error: Invalid network version
ECPair.fromWIF(wif, bitcoin.networks.bitcoin); // Error: Invalid network version
ECPair.fromWIF(wif); // Error: Invalid network version
</code></pre>
<p>The error message suggests the WIF is not possible on those attempted networks.</p>
<p>How do I make a <code>KeyPair</code> for <code>bcy/test</code> ?</p>

<javascript><bitcoinjs><bip174-psbt><wallet-import-format><blockcypher>
How to use BlockCypher's test network with BitcoinJS-lib?
1owk3y
# How to use BlockCypher's test network with BitcoinJS-lib?

(Asked by: username_0 on 2024-01-13)

Trying to make a PSBT via BitcoinJS-lib.

*I'm using BlockCypher's internal testnet (bcy/test) because I have no choice: literally every other testnet faucet I tested was broken.*

Using [BlockCypher's API](https://www.blockcypher.com/dev/bitcoin/#testing) to make new addresses, they give you an `address`, `private`, `public` and `wif`

*(their documentation doesn't mention the `wif`, but it does indeed give one...)*

Here's an example response

```
{
  "private": "9125ea9f573e23ce178d98cc2ec2a78655bd030c14b525729a026d6570b411c8",
  "public": "03f1fbc34305c61d7638c449030c32a66eb36726c208fca9962923a98ca75d77fe",
  "address": "C1E96vE5GvKd5kXU4T4hhF6QioZzACrmdD",
  "wif": "BtCBNtS2noEXwm4rJi9nyiVbmZJMR9CEBMbF5Uz6JTSaR9EQn8jS"
}

```

However none of this information is usable on it's own because the `sign` functions of BitcoinJS-lib expect a Signer (`KeyPair`) class object.. giving it a private key on it's own doesn't work.

i.e. `psbt.signInput(0, privateKey);` results in: `Error: Need Signer to sign input`

I tried to make a `KeyPair` out of a WIF, but because BitcoinJS-lib lacks the `bitcoin.networks` configuration appropriate for `bcy/test` it always fails to resolve..

```
ECPair.fromWIF(wif, bitcoin.networks.testnet); // Error: Invalid network version
ECPair.fromWIF(wif, bitcoin.networks.bitcoin); // Error: Invalid network version
ECPair.fromWIF(wif); // Error: Invalid network version

```

The error message suggests the WIF is not possible on those attempted networks.

How do I make a `KeyPair` for `bcy/test` ?

**Tags:** javascript, bitcoinjs, bip174-psbt, wallet-import-format, blockcypher


---

## 1 answers

### Answer by username_1 on 2024-01-13. Score: 1 | Accepted answer

Blockcypher seems to be using custom network with some of the things changed, as they dont mention anything about WIF I recommend not using it, they only mention 2 changes the ScriptHash and the Pubkeyhash, you can use those to create a custom network object and use that for ECPair and PSBT:

```
const BLOCKCYPHER = {...bitcoin.networks.testnet}; // copy to not pollute original
BLOCKCYPHER.pubKeyHash = 0x1B;
BLOCKCYPHER.scriptHash = 0x1F;
BLOCKCYPHER.wif = 73;
bitcoin.networks.bcytestnet = BLOCKCYPHER; // add back as a new bitcoin.network

```

and it is implemented as follows

```
var keyPair = ECPair.fromPrivateKey(Buffer.from('9125ea9f573e23ce178d98cc2ec2a78655bd030c14b525729a026d6570b411c8', 'hex'), bitcoin.networks.bcytestnet);
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey, network: bitcoin.networks.bcytestnet});
console.log(address); //outputs correct address: C1E96vE5GvKd5kXU4T4hhF6QioZzACrmdD
const psbt = new bitcoin.Psbt({ network: bitcoin.networks.bcytestnet });

```

> **Comments:**
> **username_0**: This certainly seems like the correct approach, but still gives 'Invalid network version' when used with `fromWIF`. Making a `KeyPair` from a privateKey instead seems to work, but it works regardless of which network is supplied. So now I'm even more confused. Shouldn't either method fail since the network is not fully correct for blockcypher?  
> **username_0**: Doing some reverse engineering I found that adding `BLOCKCYPHER.wif = 73` to your answer might supress the error and hopefully fill any cryptographic holes in which case I will Accept your answer. Let me do some tests to see how well the revised answer works after being integrated. Thanks for your help!  
> **username_1**: @username_0 this approach should work unless they have changed any other parameters in their blockchain. They only mention 2 of them changed at: https://www.blockcypher.com/dev/bitcoin/#testing , but they have Wif changed as well. They don't seem to share the code for their private chain as well or else we could use that to find out all of the other parameters in the Network object.  
> **username_0**: Honestly I'm not entirely sure if adding `wif=73` does anything at all except for supressing the warning about the wif's 'version' not being expected... but after testing it looks like it stops enough warnings to let signings and keypair generation start happening and the transactions do indeed get processed by BlockCypher's blockchain correctly. Thanks again!  

---

