SDK Reference: EVM Log Trigger

The EVM Log Trigger fires when a specific log (event) is emitted by an onchain smart contract.

evm.LogTrigger

Creates the EVM log trigger instance.

import (
    "github.com/ethereum/go-ethereum/common"
    "github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/evm"
)

// The first argument is the Chain Selector for the network to monitor.
// 16015286601757825753 is the selector for Sepolia testnet.
logTrigger := evm.LogTrigger(16015286601757825753, &evm.FilterLogTriggerRequest{
    Addresses: [][]byte{
        common.HexToAddress("0x123...abc").Bytes(),
    },
    // This example filters for a Transfer event signature
    Topics: []*evm.TopicValues{
        {
            Values: [][]byte{
                // Keccak256 hash of "Transfer(address,address,uint256)"
                common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef").Bytes(),
            },
        },
    },
    Confidence: evm.ConfidenceLevel_CONFIDENCE_LEVEL_FINALIZED,
})

evm.FilterLogTriggerRequest

The configuration struct for the EVM log trigger.

Field
Type
Description
Addresses[][]byteA list of contract addresses to monitor, as 20-byte arrays.
Topics[]*evm.TopicValuesA fixed 4-element array to filter event topics. The first element contains event signatures, and the next three elements contain indexed argument values. An empty array element acts as a wildcard.
ConfidenceConfidenceLevelThe block confirmation level to monitor. Can be:
  • evm.ConfidenceLevel_CONFIDENCE_LEVEL_SAFE (default): A block that is considered unlikely to be reorged but is not yet irreversible.
  • evm.ConfidenceLevel_CONFIDENCE_LEVEL_LATEST: The most recent block. This is the fastest but least secure, as the block could be orphaned. Best for non-critical, time-sensitive actions.
  • evm.ConfidenceLevel_CONFIDENCE_LEVEL_FINALIZED: A block that is considered irreversible. This is the safest option, as the event is guaranteed to be on the canonical chain, but it requires waiting longer for finality.

evm.Log

The generic payload passed to the callback function for any EVM log.

Fields:

FieldTypeDescription
Address[]byteAddress of the contract that emitted the log.
Topics[][]byteIndexed log fields (including event signature).
Data[]byteABI-encoded non-indexed log data.
TxHash[]byteHash of the transaction.
BlockHash[]byteHash of the block.
BlockNumber*pb.BigIntThe block number containing the log.
TxIndexuint32Index of the transaction within the block.
Indexuint32Index of the log within the block.
EventSig[]byteKeccak256 hash of the event signature.
RemovedboolTrue if the log was removed during a reorg.

Callback Function

Your callback function for EVM log triggers must conform to this signature:

func onEvmTrigger(config *Config, runtime cre.Runtime, log *evm.Log) (*YourReturnType, error)

Parameters:

  • config: Your workflow's static configuration struct.
  • runtime: The runtime object.
  • log: The generic evm.Log payload. You will need to manually decode the Topics and Data fields based on the event ABI.

Get the latest Chainlink content straight to your inbox.