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 | [][]byte | A list of contract addresses to monitor, as 20-byte arrays. |
Topics | []*evm.TopicValues | A 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. |
Confidence | ConfidenceLevel | The block confirmation level to monitor. Can be:
|
evm.Log
The generic payload passed to the callback function for any EVM log.
Fields:
| Field | Type | Description |
|---|---|---|
Address | []byte | Address of the contract that emitted the log. |
Topics | [][]byte | Indexed log fields (including event signature). |
Data | []byte | ABI-encoded non-indexed log data. |
TxHash | []byte | Hash of the transaction. |
BlockHash | []byte | Hash of the block. |
BlockNumber | *pb.BigInt | The block number containing the log. |
TxIndex | uint32 | Index of the transaction within the block. |
Index | uint32 | Index of the log within the block. |
EventSig | []byte | Keccak256 hash of the event signature. |
Removed | bool | True 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 genericevm.Logpayload. You will need to manually decode theTopicsandDatafields based on the event ABI.