with tab1 as (
select
TX_HASH as ids,
ACTION_NAME as Name_of_actions
from near.core.fact_actions_events
),
tab2 AS
(select
TX_HASH as ids,
TX_RECEIVER as sm_contract,
min(BLOCK_TIMESTAMP)
from near.core.fact_transactions
group by 2, 1
order by 1)
select
count(sm_contract)
from tab2
inner join tab1 on tab1.ids = tab2.ids
where Name_of_actions='AddKey'