@somnia-chain/markets-sdk


@somnia-chain/markets-sdk / chains / createBridgeTransfer

Function: createBridgeTransfer()

createBridgeTransfer(params): BridgeTransfer

Defined in: packages/sdk/src/chains/bridge/transfer.ts:107

Build the unsigned transactions that bridge amount of token from one Somnia network to another.

Returns a plan rather than a single transaction, because what it takes depends on the route: a collateral leg needs an ERC-20 approve before transferRemote, while native and synthetic legs need only the bridge call. approveStep is absent when there is nothing to approve — branch on it and it narrows, no non-null assertion needed:

Details

  • params: Token, direction, amount, recipient, and the optional gas/approval knobs.
  • Returns: The transfer: bridgeStep (the transferRemote call), approveStep (the ERC-20 approval on a collateral route, absent otherwise), and both sides' token details.

Gotchas

  • Throws If the amount is not positive, the recipient isn't an address, the two chains are the same, or that token has no route between them. The message names what IS supported.

Example (Planning a bridge transfer)

ts
import { BridgeToken, ChainId, createBridgeTransfer } from "@somnia-chain/markets-sdk/chains";

const plan = createBridgeTransfer({
  token: BridgeToken.WBTC,
  from: ChainId.somniaShannon,
  to: ChainId.hidekiTestnet,
  amount: 100_000_000n, // 1 WBTC — 8 decimals, not 18
  recipient: account.address,
});

if (plan.approveStep) {
  const hash = await walletClient.sendTransaction({ ...plan.approveStep, account });
  await publicClient.waitForTransactionReceipt({ hash }); // the approval must LAND first
}
const hash = await walletClient.sendTransaction({ ...plan.bridgeStep, account });
await publicClient.waitForTransactionReceipt({ hash });

On a Somnia node, sendBridgeStep does the same in one round-trip per transaction via realtime_sendRawTransaction.

Delivery is asynchronous: transferRemote only escrows and dispatches. The relayer delivers on the far side seconds later, and this bridge does not meter that gas — see SOMNIA_BRIDGE.

Parameters

params

CreateBridgeTransferParams

Returns

BridgeTransfer