• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

transactions – Missing Witness field in p2wpkh decoded tx hex

Moussa by Moussa
June 13, 2026
in Bitcoin
0
How do Bitcoin mining pools typically handle payout frequency versus thresholds?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


I have placed together a raw tx hex but when it’s unable to be broadcasted as I keep getting an error below

sendrawtransaction RPC error: {"code":-25,"message":"bad-txns-inputs-missingorspent"}

I then decoded the tx hex using https://live.blockcypher.com/btc/decodetx/ to see that I seem to be missing the Witness field as I am using native segwit addresses:

{
    "addresses": [
        "bc1qj3rjxzhlqm6fqesd5fwphjnf457zkww3s5qrv5",
        "bc1qjp3cch0hdvdr0hy99cs76kl9kekmuxv3k9nr6l"
    ],
    "block_height": -1,
    "block_index": -1,
    "confirmations": 0,
    "double_spend": false,
    "fees": 200,
    "hash": "88420211f5ea53174fc6a708c00ca2e840d687591573d0ecd2464fae20d139a7",
    "inputs": [
        {
            "addresses": [
                "bc1qj3rjxzhlqm6fqesd5fwphjnf457zkww3s5qrv5"
            ],
            "age": 696993,
            "output_index": 0,
            "output_value": 60200,
            "prev_hash": "74e24a2d50ba64abc099126c1c208b5f7156e3ad515b86f3edcca3f3d4291f66",
            "script": "4730440220516e15b6354f17e3f02711107624005e6ccd26cf61ef21b35e91315dfbd33e9f022049dadb73ca3e814de9da0b35ff20a8ca82147dda138ede948ccac5621a5bc1bb01210384485d43e938f8c68c4ac903d4d5a97fe842f66c12b860d8d2e1242d2b01fc1f",
            "script_type": "pay-to-witness-pubkey-hash",
            "sequence": 4294967295
        }
    ],
    "outputs": [
        {
            "addresses": [
                "bc1qjp3cch0hdvdr0hy99cs76kl9kekmuxv3k9nr6l"
            ],
            "script": "001490638c5df76b1a37dc852e21ed5be5b66dbe1991",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 60000
        }
    ],
    "preference": "low",
    "received": "2021-09-05T10:17:14.395062568Z",
    "relayed_by": "3.82.154.159",
    "size": 188,
    "total": 60000,
    "ver": 2,
    "vin_sz": 1,
    "vout_sz": 1,
    "vsize": 188
}

I then thought perhaps I didn’t add a scriptPubKey into the addInput but this code didn’t seem to work for me:

const fetch = require("node-fetch")
const bitcoin = require("bitcoinjs-lib")
const url = "https://blockchain.info/rawaddr/"
let MAINNET = bitcoin.networks.bitcoin
pubAdd = "bc1qj3rjxzhlqm6fqesd5fwphjnf457zkww3s5qrv5"

let txb = new bitcoin.TransactionBuilder(MAINNET)
var txid = null
var outn = 0
var transactionhex = ""

async function getPubAddInfo() {
  const response = await fetch(url + pubAdd)
  const data = await response.json()

  txid = data["txs"][0]["hash"]
  outn = data["txs"][0]["out"][0]["n"]
}

async function getTXHash() {
  await getPubAddInfo()

  let WIF = "xxxxxxxxxxxx"
  let keypairSpend = bitcoin.ECPair.fromWIF(WIF, MAINNET)

  var scriptPubkey = bitcoin.script.witnessPubKeyHash.output.encode(bitcoin.crypto.hash160(keypairSpend.getPublicKeyBuffer()))

  txb.addInput(txid, outn, null, scriptPubkey)

  txb.addOutput("bc1qjp3cch0hdvdr0hy99cs76kl9kekmuxv3k9nr6l", 60000)

  txb.sign(0, keypairSpend, null, null, 60200)

  let tx = txb.build()
  transactionhex = tx.toHex()
  console.log(transactionhex)
}

getTXHash()

At the moment I get the error TypeError: Cannot read property 'output' of undefined on the line where i create var scriptPubKey.

Any suggestions as to how I can add the Witness field into the tx? Is it because I am improperly adding the scriptPubKey? I am using bitcoinjs 5.2.0



Source link

Related articles

Bitcoin Core IBD becomes extremely slow after ~68%; peers connect but stop delivering blocks

August 30, 2026
ECB’s Schnabel Says Central Bank Money ‘Must Go Onchain’ – Bitcoin News

ECB’s Schnabel Says Central Bank Money ‘Must Go Onchain’ – Bitcoin News

August 30, 2026
Share76Tweet47

Related Posts

Bitcoin Core IBD becomes extremely slow after ~68%; peers connect but stop delivering blocks

by Moussa
August 30, 2026
0

I'm currently doing the Initial Block Download (IBD) of a Bitcoin Core node. For most of the synchronization, everything behaved...

ECB’s Schnabel Says Central Bank Money ‘Must Go Onchain’ – Bitcoin News

ECB’s Schnabel Says Central Bank Money ‘Must Go Onchain’ – Bitcoin News

by Moussa
August 30, 2026
0

Key TakeawaysIsabel Schnabel believes that the ECB must bring its reserves onchain.Project Pontes is due to launch in September 2026,...

Swedish Tax Scrutiny Shadows Crypto Miners’ Pivot to AI

Swedish Tax Scrutiny Shadows Crypto Miners’ Pivot to AI

by Moussa
August 30, 2026
0

This article first appeared in The Energy Mag. The original article can be viewed here. The Energy Mag (formerly The...

Stablecoins Still Aren’t Credible Money at Scale

Stablecoins Still Aren’t Credible Money at Scale

by Moussa
August 30, 2026
0

Key TakeawaysPablo Hernández de Cos flagged four failures in stablecoins during his Jackson Hole address.Global stablecoin supply has climbed to...

A Texas Player Just Let $1 Million Expire. It Was Sitting at a Gas Station the Whole Time

A Texas Player Just Let $1 Million Expire. It Was Sitting at a Gas Station the Whole Time

by Moussa
August 30, 2026
0

Key TakeawaysPowerball’s $1 million Austin ticket expired after its Aug. 1 claim deadline.Circle K sold the ticket matching 5 white...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagc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0bnAtZmllbGQlMjB0bnAtcHJpdmFjeS1maWVsZCUyMiUzRSUzQ2xhYmVsJTNFJTNDaW5wdXQlMjB0eXBlJTNEJTIyY2hlY2tib3glMjIlMjBuYW1lJTNEJTIybnklMjIlMjByZXF1aXJlZCUyMGNsYXNzJTNEJTIydG5wLXByaXZhY3klMjIlM0UlQzIlQTBCeSUyMGNvbnRpbnVpbmclMkMlMjB5b3UlMjBhY2NlcHQlMjB0aGUlMjBwcml2YWN5JTIwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News