Skip to main content

contract_logs

Schema: public

Description

This table contains parsed information about logs emitted to smart contracts. This parsed data includes the name of the emitted event along with property names/values emitted by each event. This is useful for understanding important events that have occurred due to contract invocations. Where-as contract_calls are good for determining how a contract is being invoked, contract_logs allow a more holistic view of events happening within a contract regardless of entry point. Contract logs also catch important events emitted as part of delegate calls where-as contract calls only show top-level contract invocations

Columns

Column NameData TypeDescription
idbpchar(44)The unique identifier for the contract log.
consensus_timetimestamptzThe timestamp of the contract log's consensus time.
chaintextThe blockchain this contract log belongs to.
transaction_hashtextThe unique hash of the transaction containing the contract log.
transaction_sendertextThe sender of the transaction containing the contract log.
transaction_recipienttextThe recipient of the transaction containing the contract log.
contracttextThe address of the smart contract.
metric_nametextThe name of the metric associated with the contract log.
property_nametextThe name of the property associated with the contract log.
property_typetextThe type of the property associated with the contract log.
valnumericThe value associated with the contract log.
string_valtextThe string value associated with the contract log.
log_indexint4The index of the contract log.

Examples

Get total amount of USDT on Avalanche transferred each hour over the last 12 hours
with decimals as (
select (am.context->>'decimals')::int as decimals
from address_metadata am
where am.account = '0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7'
)
select
time_bucket('1 hour'::interval, cl.consensus_time) as time,
sum(lib_math.decimaled_amount(cl.val, d.decimals)) val
from contract_logs cl
cross join decimals d
where cl.consensus_time between now() - '12 hours'::interval and now()
and cl.contract = '0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7'
and cl.metric_name = 'Transfer'
and cl.property_name = 'value'
group by time
order by time;

Note: this query uses our decimaled_amount function to convert from raw values to human-friendly decimal amounts.