Skip to content

btc.signTransaction

Sign a single BTC raw transaction via the btc object. Supports three signature types: legacy, segwit_v0, and taproot.

For the taproot type, leafHashesHex distinguishes between key path and script path: undefined for key path, a value for script path.

Usage

Legacy (P2PKH) Signing

ts
const result = await Turing.btc.signTransaction({
  txHex: "0200000001...",
  type: "legacy",
  prevOutScriptsHex: ["76a914...88ac"],
});

if (result.sigs) {
  console.log("Signatures:", result.sigs);
}

SegWit V0 (P2WPKH) Signing

ts
const result = await Turing.btc.signTransaction({
  txHex: "0200000001...",
  type: "segwit_v0",
  prevOutScriptsHex: ["76a914...88ac"],
  values: [100000],
});

if (result.sigs) {
  console.log("Signatures:", result.sigs);
}

Taproot Key Path Signing

ts
const result = await Turing.btc.signTransaction({
  txHex: "0200000001...",
  type: "taproot",
  prevOutScriptsHex: ["5120..."],
  values: [100000],
});

if (result.sigs) {
  console.log("Signatures:", result.sigs);
}

Taproot Script Path Signing

ts
const result = await Turing.btc.signTransaction({
  txHex: "0200000001...",
  type: "taproot",
  prevOutScriptsHex: ["5120..."],
  values: [100000],
  leafHashesHex: ["ab12cd34..."],
});

if (result.sigs) {
  console.log("Signatures:", result.sigs);
}

Parameters

ts
type BtcSigHashType = "legacy" | "segwit_v0" | "taproot";

interface BtcSignTransaction {
  txHex: string;                          // Raw transaction hex
  type: BtcSigHashType;                   // Signature hash type
  prevOutScriptsHex: string[];            // Previous output script hex for each input
  values?: number[];                      // Amount (satoshis) for each input, required for segwit_v0/taproot
  leafHashesHex?: (string | undefined)[]; // Leaf hash for each input, taproot only. undefined = key path, value = script path
}
FieldTypeDescription
txHexstringRaw transaction hex to sign
typeBtcSigHashTypeSignature type — "legacy", "segwit_v0", or "taproot"
prevOutScriptsHexstring[]Previous output script hex for each input
valuesnumber[](Optional) Amount in satoshis for each input. Required for segwit_v0 and taproot
leafHashesHex(string | undefined)[](Optional) Leaf hash for each input. Taproot only — undefined for key path, a hex string for script path

Returns

ts
interface BtcSignTransactionResponse {
  sigs?: string[];  // Signature hex for each input
  error?: string;   // Error message
}
FieldTypeDescription
sigsstring[]Array of signature hex strings, one per input
errorstringError message if signing fails

Error Handling

ts
const result = await Turing.btc.signTransaction({
  txHex: "0200000001...",
  type: "legacy",
  prevOutScriptsHex: ["76a914...88ac"],
});

if (result.error) {
  console.error("Signing failed:", result.error);
  return;
}

console.log("Signatures:", result.sigs);

Live Example

Live Example

Turing.btc.signTransaction()

Unknown
Use the wallet control in the top navigation before running this example.

Includes sample data for preview. Clear it to use your own transaction data.

Code Preview
const params = {
  "txHex": "020000000133333333333333333333333333333333333333333333333333333333333333330000000000ffffffff01a0860100000000001976a914444444444444444444444444444444444444444488ac00000000",
  "type": "legacy",
  "prevOutScriptsHex": [
    "76a914555555555555555555555555555555555555555588ac"
  ]
};

const result = await Turing.btc.signTransaction(params);
console.log(result);
Make sure the browser extension is enabled, or open this page inside Turing Wallet on mobile.