fboucquez / ordinal-inscription-example-using-bitcoinjs-lib

14 stars 6 forks source link

Get "Invalid Schnorr signature" in testnet #2

Open maplerichie opened 6 months ago

maplerichie commented 6 months ago

Try modify the ordinals-bitcoinjs.test.js into run.js as below

const ordinalsBitcoinjs = require('./ordinals-bitcoinjs')

const {
  ECPair,
  createRevealTx,
  createCommitTxData,
  createTextInscription,
} = ordinalsBitcoinjs

async function main() {
  const secret = 'fc7458de3d5616e7803fdc81d688b9642641be32fee74c4558ce680cac3d4111'
  const privateKey = Buffer.from(secret, 'hex')
  const keypair = ECPair.fromPrivateKey(privateKey)
  const publicKey = keypair.publicKey

  const inscription = createTextInscription({ text: 'Hello!!' })
  const commitTxData = createCommitTxData({
    publicKey,
    inscription,
  })
  const toAddress = 'tb1p54k30k88cuewxusuyxca7wsxg0qwgfswldfy6qdmpn8plax2qanqjxas2p'

  const padding = 549
  const txSize = 600 + Math.floor(inscription.content.length / 4)
  const feeRate = 2
  const minersFee = txSize * feeRate

  const requiredAmount = 550 + minersFee + padding

  const commitTxResult = {
    txId: 'fe054e7d1d9e0ccc5b464bd9da0e06d886806ed868cb54d1edd8916382ab5b3e',
    sendUtxoIndex: 0,
    sendAmount: requiredAmount,
  }

  const revelRawTx = await createRevealTx({
    commitTxData,
    commitTxResult,
    toAddress,
    privateKey,
    amount: padding,
  })

  const txHash = await broadcastTx(revelRawTx.rawTx, "testnet");
  console.log(txHash);
}

main().catch((err) => console.error(err));

const broadcastTx = async (
  txHex,
  network
) => {
  const url =
    network === "main"
      ? `https://mempool.space/api/tx`
      : `https://mempool.space/testnet/api/tx`;
  const resp = await fetch(url, {
    method: "POST",
    body: txHex,
    headers: {
      'Content-Type': 'application/json'
    }
  });
  const data = await resp.text();
  return data;
}

And change the network in ordinals-bitcoinjs.js into bitcoinjsLib.networks.testnet

The error from broadcast is sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Invalid Schnorr signature)"}, any idea which part invalid cause this to happen?

Also try mnemonic with bip32 but another error occured, sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Witness program hash mismatch)"}

Thanks

mgpai22 commented 6 months ago

@fboucquez I have the same issue.

James1847 commented 6 months ago

Try modify the ordinals-bitcoinjs.test.js into run.js as below

const ordinalsBitcoinjs = require('./ordinals-bitcoinjs')

const {
  ECPair,
  createRevealTx,
  createCommitTxData,
  createTextInscription,
} = ordinalsBitcoinjs

async function main() {
  const secret = 'fc7458de3d5616e7803fdc81d688b9642641be32fee74c4558ce680cac3d4111'
  const privateKey = Buffer.from(secret, 'hex')
  const keypair = ECPair.fromPrivateKey(privateKey)
  const publicKey = keypair.publicKey

  const inscription = createTextInscription({ text: 'Hello!!' })
  const commitTxData = createCommitTxData({
    publicKey,
    inscription,
  })
  const toAddress = 'tb1p54k30k88cuewxusuyxca7wsxg0qwgfswldfy6qdmpn8plax2qanqjxas2p'

  const padding = 549
  const txSize = 600 + Math.floor(inscription.content.length / 4)
  const feeRate = 2
  const minersFee = txSize * feeRate

  const requiredAmount = 550 + minersFee + padding

  const commitTxResult = {
    txId: 'fe054e7d1d9e0ccc5b464bd9da0e06d886806ed868cb54d1edd8916382ab5b3e',
    sendUtxoIndex: 0,
    sendAmount: requiredAmount,
  }

  const revelRawTx = await createRevealTx({
    commitTxData,
    commitTxResult,
    toAddress,
    privateKey,
    amount: padding,
  })

  const txHash = await broadcastTx(revelRawTx.rawTx, "testnet");
  console.log(txHash);
}

main().catch((err) => console.error(err));

const broadcastTx = async (
  txHex,
  network
) => {
  const url =
    network === "main"
      ? `https://mempool.space/api/tx`
      : `https://mempool.space/testnet/api/tx`;
  const resp = await fetch(url, {
    method: "POST",
    body: txHex,
    headers: {
      'Content-Type': 'application/json'
    }
  });
  const data = await resp.text();
  return data;
}

And change the network in ordinals-bitcoinjs.js into bitcoinjsLib.networks.testnet

The error from broadcast is sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Invalid Schnorr signature)"}, any idea which part invalid cause this to happen?

Also try mnemonic with bip32 but another error occured, sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Witness program hash mismatch)"}

Thanks

how can u build the commitTx using psbt?