Bitcoin Transactions
Build, sign, broadcast Bitcoin transactions, and compute signature hashes with Zafeguard Bitcoin components.
Bitcoin Transactions
Components for building, signing, and broadcasting Bitcoin transactions, plus signature hash computation.
Public endpoints enforce rate limits per IP address and can fail under concurrent load. Use a private or self-hosted Bitcoin node. See Connecting to Bitcoin.
BROADCAST_BITCOIN_TRANSACTION
BROADCAST_BITCOIN_TRANSACTION Workflow Component
Broadcasts a finalized raw transaction to the Bitcoin network and returns the transaction ID.
Config
| Field | Type | Required | Description |
|---|---|---|---|
network | 'mainnet' | 'testnet' | Yes | Target Bitcoin network |
Inputs
| Field | Type | Description |
|---|---|---|
signedTransaction | string (hex) | Raw transaction hex to broadcast |
Outputs
| Field | Type | Description |
|---|---|---|
txid | string | Transaction ID (64-char hex) |
SDK example
import { WorkspaceClient, ComponentModule } from '@zafeguard/caller-sdk';
const workspace = new WorkspaceClient({ apiKey: process.env.ZAFEGUARD_API_KEY! });
const result = await workspace.call(ComponentModule.BROADCAST_BITCOIN_TRANSACTION, {
signedTransaction: 'deadbeef...',
}).promise();
console.log(result.txid);BUILD_BITCOIN_TRANSACTION
BUILD_BITCOIN_TRANSACTION Workflow Component
Builds an unsigned PSBT with UTXO selection, fee estimation, and sighash generation. Supports optional locktime, OP_RETURN data, change address configuration, and fee deduction.
Config
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
paymentType | 'p2pkh' | 'p2sh-p2wpkh' | 'p2wpkh' | 'p2tr' | Yes | — | Bitcoin payment type (address format) |
network | 'mainnet' | 'testnet' | Yes | — | Target Bitcoin network |
deductFee | boolean | No | false | When true, subtracts the estimated fee from amount instead of adding it on top |
Inputs
| Field | Type | Description |
|---|---|---|
recipientAddress | string | Destination Bitcoin address |
amount | number | Amount to send in satoshis (non-negative integer) |
publicKey | string (hex) | Sender public key — compressed 33 bytes (66 hex) or uncompressed 65 bytes (130 hex) |
locktime | string | null | Transaction locktime as block height string. null to disable |
opReturnData | string | null | Hex data to embed in an OP_RETURN output. null to skip |
changeAddress | string | null | Address for change output. null uses the sender's address |
feeRate | number | null | Custom fee rate in sat/vByte. null falls back to the network's half-hour fee estimate. Must be a positive number. See Customizing Transaction Fees for the vBytes formula and recommended rate ranges. |
Outputs
| Field | Type | Description |
|---|---|---|
unsignedTransaction | string (hex) | Hex-encoded unsigned PSBT |
messageHashes | string[] | Array of sighash hex strings, one per input (each 64 hex chars) |
estimatedFee | number | Estimated network fee in satoshis (using the chosen fee rate) |
SDK example
import { WorkspaceClient, ComponentModule } from '@zafeguard/caller-sdk';
const workspace = new WorkspaceClient({ apiKey: process.env.ZAFEGUARD_API_KEY! });
const result = await workspace.call(ComponentModule.BUILD_BITCOIN_TRANSACTION, {
recipientAddress: 'bc1q...',
amount: 50000,
publicKey: '02abc123...',
locktime: null,
opReturnData: null,
changeAddress: null,
feeRate: null, // or e.g. 25 for 25 sat/vByte
}).promise();
console.log(result.unsignedTransaction);
console.log(result.messageHashes); // sign each of these
console.log(result.estimatedFee);SIGN_BITCOIN_TRANSACTION
SIGN_BITCOIN_TRANSACTION Workflow Component
Applies signatures to an unsigned PSBT and produces a finalized raw transaction ready to broadcast.
Config
None.
Inputs
| Field | Type | Description |
|---|---|---|
unsignedTransaction | string (hex) | Hex-encoded PSBT from BUILD_BITCOIN_TRANSACTION |
signatures | string[] | Hex-encoded signatures, one per input |
publicKey | string (hex) | Signer public key — compressed 33 bytes (66 hex) or uncompressed 65 bytes (130 hex) |
Outputs
| Field | Type | Description |
|---|---|---|
signedTransaction | string (hex) | Finalized raw transaction hex, ready to broadcast |
SDK example
import { WorkspaceClient, ComponentModule } from '@zafeguard/caller-sdk';
const workspace = new WorkspaceClient({ apiKey: process.env.ZAFEGUARD_API_KEY! });
const result = await workspace.call(ComponentModule.SIGN_BITCOIN_TRANSACTION, {
unsignedTransaction: buildResult.unsignedTransaction,
signatures: ['3045...', '3044...'],
publicKey: '02abc123...',
}).promise();
console.log(result.signedTransaction);COMPUTE_BITCOIN_SIGNATURE_HASH
COMPUTE_BITCOIN_SIGNATURE_HASH Workflow Component
Computes a signature hash for a message using either the standard Bitcoin message format or raw SHA-256 hashing.
Config
| Field | Type | Required | Description |
|---|---|---|---|
format | 'bitcoin-message' | 'raw' | Yes | bitcoin-message produces a standard signed-message hash. raw produces a double SHA-256 hash |
Inputs
| Field | Type | Description |
|---|---|---|
message | string | Message string to hash |
Outputs
| Field | Type | Description |
|---|---|---|
messageHash | string | 32-byte hash as 64-char hex, ready for external signing |
Transaction flow
GET_BITCOIN_DERIVATION_PATH
│
▼
(external signing)
→ public key
│
▼
BUILD_BITCOIN_TRANSACTION ─── messageHashes ──▶ (external signing)
│ │ signatures
│ ▼
└─── unsignedTransaction ──▶ SIGN_BITCOIN_TRANSACTION
│
▼ signedTransaction
BROADCAST_BITCOIN_TRANSACTION
Stage statuses
| Status | Meaning |
|---|---|
CREATED | Queued, waiting to execute |
RUNNING | Actively executing |
COMPLETED | Finished successfully |
FAILED | Failed — check error field |