Skip to main content

Import


createBtcBuilder

Factory function to create a Bitcoin or Zcash transaction builder.

Signature

Parameters

BtcBuilderConfig
required
Configuration for the builder.

Returns

BtcBuilder
A builder instance with methods for UTXO operations, proof generation, and transaction broadcasting.

Example


BtcBuilder

The builder interface returned by createBtcBuilder. Provides methods for UTXO selection, withdrawal planning, proof generation, and transaction broadcasting.

buildWithdrawalPlan

Builds a complete withdrawal plan from available UTXOs, selecting inputs and constructing outputs.

Signature

Parameters

UTXO[]
required
Available UTXOs to spend from.
bigint
required
Amount to send in satoshis (BTC) or zatoshis (ZEC).
string
required
Recipient address.
string
required
Address to receive change.
number
Fee rate in sat/vbyte. Defaults to 1. Ignored for Zcash (uses ZIP-317).
UtxoPlanOverrides
Optional overrides for UTXO selection behavior.

Returns

BtcWithdrawalPlan
The withdrawal plan with inputs, outputs, and calculated fee.

Example


selectUtxos

Selects UTXOs to cover a target amount plus estimated fees.

Signature

Parameters

NormalizedUTXO[]
required
Available UTXOs with normalized amount as bigint.
bigint
required
Target amount in satoshis/zatoshis.
Partial<UtxoSelectionOptions>
Selection options (merged with chain-specific defaults).

Returns

UtxoSelectionResult
Selection result with inputs, totals, fee, and change.

Example


getDepositProof

Generates a deposit proof for verifying a BTC/ZEC deposit on NEAR. Used when finalizing cross-chain transfers.

Signature

Parameters

string
required
The transaction hash of the deposit.
number
required
The output index in the transaction.

Returns

Promise<BtcDepositProof>
Proof data for on-chain verification.

Example


getMerkleProof

Gets a Merkle proof for transaction inclusion in a block.

Signature

Parameters

string
required
The transaction hash.

Returns

Promise<BtcMerkleProof>
Merkle proof with block height and position.

Example


addressToScriptPubkey

Converts an address to its hex-encoded scriptPubkey.

Signature

Parameters

string
required
Bitcoin or Zcash address.

Returns

string
Hex-encoded scriptPubkey.

Example


broadcastTransaction

Broadcasts a signed transaction to the network.

Signature

Parameters

string
required
Hex-encoded signed transaction.

Returns

Promise<string>
Transaction ID if broadcast succeeds.

Example


getTransactionBytes

Fetches raw transaction bytes for a given transaction hash.

Signature

Parameters

string
required
The transaction hash.

Returns

Promise<Uint8Array>
Raw transaction bytes.

Example


getNetwork

Returns the Bitcoin network configuration object from @scure/btc-signer.

Signature

Returns

NETWORK | TEST_NETWORK
Network configuration for address encoding/decoding.

Example


Fee Calculation

linearFeeCalculator

Creates a fee calculator based on linear transaction size estimation (Bitcoin).

Signature

Parameters

LinearFeeParameters
required

Returns

FeeCalculator
A function (inputCount: number, outputCount: number) => bigint that calculates fees.

Example


zcashFeeCalculator

Creates a fee calculator using the ZIP-317 marginal fee model for Zcash.

Signature

Returns

FeeCalculator
A function that calculates Zcash fees per ZIP-317.

Example


calculateZcashFee

Directly calculates Zcash transaction fee using ZIP-317. ZIP-317 marginal fee model:
  • Each input or output counts as a “logical action”
  • Grace actions = 2 (first 2 actions are free)
  • Marginal fee = 5000 zatoshis per action
  • Fee = 5000 * max(2, max(inputs, outputs))

Signature

Parameters

number
required
Number of transaction inputs.
number
required
Number of transaction outputs.

Returns

bigint
Fee in zatoshis.

Example


getZcashScript

Converts a Zcash transparent address to its hex-encoded scriptPubkey. Supports:
  • Mainnet P2PKH (t1…)
  • Mainnet P2SH (t3…)
  • Testnet P2PKH (tm…)
  • Testnet P2SH (t2…)

Signature

Parameters

string
required
Zcash transparent address.

Returns

string
Hex-encoded scriptPubkey.

Example


ZCASH_DUST_THRESHOLD

Dust threshold constant for Zcash transactions (5000 zatoshis).

RPC Utilities

UtxoRpcClient

Low-level RPC client for Bitcoin/Zcash nodes. Used internally by BtcBuilder but exported for advanced use cases.

Constructor

UtxoRpcConfig
required

Methods

call
Execute a raw JSON-RPC method.
getTransaction
Fetch transaction details.
getBlock
Fetch block details.
buildDepositProof
Build a complete deposit proof.
buildMerkleProof
Build a Merkle inclusion proof.

Example


buildBitcoinMerkleProof

Builds a Bitcoin-style Merkle proof for transaction inclusion in a block.

Signature

Parameters

string[]
required
Array of all transaction IDs in the block (in order).
string
required
Transaction ID to generate proof for.

Returns

{ index: number; merkle: string[] }

Example


Types

UTXO

Unspent Transaction Output representation. Re-exported from @omni-bridge/core.

NormalizedUTXO

Normalized UTXO with amount as bigint for internal processing.

BtcWithdrawalPlan

Complete withdrawal plan ready for signing.

BtcDepositProof

Proof data for verifying a BTC/ZEC deposit on NEAR.

BtcMerkleProof

Merkle inclusion proof for a transaction.

FeeCalculator

Function type for calculating transaction fees.

LinearFeeParameters

Parameters for the linear fee calculation model.

UtxoSelectionOptions

Options for UTXO selection algorithms.

UtxoSelectionResult

Result of UTXO selection.

UtxoPlanOverrides

Overrides for withdrawal plan generation. Subset of UtxoSelectionOptions excluding feeCalculator.

BtcBuilderConfig

Configuration for createBtcBuilder.

UtxoRpcConfig

Configuration for UtxoRpcClient.

UtxoChainType

UTXO chain type for RPC configuration.

Constants


Default Fee Parameters

Bitcoin Defaults

Zcash Defaults (ZIP-317)