You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a raw transaction for bch testnet. But when sending it, I get this error: mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation) (code 16). I run out of ideas and I don't which part I'm doing wrong.
This is my code:
val creationtime = System.currentTimeMillis() / 1000
val network = TestNet3Params.get()
val path = HDPath.M(ChildNumber(44, true))
.extend(
ChildNumber(145, true),
ChildNumber.ZERO_HARDENED,
ChildNumber.ZERO,
ChildNumber.ZERO
)
val seed = DeterministicSeed(seedCode, null, passphrase, creationtime)
val wallet = Wallet.fromSeed(
network,
seed,
Script.ScriptType.P2PKH,
path
) // this is a test wallet to see if it will work
val privateKey = wallet.watchingKey.privateKeyAsHex
val fromAddress = "bchtest:qrxqjk7d7f4kqzvjqux0g2qwr42kzfwjcs7plfytvm"
val toAddress = "bchtest:qzqxaef45wvwxqq38r6h7d2q2kgxa90a25aghw98ua"
val prevTxHash = "e2d06c0b446d9bfe4b91e000fd6451b48643e2d74c9023b5fa9d5344092bcf12"
val outputAmount = "0.02".toSatoshi()
val feeAmountInLong = "0.00000300".toSatoshi()
val fromAddr = AddressFactory.create().getAddress(network, fromAddress)
val toAddr = AddressFactory.create().getAddress(network, toAddress)
val tx = Transaction(network)
val value1 = "0.10".toSatoshi()
val changeAmountInLong = (value1) - outputAmount.toLong() - feeAmountInLong
val transactionOutpoint1 = TransactionOutPoint(network, 0, Sha256Hash.wrap(prevTxHash)) //prevTransaction
val scriptBytes1 = HEX.decode("76a914cc095bcdf26b600992070cf4280e1d556125d2c488ac")
val txInput1 = TransactionInput(network, tx, scriptBytes1 ,transactionOutpoint1, Coin.valueOf(value1))
tx.addInput(txInput1)
tx.addOutput(Coin.valueOf(outputAmountInLong), toAddr)
tx.addOutput(Coin.valueOf(changeAmountInLong), fromAddr)
val scriptPubKey = ScriptBuilder.createOutputScript(fromAddr)
val hashForSignature: Sha256Hash = tx.hashForSignature(0, scriptPubKey, SigHash.ALL, false)
val ecKey: ECKey = ECKey.fromPrivate(HEX.decode(privateKey))
val ecSig = ecKey.sign(hashForSignature)
val txSig = TransactionSignature(ecSig, SigHash.ALL, false, true)
txInput1.scriptSig = ScriptBuilder.createInputScript(txSig, ecKey);`
I figured out my fromAddress was wrong and was not the same as the one that my seed produced and that was the reason I faced that error. But now that I fixed it I run into another error:
mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)
this is my raw transaction: 0100000001766d266bc5b02fbc28074fc0c356cf136ea765287b627e728491fe746d33c4a9000000006b483045022100da0fe5666274051a9667d458e87c60c2805860747fb94ccf42f9be4e95a4b69e02207feec061f42b2f9148277b298681b2eddfec81f3531080d79ddd6c63521f2ff44121032a5ca9f5391712e636ed2ebc62fc5801eff1c666d9db35f3957b191eebddfc77ffffffff0280841e00000000001976a914806ee535a398e3001138f57f354055906e95fd5588ac70237b00000000001976a9146f8227901f4b2ba31c53449a6b68737d5180a07388ac00000000
Is there anything wrong with my code in creating script? Any help would be greatly appreciated.
I'm trying to create a raw transaction for bch testnet. But when sending it, I get this error: mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation) (code 16). I run out of ideas and I don't which part I'm doing wrong.
This is my code:
I'd appreciate your help @pokkst
The text was updated successfully, but these errors were encountered: