Skip to main content

Import


createBtcBuilder

Factory function to create a Bitcoin or Zcash transaction builder.

Signature

Parameters

config
BtcBuilderConfig
required
Configuration for the builder.

Returns

BtcBuilder
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

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

Returns

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

Example


selectUtxos

Selects UTXOs to cover a target amount plus estimated fees.

Signature

Parameters

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

Returns

UtxoSelectionResult
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

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

Returns

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

Example


getMerkleProof

Gets a Merkle proof for transaction inclusion in a block.

Signature

Parameters

txHash
string
required
The transaction hash.

Returns

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

Example


addressToScriptPubkey

Converts an address to its hex-encoded scriptPubkey.

Signature

Parameters

address
string
required
Bitcoin or Zcash address.

Returns

scriptPubkey
string
Hex-encoded scriptPubkey.

Example


broadcastTransaction

Broadcasts a signed transaction to the network.

Signature

Parameters

txHex
string
required
Hex-encoded signed transaction.

Returns

txid
Promise<string>
Transaction ID if broadcast succeeds.

Example


getTransactionBytes

Fetches raw transaction bytes for a given transaction hash.

Signature

Parameters

txHash
string
required
The transaction hash.

Returns

txBytes
Promise<Uint8Array>
Raw transaction bytes.

Example


getNetwork

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

Signature

Returns

network
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

params
LinearFeeParameters
required

Returns

FeeCalculator
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
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

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

Returns

fee
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

address
string
required
Zcash transparent address.

Returns

scriptPubkey
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

config
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

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

Returns

proof
{ 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)