• About
  • FAQ
  • Privacy Policy
  • Support Forum
  • Disclaimer
  • Contact Us
Newsletter
Token Alytics
  • Home
  • Bitcoin
  • Blockchain
  • Cryptocurrency
  • Defi
  • Ripple
  • Ethereum
  • Metaverse
No Result
View All Result
  • Home
  • Bitcoin
  • Blockchain
  • Cryptocurrency
  • Defi
  • Ripple
  • Ethereum
  • Metaverse
No Result
View All Result
Token Alytics
No Result
View All Result
Home Bitcoin

segregated witness – Signing a Bitcoin SegWit transaction utilizing Bitcoinj

thecryptogoblin by thecryptogoblin
November 29, 2024
in Bitcoin
0
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


I’m engaged on a SegWit Bitcoin transaction, and I am encountering an error when attempting to broadcast it:

Code: -26, Error: mandatory-script-verify-flag-failed (Signature should
be zero for failed CHECK(MULTI)SIG operation)

Right here’s the code I’m utilizing to signal the transaction:

personal static void signInputsOfTransaction(Handle sourceAddress, Transaction tx, ECKey key) {
    for (int i = 0; i < tx.getInputs().dimension(); i++) {
        Script scriptPubKey = ScriptBuilder.createP2WPKHOutputScript(key);

        Coin inputValue = tx.getInput(i).getValue();

        Sha256Hash hash = tx.hashForWitnessSignature(
            i, scriptPubKey, inputValue, Transaction.SigHash.ALL, false
        );

        ECKey.ECDSASignature ecdsaSignature = key.signal(hash);
        TransactionSignature txSignature = new TransactionSignature(ecdsaSignature, Transaction.SigHash.ALL, false);

        TransactionWitness witness = new TransactionWitness(2);
        witness.setPush(0, txSignature.encodeToBitcoin());
        witness.setPush(1, key.getPubKey());
        tx.getInput(i).setWitness(witness);

        tx.getInput(i).setScriptSig(ScriptBuilder.createEmpty());
    }
}

Right here’s the uncooked transaction hex I’m attempting to broadcast:

010000000001011a34c12133e07aceb6b0cd254e2d9e12fde095b5a3afece4907945e36254e0d40100000000ffffffff02e803000000000000160014c9bf27c413655f5894a6a095ccfb5f1d291123f185170000000000001600146edda921d055dece3a894e39fd91a0c50faf675c02473044022000e9341c7c137529db50f706bc2bc1c1057674cda3bc33be5c559a45731b9c2802201a0f435a70e0f3a89d272efa407e0817e964f4c14ee9f9e3e4b5961fa658fc1d01210336069ac77986a9de47f0c371b682906149e43c2f51853b30d31132d1ec33b76900000000

I’ve decoded it utilizing a Bitcoin transaction API (BlockCypher), and right here’s the output:

{
    "outputs": [
        {
            "addresses": ["bc1qexlj03qnv404399x5z2ue76lr553zgl3kfx7va"],
            "script_type": "pay-to-witness-pubkey-hash",
            "worth": 1000,
            "script": "0014c9bf27c413655f5894a6a095ccfb5f1d291123f1"
        },
        {
            "addresses": ["bc1qdmw6jgws2h0vuw5ffculmydqc5867e6ulzzm97"],
            "script_type": "pay-to-witness-pubkey-hash",
            "worth": 6021,
            "script": "00146edda921d055dece3a894e39fd91a0c50faf675c"
        }
    ],
    "addresses": [
        "bc1qdmw6jgws2h0vuw5ffculmydqc5867e6ulzzm97",
        "bc1qexlj03qnv404399x5z2ue76lr553zgl3kfx7va"
    ],
    "charges": 1130,
    "ver": 1,
    "vsize": 141,
    "inputs": [{
        "sequence": 4294967295,
        "witness": [
            "3044022000e9341c7c137529db50f706bc2bc1c1057674cda3bc33be5c559a45731b9c2802201a0f435a70e0f3a89d272efa407e0817e964f4c14ee9f9e3e4b5961fa658fc1d01",
            "0336069ac77986a9de47f0c371b682906149e43c2f51853b30d31132d1ec33b769"
        ],
        "addresses": ["bc1qdmw6jgws2h0vuw5ffculmydqc5867e6ulzzm97"],
        "prev_hash": "d4e05462e3457990e4ecafa3b595e0fd129e2d4e25cdb0b6ce7ae03321c1341a",
        "output_value": 8151,
        "script_type": "pay-to-witness-pubkey-hash",
        "output_index": 1,
        "age": 698646
    }],
    "desire": "low",
    "acquired": "2024-11-28T15:26:00.690177102Z",
    "block_height": -1,
    "confirmations": 0,
    "relayed_by": "189.37.69.88",
    "complete": 7021,
    "dimension": 222,
    "block_index": -1,
    "double_spend": false,
    "vin_sz": 1,
    "hash": "0cafb57866d9a412e6cd0f806e03363baab1bdbf6434181ea5a927aa62930f77",
    "vout_sz": 2 }

Is there one thing unsuitable with the way in which I’m signing or establishing the TransactionWitness?

Related articles

Evaluation of multisig funds safety technique

Evaluation of multisig funds safety technique

June 15, 2025
New Cryptocurrency Releases, Listings, & Presales In the present day – ReachX Mainnet, Maximize AI, Greatest Pockets Token

New Cryptocurrency Releases, Listings, & Presales In the present day – ReachX Mainnet, Maximize AI, Greatest Pockets Token

June 15, 2025


I’m engaged on a SegWit Bitcoin transaction, and I am encountering an error when attempting to broadcast it:

Code: -26, Error: mandatory-script-verify-flag-failed (Signature should
be zero for failed CHECK(MULTI)SIG operation)

Right here’s the code I’m utilizing to signal the transaction:

personal static void signInputsOfTransaction(Handle sourceAddress, Transaction tx, ECKey key) {
    for (int i = 0; i < tx.getInputs().dimension(); i++) {
        Script scriptPubKey = ScriptBuilder.createP2WPKHOutputScript(key);

        Coin inputValue = tx.getInput(i).getValue();

        Sha256Hash hash = tx.hashForWitnessSignature(
            i, scriptPubKey, inputValue, Transaction.SigHash.ALL, false
        );

        ECKey.ECDSASignature ecdsaSignature = key.signal(hash);
        TransactionSignature txSignature = new TransactionSignature(ecdsaSignature, Transaction.SigHash.ALL, false);

        TransactionWitness witness = new TransactionWitness(2);
        witness.setPush(0, txSignature.encodeToBitcoin());
        witness.setPush(1, key.getPubKey());
        tx.getInput(i).setWitness(witness);

        tx.getInput(i).setScriptSig(ScriptBuilder.createEmpty());
    }
}

Right here’s the uncooked transaction hex I’m attempting to broadcast:

010000000001011a34c12133e07aceb6b0cd254e2d9e12fde095b5a3afece4907945e36254e0d40100000000ffffffff02e803000000000000160014c9bf27c413655f5894a6a095ccfb5f1d291123f185170000000000001600146edda921d055dece3a894e39fd91a0c50faf675c02473044022000e9341c7c137529db50f706bc2bc1c1057674cda3bc33be5c559a45731b9c2802201a0f435a70e0f3a89d272efa407e0817e964f4c14ee9f9e3e4b5961fa658fc1d01210336069ac77986a9de47f0c371b682906149e43c2f51853b30d31132d1ec33b76900000000

I’ve decoded it utilizing a Bitcoin transaction API (BlockCypher), and right here’s the output:

{
    "outputs": [
        {
            "addresses": ["bc1qexlj03qnv404399x5z2ue76lr553zgl3kfx7va"],
            "script_type": "pay-to-witness-pubkey-hash",
            "worth": 1000,
            "script": "0014c9bf27c413655f5894a6a095ccfb5f1d291123f1"
        },
        {
            "addresses": ["bc1qdmw6jgws2h0vuw5ffculmydqc5867e6ulzzm97"],
            "script_type": "pay-to-witness-pubkey-hash",
            "worth": 6021,
            "script": "00146edda921d055dece3a894e39fd91a0c50faf675c"
        }
    ],
    "addresses": [
        "bc1qdmw6jgws2h0vuw5ffculmydqc5867e6ulzzm97",
        "bc1qexlj03qnv404399x5z2ue76lr553zgl3kfx7va"
    ],
    "charges": 1130,
    "ver": 1,
    "vsize": 141,
    "inputs": [{
        "sequence": 4294967295,
        "witness": [
            "3044022000e9341c7c137529db50f706bc2bc1c1057674cda3bc33be5c559a45731b9c2802201a0f435a70e0f3a89d272efa407e0817e964f4c14ee9f9e3e4b5961fa658fc1d01",
            "0336069ac77986a9de47f0c371b682906149e43c2f51853b30d31132d1ec33b769"
        ],
        "addresses": ["bc1qdmw6jgws2h0vuw5ffculmydqc5867e6ulzzm97"],
        "prev_hash": "d4e05462e3457990e4ecafa3b595e0fd129e2d4e25cdb0b6ce7ae03321c1341a",
        "output_value": 8151,
        "script_type": "pay-to-witness-pubkey-hash",
        "output_index": 1,
        "age": 698646
    }],
    "desire": "low",
    "acquired": "2024-11-28T15:26:00.690177102Z",
    "block_height": -1,
    "confirmations": 0,
    "relayed_by": "189.37.69.88",
    "complete": 7021,
    "dimension": 222,
    "block_index": -1,
    "double_spend": false,
    "vin_sz": 1,
    "hash": "0cafb57866d9a412e6cd0f806e03363baab1bdbf6434181ea5a927aa62930f77",
    "vout_sz": 2 }

Is there one thing unsuitable with the way in which I’m signing or establishing the TransactionWitness?

Tags: BitcoinBitcoinjsegregatedSegwitsigningtransactionwitness
Share76Tweet47

Related Posts

Evaluation of multisig funds safety technique

Evaluation of multisig funds safety technique

by thecryptogoblin
June 15, 2025
0

I need to shield my bitcoin and my menace mannequin is that one of many two paper copies of the...

New Cryptocurrency Releases, Listings, & Presales In the present day – ReachX Mainnet, Maximize AI, Greatest Pockets Token

New Cryptocurrency Releases, Listings, & Presales In the present day – ReachX Mainnet, Maximize AI, Greatest Pockets Token

by thecryptogoblin
June 15, 2025
0

Be a part of Our Telegram channel to remain updated on breaking information protection Bitcoin’s shortage mannequin attracts buyers fleeing...

Staking Might Be Coming to Solana ETFs, If SEC Says Sure

Staking Might Be Coming to Solana ETFs, If SEC Says Sure

by thecryptogoblin
June 15, 2025
0

A crowd of heavyweight asset managers simply resubmitted their Solana ETF purposes, and this time they’re making room for staking....

Ethereum Researchers Go away EigenLayer Advisory Function Following Controversy — Particulars

Ethereum Basis Donates $500,000 To Twister Money Co-Founder’s Authorized Protection

by thecryptogoblin
June 14, 2025
0

Trusted Editorial content material, reviewed by main business consultants and seasoned editors. Advert Disclosure The Ethereum Basis (EF) has introduced...

This is The place Help & Resistance Lies For Solana, Primarily based On On-Chain Information

This Analyst Predicted The Dogecoin Value Crash – Right here’s The Relaxation Of The Forecast

by thecryptogoblin
June 14, 2025
0

Motive to belief Strict editorial coverage that focuses on accuracy, relevance, and impartiality Created by business specialists and meticulously reviewed...

Load More
  • Trending
  • Comments
  • Latest
CryptoRank Telegram Airdrop Information | How To Take part

CryptoRank Telegram Airdrop Information | How To Take part

September 7, 2024

bitcoin core – mandatory-script-verify-flag-failed (Script evaluated with out error however completed with a false/empty prime stack component) on wrapped SegWit enter

December 24, 2024
How Essential is Jito Solana MEV Bot Growth for the Cryptocurrency Ecosystem?

How Essential is Jito Solana MEV Bot Growth for the Cryptocurrency Ecosystem?

August 1, 2024

Bitcoin and XRP Resilient Amid Tech Inventory Rout; Ether Slides After ETF Launch

July 26, 2024

Ethereum Whales Quickly Accumulate ETH Amid Worth Decline

0

How Can a Web3 Neobanking Platform Be Useful for the Decentralized Enterprise Area?

0

2024 Recreation Growth Traits: Alternatives & Challenges | by Jon Radoff | Constructing the Metaverse

0

Prime Ethereum Analyst Says DOGE, PEPE, and RCOF Are About to Expertise a ‘Historic Breakout’

0
Evaluation of multisig funds safety technique

Evaluation of multisig funds safety technique

June 15, 2025
Vietnam Recognises Digital Belongings and Creates Proactive 2026 Legal guidelines to Promote Trade ⋆ ZyCrypto

Vietnam Recognises Digital Belongings and Creates Proactive 2026 Legal guidelines to Promote Trade ⋆ ZyCrypto

June 15, 2025
Trident Digital Bets Large on Ripple — $500 Million XRP Reserve Introduced

Crypto Ballot Reveals 91% Bullish on XRP—$5 Inside Attain

June 15, 2025
FIFA Rivals Cell Recreation Debuts Worldwide with PvP Motion and Digital Possession

FIFA Rivals Cell Recreation Debuts Worldwide with PvP Motion and Digital Possession

June 15, 2025

Token Alytics

We are a team of dedicated enthusiasts, analysts, and writers with a shared interest in the dynamic and fast-paced world of digital assets and blockchain innovation. Our diverse backgrounds in finance, technology, and media give us a unique perspective on the developments in the crypto space.

Categories

  • Bitcoin
  • Blockchain
  • Cryptocurrency
  • Defi
  • Ethereum
  • Metaverse
  • Ripple

Follow Us

  • 643 Followers

Recent News

Evaluation of multisig funds safety technique

Evaluation of multisig funds safety technique

June 15, 2025
Vietnam Recognises Digital Belongings and Creates Proactive 2026 Legal guidelines to Promote Trade ⋆ ZyCrypto

Vietnam Recognises Digital Belongings and Creates Proactive 2026 Legal guidelines to Promote Trade ⋆ ZyCrypto

June 15, 2025
  • About
  • FAQ
  • Privacy Policy
  • Support Forum
  • Disclaimer
  • Contact Us

© 2018- tokenalytics.io, All rights reserved

No Result
View All Result
  • Home
  • Bitcoin
  • Blockchain
  • Cryptocurrency
  • Defi
  • Ripple
  • Ethereum
  • Metaverse

© 2018- tokenalytics.io, All rights reserved