<pre><code>let content_type = &quot;text/plain;charset=utf-8&quot;;
    let body = Buffer.from(&quot;000&quot;);
    const inscription = {
      body,
      content_type,
    };
    const network = bitcoin.networks.testnet;

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

    console.log(&quot;internalKey&quot;, internalKey)
    console.log(&quot;keyPair&quot;, 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 instructions = [
      bitcoin.opcodes.OP_FALSE,
      bitcoin.opcodes.OP_IF,
      Buffer.from(&quot;ord&quot;),
      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(instructions);

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

    const scriptTree = {
      output: revealScriptWithCheckSig,
    };

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

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

    if (!p2pk_p2tr.output) {
      console.log(&quot;no output&quot;);
      return;
    }
    const script_addr = p2pk_p2tr.address ?? '';

    let utxos = await waitUntilUTXO(script_addr)
    const p2pk_psbt = new bitcoin.Psbt({ network: TESTNET });
    p2pk_psbt.addInput({
      hash: utxos[0].txid,
      index: utxos[0].vout,
      witnessUtxo: { value: utxos[0].value, 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({
      address: &quot;mohjSavDdQYHRYXcS3uS6ttaHP8amyvX78&quot;, // faucet address
      value: utxos[0].value - 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}`);
</code></pre>

CC BY-SA 4.0
2023-07-12T14:10:21.140Z
What do you mean by "wrong"? did it not compile? was there a compilation error? was there a run-time error? were the results different from what you expected in some way?
RedGrittyBrick
CC BY-SA 4.0
2023-07-13T02:32:55.443Z
Showed this error bitcoinjs Can not sign for input #0 with the key, the bitcoinjs author said that I sent 2 already compiled scripts, this is wrong, but I don't know how to fix it, can you help me
lari fa
<bitcoinjs><ordinals>
Why is this Ordinals transaction I sent wrong, can anyone help me?
lari fa
# Why is this Ordinals transaction I sent wrong, can anyone help me?

(Asked by: username_0 on 2023-07-12)

```
let content_type = "text/plain;charset=utf-8";
    let body = Buffer.from("000");
    const inscription = {
      body,
      content_type,
    };
    const network = bitcoin.networks.testnet;

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

    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 instructions = [
      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(instructions);

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

    const scriptTree = {
      output: revealScriptWithCheckSig,
    };

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

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

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

    let utxos = await waitUntilUTXO(script_addr)
    const p2pk_psbt = new bitcoin.Psbt({ network: TESTNET });
    p2pk_psbt.addInput({
      hash: utxos[0].txid,
      index: utxos[0].vout,
      witnessUtxo: { value: utxos[0].value, 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({
      address: "mohjSavDdQYHRYXcS3uS6ttaHP8amyvX78", // faucet address
      value: utxos[0].value - 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}`);

```

**Tags:** bitcoinjs, ordinals

> **Comments:**
> **username_1**: What do you mean by "wrong"? did it not compile? was there a compilation error? was there a run-time error? were the results different from what you expected in some way?  
> **username_0**: Showed this error bitcoinjs Can not sign for input #0 with the key, the bitcoinjs author said that I sent 2 already compiled scripts, this is wrong, but I don't know how to fix it, can you help me  

---

## 0 answers

