Skip to main content

Bridge & Gas API

The Bridge and Gas API provides 6 methods -- 4 for bridging tokens across chains and 2 for estimating gas costs.

Bridge Methods

MethodParametersReturnsDescription
getBridgeQuote(request)request: BridgeQuoteRequestApiResponse<BridgeQuote>Fetches a price quote for bridging tokens across chains.
executeBridge(request)request: BridgeExecuteRequestApiResponse<BridgeTransaction>Executes a cross-chain bridge using a previously obtained quote.
getBridgeStatus(bridgeId)bridgeId: stringApiResponse<BridgeTransaction>Returns the current status of a bridge transaction.
getSupportedBridgeRoutes(fromChain?, toChain?)fromChain?: string, toChain?: stringApiResponse<BridgeRoute[]>Lists supported bridge routes between chains.

Gas Methods

MethodParametersReturnsDescription
getGasEstimate(request)request: GasEstimateRequestApiResponse<GasEstimate>Estimates the gas cost for a specific transaction.
getGasPrice(chainId)chainId: stringApiResponse<GasPrice>Returns current gas prices for a chain.

Types

BridgeQuoteRequest

interface BridgeQuoteRequest {
/** Source chain ID. */
fromChain: string;
/** Destination chain ID. */
toChain: string;
/** Token to bridge. Use "native" for chain-native currency. */
token: string;
/** Amount to bridge (human-readable). */
amount: string;
/** Sender wallet address. */
senderAddress: string;
/** Recipient address on the destination chain. Defaults to senderAddress. */
recipientAddress?: string;
}

BridgeQuote

interface BridgeQuote {
quoteId: string;
fromChain: string;
toChain: string;
token: string;
fromAmount: string;
/** Estimated amount received on the destination chain. */
toAmount: string;
/** Bridge fee. */
fee: string;
feeUsd: string;
/** Estimated gas cost on source chain. */
gasEstimate: string;
gasEstimateUsd: string;
/** Estimated time for the bridge in seconds. */
estimatedTime: number;
/** Bridge protocol used (e.g. "LayerZero", "Wormhole"). */
bridge: string;
expiresAt: string;
}

BridgeExecuteRequest

interface BridgeExecuteRequest {
/** Quote ID from a previous getBridgeQuote call. */
quoteId: string;
/** Sender wallet address. */
senderAddress: string;
}

BridgeTransaction

interface BridgeTransaction {
bridgeId: string;
fromChain: string;
toChain: string;
token: string;
fromAmount: string;
toAmount?: string;
fee: string;
/** Transaction hash on the source chain. */
sourceTxHash?: string;
/** Transaction hash on the destination chain. */
destinationTxHash?: string;
status: 'pending' | 'source_confirmed' | 'bridging' | 'completed' | 'failed';
bridge: string;
createdAt: string;
completedAt?: string;
}

BridgeRoute

interface BridgeRoute {
fromChain: string;
fromChainName: string;
toChain: string;
toChainName: string;
/** Tokens supported on this route. */
tokens: string[];
/** Bridge protocols available for this route. */
bridges: string[];
/** Estimated transfer time in seconds. */
estimatedTime: number;
}

GasEstimateRequest

interface GasEstimateRequest {
/** Chain ID. */
chainId: string;
/** Sender address. */
from: string;
/** Recipient address. */
to: string;
/** Transaction value (in wei or native units). */
value?: string;
/** Transaction calldata. */
data?: string;
}

GasEstimate

interface GasEstimate {
chainId: string;
/** Estimated gas units required. */
gasLimit: string;
/** Gas price in native currency (human-readable). */
gasPriceNative: string;
/** Gas cost in USD. */
gasCostUsd: string;
/** Recommended max fee per gas (EIP-1559). */
maxFeePerGas?: string;
/** Recommended max priority fee (EIP-1559). */
maxPriorityFeePerGas?: string;
}

GasPrice

interface GasPrice {
chainId: string;
chainName: string;
/** Slow gas price (longer confirmation). */
slow: GasPriceTier;
/** Standard gas price. */
standard: GasPriceTier;
/** Fast gas price (quicker confirmation). */
fast: GasPriceTier;
/** Base fee (EIP-1559 chains). */
baseFee?: string;
/** Last updated timestamp. */
updatedAt: string;
}

interface GasPriceTier {
/** Gas price in Gwei. */
gwei: string;
/** Estimated confirmation time in seconds. */
estimatedSeconds: number;
/** Estimated cost for a simple transfer in USD. */
transferCostUsd: string;
}

Examples

Get a Bridge Quote

const quoteRes = await engine.getBridgeQuote({
fromChain: 'ethereum',
toChain: 'polygon',
token: 'USDC',
amount: '1000',
senderAddress: '0xABC...',
});

if (quoteRes.success && quoteRes.data) {
const q = quoteRes.data;
console.log(`Bridge 1000 USDC: ETH -> Polygon`);
console.log(`Receive: ~${q.toAmount} USDC`);
console.log(`Fee: ${q.fee} ($${q.feeUsd})`);
console.log(`Time: ~${q.estimatedTime}s via ${q.bridge}`);
}

Execute a Bridge

const execRes = await engine.executeBridge({
quoteId: quoteRes.data!.quoteId,
senderAddress: '0xABC...',
});

if (execRes.success && execRes.data) {
console.log('Bridge submitted:', execRes.data.bridgeId);
}

Poll Bridge Status

let bridge = execRes.data!;
while (bridge.status !== 'completed' && bridge.status !== 'failed') {
await new Promise(r => setTimeout(r, 10000));
const poll = await engine.getBridgeStatus(bridge.bridgeId);
if (poll.success && poll.data) {
bridge = poll.data;
console.log('Bridge status:', bridge.status);
}
}

if (bridge.status === 'completed') {
console.log(`Bridged! Dest tx: ${bridge.destinationTxHash}`);
}

List Bridge Routes

const routesRes = await engine.getSupportedBridgeRoutes('ethereum');

if (routesRes.success && routesRes.data) {
for (const r of routesRes.data) {
console.log(`${r.fromChainName} -> ${r.toChainName}`);
console.log(` Tokens: ${r.tokens.join(', ')}`);
console.log(` Bridges: ${r.bridges.join(', ')}`);
console.log(` Time: ~${r.estimatedTime}s`);
}
}

Estimate Gas

const gasRes = await engine.getGasEstimate({
chainId: 'ethereum',
from: '0xABC...',
to: '0xDEF...',
value: '1000000000000000000', // 1 ETH in wei
});

if (gasRes.success && gasRes.data) {
console.log(`Gas limit: ${gasRes.data.gasLimit}`);
console.log(`Cost: ~$${gasRes.data.gasCostUsd}`);
}

Get Current Gas Prices

const priceRes = await engine.getGasPrice('ethereum');

if (priceRes.success && priceRes.data) {
const g = priceRes.data;
console.log(`Ethereum gas prices (updated ${g.updatedAt}):`);
console.log(` Slow: ${g.slow.gwei} Gwei (~${g.slow.estimatedSeconds}s)`);
console.log(` Standard: ${g.standard.gwei} Gwei (~${g.standard.estimatedSeconds}s)`);
console.log(` Fast: ${g.fast.gwei} Gwei (~${g.fast.estimatedSeconds}s)`);
}

Next Steps

  • Swap API -- swap tokens on the same chain.
  • Wallet API -- send transactions and check balances.