simulate
Gas-simulate an unsigned transaction. Returns the simulated gas usage scaled by a default multiplier.
Signature
function simulate(
client: Client,
parameters: {
simulate: SimulateRequest
scale?: number
height?: number
},
): Promise<SimulateResponse>Example
import { createPublicClient, createTransport, testnet } from "@left-curve/sdk"
import type { Address } from "@left-curve/sdk"
const client = createPublicClient({ chain: testnet, transport: createTransport() })
const sender: Address = "0x1234567890abcdef1234567890abcdef12345678"
const { gasLimit, gasUsed } = await client.simulate({
simulate: {
sender,
msgs: [
{
transfer: {
"0xabcdef1234567890abcdef1234567890abcdef12": { dango: "1000000" },
},
},
],
data: null,
},
})Parameters
simulate — SimulateRequest. The unsigned transaction shape: { sender, msgs, data }.
scale — number, optional, default 1.3. Multiplier applied to gasUsed before returning.
height — number, optional. Block height to simulate at. Default 0 (latest).
Returns
SimulateResponse — { gasLimit, gasUsed }. gasUsed is Math.round(rawGasUsed * scale).
Notes
- The 1.3× scaling factor is the default safety margin used by
signAndBroadcastTx. Passscale: 1to see the unmodified estimate. - Simulation runs the messages against the latest state and may differ from the eventual on-chain result if the state changes between simulation and broadcast.
See also
signAndBroadcastTx— usessimulateinternallybroadcastTxSync