Thursday, February 6, 2025
HomeBitcoinjavascript - bitcoinjs - mandatory-script-verify-flag-failed (Signature have to be zero for failed...

javascript – bitcoinjs – mandatory-script-verify-flag-failed (Signature have to be zero for failed CHECK(MULTI)SIG operation)


enter image description here

I am attempting to comply with the beneath transaction instance by magic eden and lengthen it to assist a number of patrons and vendor (in crimson). Nevertheless I’m having difficulties once I add a couple of signature from one other social gathering (with one vendor it broadcasts okay). The transaction builds and indicators tremendous however when I attempt to broadcast it to the community it ends in the error mandatory-script-verify-flag-failed (Signature have to be zero for failed CHECK(MULTI)SIG operation). Utilizing native segwit addresses for this (no-tr).

What am I lacking or doing improper?

Utilizing the bitcoinjs library here’s what I’ve thus far (solely the crimson):

Vendor signing:

let psbt = new bitcoin.Psbt({ community });

const [ordinalUtxoTxId, ordinalUtxoVout] = ordinalOutput.break up(":");
const tx = bitcoin.Transaction.fromHex(await getTxHexById(ordinalUtxoTxId));

strive {
    tx.setWitness(parseInt(ordinalUtxoVout), []);
} catch {}

const enter = 
    bitcoin.Transaction.SIGHASH_ANYONECANPAY,
;

psbt.addInput(enter);

psbt.addOutput({
  deal with: paymentAddress,
  worth: value,
});

Purchaser Signing (ignoring padding inputs and outputs):

// Add inscriptions inputs and outputs
for (const signedPsbt of sellerSignedPsbts) {
    // Add inscription output
    psbt.addOutput({
        deal with: receiverAddress,
        worth: signedPsbt.information.inputs[0].witnessUtxo.worth,
    });

    // Add payer signed enter
    psbt.addInput({
        ...signedPsbt.information.globalMap.unsignedTx.tx.ins[0],
        // ...signedPsbt.information.inputs[0],
        witnessUtxo: signedPsbt.information.inputs[0].witnessUtxo,
        nonWitnessUtxo: signedPsbt.information.inputs[0].nonWitnessUtxo,
        // finalScriptWitness: signedPsbt.information.inputs[0].finalScriptWitness,
    });

    enter++;
}

// Add vendor cost outputs for payee
for (const signedPsbt of sellerSignedPsbts) {
    // Add payer output
    psbt.addOutput({
        ...signedPsbt.information.globalMap.unsignedTx.tx.outs[0],
    });
}

Merge vendor and purchaser signed psbts:

const buyerSignedPsbt = bitcoin.Psbt.fromBase64(signedBuyingPSBTBase64);

for (let index = 0; index < signedListingsPSBTBase64.size; index++) {
    const sellerSignedPsbt = bitcoin.Psbt.fromBase64(signedListingsPSBTBase64[index]);

    buyerSignedPsbt.information.globalMap.unsignedTx.tx.ins[BUYING_PSBT_SELLER_SIGNATURE_INDEX + index] = sellerSignedPsbt.information.globalMap.unsignedTx.tx.ins[0];
    buyerSignedPsbt.information.inputs[BUYING_PSBT_SELLER_SIGNATURE_INDEX + index] = sellerSignedPsbt.information.inputs[0];
}

// broadcast buyerSignedPsbt

RELATED ARTICLES

Most Popular

Recent Comments