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()

Detecting Wallet...

The active wallet network is Unknown. This method requires BTC. Switch networks and try again.

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

Detecting Wallet...
Code Preview