Introduction to Transaction Traces
Traces are used to record the transaction execution details. It can be used to debug or retrieve more information (like getting contract addresses created within transaction execution).
Trace Types
Call
The trace is recorded for all Call
operations, including balance transferring or contract calling, executed either by the transaction itself or inside a contract.
pub struct Call {
/// The sending account.
pub from: Address,
/// The destination account.
pub to: Address,
/// The value transferred to the destination account.
pub value: U256,
/// The gas available for executing the call.
pub gas: U256,
/// The input data provided to the call.
pub input: Bytes,
/// The type of the call.
pub call_type: CallType,
}
pub enum CallType {
/// Not a CALL.
None,
/// CALL.
Call,
/// CALLCODE.
CallCode,
/// DELEGATECALL.
DelegateCall,
/// STATICCALL
StaticCall,
}
If a transaction itself is calling a contract (to
is a contract address), this trace will always be the first one in the trace list of this transaction.
call_type
can never be None
for Call
traces.
Note that gas
is the "provided" gas for the execution of the callee, so the gas overhead has been deducted. For example, it is 0
for a simple balance transferring transaction of 21000
gas, because the base gas cost (21000
) has been deducted in advance. The gas cost for call-related opcodes (CALL
, DELEGATECALL
, e.t.c.) or the 1/64 gas reserve for calling are also deducted in advance during contract execution.
CallResult
The trace is recorded after a Call
operation finishes.
pub struct CallResult {
/// The outcome of the result
pub outcome: Outcome,
/// The amount of gas left
pub gas_left: U256,
/// Output data
pub return_data: Bytes,
}
pub enum Outcome {
Success,
Reverted,
Fail,
}
Create
The trace is recorded for all operations that create contracts, including executing contract creation transactions or successfully executing the CREATE
/CREATE2
opcode.
pub struct Create {
/// The address of the creator.
pub from: Address,
/// The value with which the new account is endowed.
pub value: U256,
/// The gas available for the creation init code.
pub gas: U256,
/// The init code.
pub init: Bytes,
}
Similar to Call
, the gas
is the "provided" gas for the Create
operation.