cmdruid / tapscript

A humble library for working with Tapscript and Bitcoin Transactions.
https://www.npmjs.com/package/@cmdcode/tapscript
Creative Commons Zero v1.0 Universal
188 stars 49 forks source link

Broadcast error, Public key version reserved for soft-fork upgrades #13

Closed GEN3LAB closed 1 year ago

GEN3LAB commented 1 year ago

follow inscribe.test.ts, broadcast tx to the mainnet, get error!

const txdata = Tx.create({
  vin  : [{
    txid: '30fcb229bdef4ab1a9d864e2cb4b562c99b8ea00d68ff156f31ec1468ba6d893',
    vout: 0,
    prevout: {
      value: 4_000,
      scriptPubKey: [ 'OP_1', tpubkey ]
    },
  }],
  vout : [{
    value: 1_000,
    scriptPubKey: Address.toScriptPubKey('bc1p93mun355nyke02gvdhx7vmes5l8enh2yw86r8x0fl98hwlug2dvq3xqj66')
  }]
})

const sig = Signer.taproot.sign(seckey, txdata, 0, { extension: tapleaf })
txdata.vin[0].witness = [ sig, script, cblock ]

const response = await axios.post('https://blockstream.info/api/tx', Tx.encode(txdata).hex)
console.log(response.data)
print:
sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Public key version reserved for soft-fork upgrades)"}
cmdruid commented 1 year ago

This error is usually caused when the public key provided in the script (before OP_CHECKSIG) is 33 bytes instead of 32 bytes.

Bitcoin core detects that you are using a non-standard key (the standard for taproot is now 32-byte keys) and then throws this error.

Can you check the script that was used to create the tapkey and make sure that the public key being provided in the script is 32 bytes?

GEN3LAB commented 1 year ago

I copy & paste the example code from repo, get this error. But i've figured it out with bitcoinlib-js, still thanks for your examples.