Skip to main content

Estimate Gas for Raw Transactions

estimateGas estimates the gas cost of a raw (unsigned) transaction before execution. The typical flow is:
  1. Call any service method with raw: true to get an unsigned transaction payload.
  2. Pass that payload to estimateGas to 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 transactions
  • sodax.moneyMarket.estimateGas(params) — for money market transactions
  • sodax.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: truewalletProvider is forbidden (typed as never). The method returns an unsigned payload (TxReturnType<K, true>, e.g. EvmRawTransaction).
  • raw: falsewalletProvider is required and chain-narrowed to GetWalletProviderType<K>. The method broadcasts and returns a tx hash.
Wallet providers are obtained from 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:
Always check result.ok before accessing result.value.

Examples

Example 1: Estimate gas for a swap intent transaction (EVM spoke)
Example 2: Estimate gas for a money market supply transaction (EVM spoke)
Example 3: Estimate gas for an approval transaction
Example 4: Non-EVM chain — Sui
Example 5: Stacks