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 Name | Data Type | Description |
---|---|---|
id | bpchar(44) | The unique identifier for the contract log. |
consensus_time | timestamptz | The timestamp of the contract log's consensus time. |
chain | text | The blockchain this contract log belongs to. |
transaction_hash | text | The unique hash of the transaction containing the contract log. |
transaction_sender | text | The sender of the transaction containing the contract log. |
transaction_recipient | text | The recipient of the transaction containing the contract log. |
contract | text | The address of the smart contract. |
metric_name | text | The name of the metric associated with the contract log. |
property_name | text | The name of the property associated with the contract log. |
property_type | text | The type of the property associated with the contract log. |
val | numeric | The value associated with the contract log. |
string_val | text | The string value associated with the contract log. |
log_index | int4 | The 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.