The code :const alice = bitcoin.ECPair.fromPrivateKey(Buffer.from(child.__d, 'hex'))
const txb = new bitcoin.TransactionBuilder()
txb.setVersion(1);
txb.addInput('64d3df9413f527fd86181ac7877330ad2393068033ba41dd1469d489db5b0dcf', 1)
txb.addOutput('1PzSzJmdCuTbu27dYxjhWAdGcdya75vMmv', 500000)
txb.addOutput('1H3xhcX2N4GEhWdN89vktEWkkS2mjpgG7m', 6141829)
txb.sign(0, alice)
The result :0100000001cf0d5bdb89d46914dd41ba3380069323ad307387c71a1886fd27f51394dfd364010000006b483045022100f4c9f4d6b21afc4bd5d22b62a487a78d6b434d7e94aa9dfcc1a32d16f0a4032c022079739b9b9afcec6835b0d45541cb6ce6daaa2911ff7055776b23bf7fcd981f2101210201a7bf096af54f1c325a3ae306e9cfcd5d138f2630aee1182bf981a820250837ffffffff0220a10700000000001976a914fc302bb8d5a04b9dc72b4c1f5c53fe9e5484cad588ac85b75d00000000001976a914b01157358816f433c560162ffea92f29f3bc96a488ac00000000
then sendrawtransaction, Return error:
{ code: -26,
message: '16: mandatory-script-verify-flag-failed (Signature must use SIGHASH_FORKID)' }
How can I use this class library to sign transactions in abc? Thank you.
This library does not support altcoins.
However, I have a branch I use for BCH projects that is available on my Github.
There are no guarantees I will maintain it though...
https://github.com/junderw/bitcoinjs-lib/tree/cash403
You will need to do txb.enableBitcoinCash() before you do txb.sign(...) and then it should work.
Thank you very much. That's what I'm looking for.
I just rebased a new branch on 4.0.3
https://github.com/junderw/bitcoinjs-lib/tree/cash403
Hello, I'm trying to sign transactions usign cash403 branch, but I always get Script failed an OP_EQUALVERIFY operation here is the code:
import { getOnChainNetwork } from "/imports/api/coins/bitcoin/server/networks.js";
import Bitcoin from "bitcoinforksjs-lib";
import { getAddress } from "/imports/api/coins/bitcoin/server/bitcoinUtils.js";
txb = new Bitcoin.TransactionBuilder(onChainNetwork);
hdNode = Bitcoin.bip32.fromBase58(xpriv, onChainNetwork);
keyPair = hdNode.derive(0).derive(0)
spk = Bitcoin.payments.p2pk({ pubkey: keyPair.publicKey, network: onChainNetwork}).output
txb.addInput(input.txId, input.vout, Bitcoin.Transaction.DEFAULT_SEQUENCE, spk)
txb.addOutput("n2U2w2ZfAgTSTWhftjoN7j4teAp29j1r4A", 1000000)
txb.addOutput("mpPBeQBu2YeuBrABJbqRV4hAWoS7D43MZB", 8998875)
txb.enableBitcoinCash(true)
txb.sign(0, keyPair, null, Bitcoin.Transaction.SIGHASH_ALL, 10000000)
txb.build().toHex()
Thanks in advance
Are you sure it's not P2PKH?
also, I edited your formatting
three backticks then the letters js followed by a line break, then a line break followed by three backticks at the end for JS syntax highlighting
Thanks!
Do you mean? Bitcoin.payments.p2pkh({pubkey: keyPair.publicKey, network: onChainNetwork}).output ?
yea
Using p2pkh I get Signature must use SIGHASH_FORKID
enableBitcoinCash should be done right after making txb
same error with this:
txb = new Bitcoin.TransactionBuilder(onChainNetwork);
txb.enableBitcoinCash(true)
I'm using https://iancoleman.io/bip39/, bip44, coin:bitcoin testnet then xpriv is the Account Extended Private Key.
can I see your package.json for bitcoinforksjs-lib?
Oh, you need to manually add in the BCH mask yourself in addition to running enable.
const hashType = Bitcoin.Transaction.SIGHASH_ALL | Bitcoin.Transaction.SIGHASH_BITCOINCASHBIP143
oh mate!! that's it! thank you very much!
One more question, this branch can be used with BTC?
yes
I am getting the same error, I am signing transactions for another network than bitcoin. It's a coin forked from Bitcoin v0.17.0.
How can I solve this issue?