@somnia-chain/markets-sdk / chains / toEip1193Transaction
Function: toEip1193Transaction()
toEip1193Transaction(
step,options?):RpcTransactionRequest
Defined in: packages/sdk/src/chains/bridge/transfer.ts:208
A BridgeTransaction as the JSON-safe object a browser wallet's
eth_sendTransaction takes — typed as viem's own RpcTransactionRequest
(hex quantities throughout), with only from/to/data/value set. Every
field is a hex string, so the result survives JSON.stringify, a server →
browser boundary, or a postMessage — which a raw BridgeTransaction
does not: its value is a bigint, and JSON.stringify throws on bigints.
What it deliberately DROPS is as important as what it converts:
chainId—eth_sendTransactionhas no chain field; an EIP-1193 wallet signs on its active chain. Switch first withwallet_switchEthereumChain(using the transaction'schainId) or it goes out on whatever network the wallet happens to be on.description— a UI label, not a transaction field; some wallets reject requests carrying unknown keys.
No gas, no nonce, no fees, same as the input: the wallet estimates and
fills those. Callers on viem don't need this at all —
walletClient.sendTransaction({ ...plan.bridgeStep, account }) takes it
as-is; this exists for the raw provider.request(...) path and for moving a
server-built plan across a JSON boundary.
Details
step: The planner transaction (or anything withto/data/value) to convert.options:from— the sender to pin; omit to let the wallet choose.- Returns: The
eth_sendTransactionparams object, JSON-safe by construction.
Example (Preparing an EIP-1193 transaction)
import { BridgeToken, ChainId, createBridgeTransfer, toEip1193Transaction } from "@somnia-chain/markets-sdk/chains";
import { numberToHex } from "viem";
const plan = createBridgeTransfer({
token: BridgeToken.STT,
from: ChainId.somniaShannon,
to: ChainId.hidekiTestnet,
amount: 1_000_000_000_000_000_000n, // 1 STT
recipient,
});
const tx = toEip1193Transaction(plan.bridgeStep, { from: sender });
tx.value; // "0xde0b6b3a7640000" — hex wei, not a bigint
JSON.stringify(tx); // safe: every field is a string
// The wallet signs on its ACTIVE chain — put it on the step's chain first.
await provider.request({
method: "wallet_switchEthereumChain",
params: [{ chainId: numberToHex(plan.bridgeStep.chainId) }],
});
await provider.request({ method: "eth_sendTransaction", params: [tx] });
Parameters
step
Pick<BridgeTransaction, "to" | "data" | "value">
options?
from?
`0x${string}`
Returns
RpcTransactionRequest