bitcoinjs – Why is that this Ordinals transaction I despatched unsuitable, can anybody assist me?

0
61


let content_type = "textual content/plain;charset=utf-8";
    let physique = Buffer.from("000");
    const inscription = {
      physique,
      content_type,
    };
    const community = bitcoin.networks.testnet;

    const internalKey = bip32.fromSeed(rng(64), community);

    console.log("internalKey", internalKey)
    console.log("keyPair", keyPair)

    const hash_lock_keypair = toXOnly(internalKey.publicKey);

    const hash_lock_script = bitcoin.script.compile([
      hash_lock_keypair,
      bitcoin.opcodes.OP_CHECKSIG,
    ]);

    const p2pk_script_asm = `${toXOnly(keyPair.publicKey).toString('hex')} OP_CHECKSIG`;
    const p2pk_script = bitcoin.script.fromASM(p2pk_script_asm);


    let directions = [
      bitcoin.opcodes.OP_FALSE,
      bitcoin.opcodes.OP_IF,
      Buffer.from("ord"),
      bitcoin.opcodes.OP_1,
      Buffer.from(inscription.content_type),
      bitcoin.opcodes.OP_0,
      Buffer.from(inscription.body),
      bitcoin.opcodes.OP_ENDIF
    ];

    const revealScript = bitcoin.script.compile(directions);

    const revealScriptWithCheckSig = bitcoin.script.compile([
      hash_lock_script,
      revealScript,
    ]);

    const scriptTree = {
      output: revealScriptWithCheckSig,
    };

    const p2pk_redeem = {
      output: revealScriptWithCheckSig,
      redeemVersion: 192,
    };

    const p2pk_p2tr = bitcoin.funds.p2tr({
      internalPubkey: toXOnly(internalKey.publicKey),
      scriptTree,
      redeem: p2pk_redeem,
      community: community,
    });

    if (!p2pk_p2tr.output) {
      console.log("no output");
      return;
    }
    const script_addr = p2pk_p2tr.deal with ?? '';

    let utxos = await waitUntilUTXO(script_addr)
    const p2pk_psbt = new bitcoin.Psbt({ community: TESTNET });
    p2pk_psbt.addInput({
      hash: utxos[0].txid,
      index: utxos[0].vout,
      witnessUtxo: { worth: utxos[0].worth, script: p2pk_p2tr.output! },
      tapLeafScript: [
        {
          leafVersion: p2pk_redeem.redeemVersion,
          script: p2pk_redeem.output,
          controlBlock: p2pk_p2tr.witness![p2pk_p2tr.witness!.length - 1]
        }
      ]
    });

    p2pk_psbt.addOutput({
      deal with: "mohjSavDdQYHRYXcS3uS6ttaHP8amyvX78", // faucet deal with
      worth: utxos[0].worth - 150
    });
    p2pk_psbt.signInput(0, internalKey);
    p2pk_psbt.finalizeAllInputs();

    let tx = p2pk_psbt.extractTransaction();
    console.log(`Broadcasting Transaction Hex: ${tx.toHex()}`);
    let txid = await broadcast(tx.toHex());
    console.log(`Success! Txid is ${txid}`);

LEAVE A REPLY

Please enter your comment!
Please enter your name here