Skip to main content

Contract interactions

On Ethereum and Avalanche, onContractInteraction() calls you each time an address interacts with a contract it had not interacted with before — a token it receives for the first time, a protocol it starts using.

const eth = cg.explore(cg.networks.ethereum)

eth.onContractInteraction('0x...', async ({ contract, height }) => {
const token = await eth.getTokenData(contract).catch(() => null)
console.log(
`New contract in block ${height}:`,
token ? `${token.name} (${token.symbol})` : contract,
)
})

With a wallet:

const wallet = cg.connect(cg.networks.avalanche, myWallet)
wallet.onContractInteraction(({ contract }) => console.log('First interaction with', contract))
FieldTypeDescription
addressstringThe address being followed
contractstringThe contract the address interacted with
heightnumberBlock height where the interaction happened

Only the first interaction with each contract produces an event; later transactions with the same contract are reported through onTransaction().

This event is not available on UTXO networks, which have no contracts.