Estimate Gas for Raw Transactions
estimateGas estimates the gas cost of a raw (unsigned) transaction before execution. The typical flow is:
- Call any service method with
raw: trueto get an unsigned transaction payload. - Pass that payload to
estimateGasto get a chain-specific gas estimate.
estimateGas is available as an instance method on three services — all delegate to SpokeService.estimateGas internally:
sodax.swaps.estimateGas(params)— for swap / intent transactionssodax.moneyMarket.estimateGas(params)— for money market transactionssodax.spoke.estimateGas(params)— for any raw spoke transaction (approvals, deposits, etc.)
Method signature
All three methods share the same signature:EstimateGasParams<C> is defined in packages/sdk/src/shared/types/spoke-types.ts:
Return type: GetEstimateGasReturnType<C>
The return type is conditional on the source chain’s chain family. The concrete type per chain family is:
The full type definitions are in
packages/types/src/common/common.ts.
raw: true / raw: false — the WalletProviderSlot<K, Raw> constraint
estimateGas always takes a raw transaction, so you must first get one by calling a service method with raw: true. The WalletProviderSlot<K, Raw> type in packages/types/src/common/common.ts enforces this at compile time:
raw: true→walletProvideris forbidden (typed asnever). The method returns an unsigned payload (TxReturnType<K, true>, e.g.EvmRawTransaction).raw: false→walletProvideris required and chain-narrowed toGetWalletProviderType<K>. The method broadcasts and returns a tx hash.
packages/wallet-sdk-core — never constructed manually in caller code.
ChainKeys.* constants
All chain constants live under ChainKeys.* from @sodax/sdk. There are no separate *_CHAIN_ID exports.
Error handling: Result<T>
Every estimateGas call returns Promise<Result<GetEstimateGasReturnType<C>>> where Result<T> is:
result.ok before accessing result.value.