BridgeKit class
Bridge Kit lets you perform cost estimates and crosschain transfers. You can also add event listeners for each bridging provider.constructor(config?)
Creates a new BridgeKit instance.TypeScript
| Name | Type | Description |
|---|---|---|
config | BridgeKitConfig | Optionally adds extra bridging providers |
TypeScript
BridgeKitConfig
Optionally adds extra bridging providers.TypeScript
| Name | Type | Description |
|---|---|---|
providers | BridgingProvider | Bridging providers to use in addition to CCTP (optional) |
CustomFeePolicy
Global configuration for collecting a transfer fee. For details on how custom fees work, see Custom Fees.TypeScript
| Name | Type | Description |
|---|---|---|
computeFee | function | Returns the fee amount in human-readable format. See Custom Fees for fee splitting details. |
resolveFeeRecipientAddress | function | Returns the address that receives the fee on the source chain. Must be a valid address for the source chain. |
TypeScript
Methods
bridge(params: BridgeParams)
Executes crosschain transfers.TypeScript
| Name | Type | Description |
|---|---|---|
params | BridgeParams | Bridge transfer parameters |
BridgeResult
Usage example
TypeScript
estimate(params: BridgeParams)
Estimates costs before transferring.TypeScript
| Name | Type | Description |
|---|---|---|
params | BridgeParams | Bridge transfer parameters |
EstimateResult
Usage example
TypeScript
getSupportedChains()
Returns a list of available blockchains.TypeScript
ChainDefinition[] An array of blockchains, each object containing:
chain- String identifier of the blockchain, used in bridge parametersname- Human-readable name of the blockchain, used in UI displaystype- Blockchain typechainId- Network ID for EVM chains onlyusdcAddress- USDC token contract address on the chaincctp- CCTP configuration including domain ID and contract addresses
ChainDefinition[]:
TypeScript
on(action: string, handler: function)
Adds an event listener.TypeScript
| Name | Type | Description |
|---|---|---|
action | string | Event type or * for all events. Events are type-safe and defined by the providers. |
handler | function | Event handler |
void
Usage example
TypeScript
off(action: string, handler: function)
Removes an event listener.TypeScript
| Name | Type | Description |
|---|---|---|
action | string | Event type or * for all events. |
handler | function | Event handler |
void
Usage example
TypeScript
retry(result: BridgeResult, context: RetryContext)
Retries a failed or incomplete bridge operation.TypeScript
| Name | Type | Description |
|---|---|---|
result | BridgeResult | The bridge result from a previous failed or incomplete operation |
context | RetryContext | Retry context containing fresh adapter instances for source and destination chains |
BridgeResult
Usage example
TypeScript
setCustomFeePolicy(customFeePolicy: CustomFeePolicy)
Sets a global custom fee policy for all transfers.TypeScript
| Name | Type | Description |
|---|---|---|
customFeePolicy | CustomFeePolicy | The custom fee policy configuration |
void
Usage example
For usage example, see CustomFeePolicy.
removeCustomFeePolicy()
Removes the custom fee policy for the kit.TypeScript
void
Usage example
TypeScript
Method parameters
BridgeParams
Parameters to execute a crosschain bridge transfer.TypeScript
| Name | Type | Description |
|---|---|---|
from | AdapterContext | The source adapter and the specific chain on which the source address exists |
to | BridgeDestination | The destination adapter, the destination chain, and a recipient address (optional, if different than adapter’s default address) |
amount | string | The amount of tokens to transfer |
config | BridgeConfig | Configuration of transfer speed (optional) |
token | USDC | The type of token to transfer (optional, defaults to USDC if omitted) |
BridgeConfig
Configuration for transfer speed.TypeScript
| Name | Type | Description |
|---|---|---|
transferSpeed | FAST | SLOW | The speed of the transfer (optional, defaults to FAST if omitted) |
maxFee | string | FAST transfers only: the maximum fee per transfer in human-readable format (for example, "5" for 5 USDC). If the actual fee exceeds this, the transfer speed switches to SLOW. |
customFee | CustomFee | A custom fee that you can add to the transfer |
CustomFee
Per-transfer fee configuration that can be included inBridgeConfig.
For details on how custom fees work, see
Custom Fees.
TypeScript
| Name | Type | Description |
|---|---|---|
value | string | The fee amount in human-readable format (for example, "1" for 1 USDC, "0.5" for 0.5 USDC). The fee is added on top of the transfer amount. |
recipientAddress | string | The address that receives the fee on the source chain. Must be a valid address for the source chain. |
TypeScript
AdapterContext
The adapter and its associated chain.TypeScript
| Name | Type | Description |
|---|---|---|
adapter | Adapter | The adapter instance that handles blockchain operations |
chain | ChainIdentifier | The identifier of the blockchain |
TypeScript
BridgeDestination
Specifies where tokens should be sent.TypeScript
| Type | Description |
|---|---|
AdapterContext | The adapter’s address on the destination chain |
BridgeDestinationWithAddress | Includes a specific recipient address used to override the default adapter’s address |
BridgeDestinationWithAddress
Specifies a recipient wallet address.TypeScript
| Name | Type | Description |
|---|---|---|
adapter | Adapter | The adapter |
chain | ChainIdentifier | The chain identifier |
recipientAddress | string | The recipient wallet address on the destination chain |
TypeScript
RetryContext
Context for retrying a failed bridge operation.TypeScript
| Name | Type | Description |
|---|---|---|
from | Adapter | Fresh adapter instance for the source chain |
to | Adapter | Fresh adapter instance for the destination chain |
TypeScript
Method results
BridgeResult
Shows the transfer state, transaction step, source, and destination chain information, and the transfer amount. Returned by the bridge method.TypeScript
| Name | Type | Description |
|---|---|---|
amount | string | The amount of the transfer |
token | string | The token to transfer, defaults to USDC |
state | "pending" | "success" | "error" | The state of the transfer |
config | BridgeConfig | The bridge configurations passed in the transfer |
source | object | Source chain information |
destination | object | Destination chain and address (includes optional recipientAddress if custom address was specified) |
steps | BridgeStep[] | Array of transaction steps, each containing the transaction state and hash |
JSON
BridgeStep
Individual transaction step within a bridge operation. Each step represents a distinct action in the cross-chain transfer process.TypeScript
| Name | Type | Description |
|---|---|---|
name | string | Human-readable name (for example, “Approve”, “Burn”, “Mint”) |
state | "pending" | "success" | "error" | "noop" | Current state of the step |
txHash | string | Transaction hash for this step (optional) |
explorerUrl | string | Block explorer URL for viewing the transaction (optional) |
data | unknown | Additional data for the step (optional) |
errorMessage | string | Human-readable error message if step failed (optional) |
error | unknown | Raw error object from the chain (optional) |
EstimateResult
Estimated costs of the transaction, returned by the estimate method.TypeScript
| Name | Type | Description |
|---|---|---|
token | string | The token being transferred (currently only USDC is supported) |
amount | string | The amount being transferred |
source | object | Source chain and address information |
destination | object | Destination chain and address information |
gasFees | EstimatedGas[] | Array of gas costs for each step on source and destination chains |
fees | object[] | Array of protocol and kit fees (type "provider" or "kit") |
JSON
EstimatedGas
Gas estimation details for a specific transaction step. Returned as part ofgasFees entries in EstimateResult.
TypeScript
| Name | Type | Description |
|---|---|---|
gas | bigint | The amount of gas units estimated for the transaction |
gasPrice | bigint | The estimated price per unit of gas (primarily for EVM chains) |
fee | string | The total estimated fee in the native token (for example, ETH, MATIC, SOL) |
- For EVM chains:
feeequalsgas * gasPrice(represented in wei) - For non-EVM chains:
gasandgasPricemay represent different metrics (for example, compute units on Solana) - The
feefield is always in the smallest unit of the native currency
Error Handling
Bridge Kit provides structured error handling with typed errors, type guards, and utility functions to help you handle errors gracefully in your application.KitError
Structured error class for all Bridge Kit operations. All errors thrown by Bridge Kit extend this class with consistent properties for programmatic handling.TypeScript
| Name | Type | Description |
|---|---|---|
code | number | Numeric error code following standardized ranges (see error constants below) |
name | string | Human-readable error ID (for example, "INPUT_NETWORK_MISMATCH") |
type | ErrorType | Error category: "INPUT", "BALANCE", "ONCHAIN", "RPC", or "NETWORK" |
recoverability | Recoverability | Error handling strategy: "FATAL", "RETRYABLE", or "RESUMABLE" |
message | string | User-friendly error explanation with context |
cause | object | Raw error details or the original error that caused this one (optional) |
| Range | Type | Description |
|---|---|---|
| 1000-1999 | INPUT | Parameter validation, invalid inputs, configuration errors |
| 3000-3999 | NETWORK | Internet connectivity, DNS, connection issues |
| 4000-4999 | RPC | Blockchain RPC provider issues, gas estimation, nonce errors |
| 5000-5999 | ONCHAIN | Transaction/simulation failures, gas exhaustion, reverts |
| 9000-9999 | BALANCE | Insufficient funds, token balance, allowance issues |
TypeScript
Error Constants
Bridge Kit exports error constant objects for each error type, providing easy access to error codes and names for specific error scenarios.InputError
Validation failures and invalid parameters. AlwaysFATAL recoverability.
TypeScript
TypeScript
BalanceError
Insufficient funds or allowance issues. AlwaysFATAL recoverability.
TypeScript
TypeScript
OnchainError
Transaction execution or simulation failures. TypicallyFATAL recoverability.
TypeScript
TypeScript
RpcError
Blockchain RPC provider communication issues. TypicallyRETRYABLE
recoverability.
TypeScript
TypeScript
NetworkError
Network connectivity issues. TypicallyRETRYABLE recoverability.
TypeScript
TypeScript
Error Type Guards
Type guard functions that enable TypeScript type narrowing and help you handle different error types appropriately.isKitError()
Checks if an error is aKitError instance.
TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to check |
boolean - true if error is a KitError with type narrowing
Usage example
TypeScript
isFatalError()
Checks if an error hasFATAL recoverability. Fatal errors require user
intervention and should not be retried.
TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to check |
boolean - true if error has FATAL recoverability
Usage example
TypeScript
isRetryableError()
Checks if an error hasRETRYABLE recoverability. Retryable errors are
transient and may succeed on subsequent attempts.
TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to check |
boolean - true if error has RETRYABLE recoverability
Usage example
TypeScript
isInputError()
Checks if an error is an input validation error.TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to check |
boolean - true if error has INPUT type
Usage example
TypeScript
isBalanceError()
Checks if an error is a balance-related error.TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to check |
boolean - true if error has BALANCE type
Usage example
TypeScript
isOnchainError()
Checks if an error is an on-chain execution error.TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to check |
boolean - true if error has ONCHAIN type
Usage example
TypeScript
isRpcError()
Checks if an error is an RPC provider error.TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to check |
boolean - true if error has RPC type
Usage example
TypeScript
isNetworkError()
Checks if an error is a network connectivity error.TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to check |
boolean - true if error has NETWORK type
Usage example
TypeScript
Error Utility Functions
Utility functions for extracting error information safely from any error type.getErrorMessage()
Safely extracts error message from any error type. Never throws.TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to extract message |
string - Error message or fallback message
Usage example
TypeScript
getErrorCode()
Safely extracts error code from aKitError, or returns null for other error
types.
TypeScript
| Name | Type | Description |
|---|---|---|
error | unknown | Error object to extract code |
number | null - Error code or null if not a KitError
Usage example
TypeScript