Function: simulateEVMTx()
simulateEVMTx(
chain:EVMChain,unsigned:UnsignedEVMTx,opts?:SimulateEVMTxOptions):Promise<SimulateEVMTxResult>
Defined in: cct/evm/simulate.ts:150
Simulates the tx in unsigned with eth_call from opts.from, or else the tx's own from,
and decodes any revert to its error name, with no ABI from the caller.
Parameters
| Parameter | Type | Description |
|---|---|---|
chain | EVMChain | Chain to simulate on. |
unsigned | UnsignedEVMTx | A generateUnsigned* result holding one transaction. |
opts? | SimulateEVMTxOptions | Optional from override, see SimulateEVMTxOptions. |
Returns
Promise<SimulateEVMTxResult>
{ success: true }, or the revert's errorName, errorArgs and raw revertData.
Remarks
Every CCT op gates on msg.sender, so a tx with no from either way is rejected
rather than simulated from the zero address. A builder given sender already rejects an
unauthorized one with CCTParamsInvalidError; built without it, the same check comes back
here as a named revert (OnlyCallableByOwner, Unauthorized). Deploy txs (no to) simulate
as a CREATE.
Throws
CCTParamsInvalidError if unsigned doesn't hold exactly one transaction, or
neither opts nor the tx has a valid from
Throws
The raw provider error on an RPC or transport failure, which says nothing about the tx
(as in core evm/simulate.ts)
Example
// built without `sender` for a multisig, simulated from the Safe that will sign it
const unsigned = await cct.generateUnsignedProvideLiquidity({ poolAddress, amount })
const result = await simulateEVMTx(cct.chain, unsigned, { from: safeAddress })
if (!result.success) console.log(result.errorName ?? result.revertData, result.errorArgs)