SDK Reference: EVM Client

This page provides a reference for the evm.Client, the low-level tool for all interactions with EVM-compatible blockchains. The client includes a comprehensive set of read, write, and utility methods for building chain-aware workflows.

Client instantiation

To use the client, you must instantiate it with the ChainSelector ID for the blockchain you intend to interact with.

import "github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/evm"

// Instantiate a client for Ethereum Sepolia
sepoliaClient := &evm.Client{
    ChainSelector: 16015286601757825753, // ethereum-testnet-sepolia
}

For chains that have a constant defined in the SDK, you can also use the ChainSelectorFromName helper for improved readability. See the Chain Selectors section for a full list of available constants.

// Alternatively, use the ChainSelectorFromName helper for better readability
sepoliaSelector, err := evm.ChainSelectorFromName("ethereum-testnet-sepolia")

sepoliaClient := &evm.Client{
    ChainSelector: sepoliaSelector,
}

Read & query methods

These methods are used to read data from the blockchain without creating a transaction.

CallContract

Executes a view or pure function on a smart contract. To use this function, you construct an evm.CallContractRequest object, which holds the details of your call. The function returns a promise that resolves to an evm.CallContractReply containing the data returned by the contract.

Signature:

func (c *Client) CallContract(runtime cre.Runtime, input *CallContractRequest) cre.Promise[*CallContractReply]

evm.CallContractRequest

This is the main input object for the CallContract function. It acts as a wrapper for the call message and an optional block number.

Field
Type
Description
Call*evm.CallMsgContains the actual details of the function call you want to make.
BlockNumber*pb.BigIntOptional. The block number to query. Defaults to latest. Use -2 for latest (the most recent block, which may be subject to re-orgs) or -3 for finalized (a block that is considered immutable and safe from re-orgs).

evm.CallMsg

This struct contains the core details of your onchain call.

Field
Type
Description
From[]byteOptional. The 20-byte address of the sender.
To[]byteThe 20-byte address of the target contract.
Data[]byteThe ABI-encoded byte string for the function call, including the function selector and arguments.

evm.CallContractReply

This is the object returned by the promise when the CallContract function successfully completes.

Field
Type
Description
Data[]byteThe ABI-encoded data returned by the contract call.

BalanceAt

Retrieves the native token balance for a specific account. You provide the account address in an evm.BalanceAtRequest, and the function returns a promise that resolves to an evm.BalanceAtReply containing the balance.

Signature:

func (c *Client) BalanceAt(runtime cre.Runtime, input *BalanceAtRequest) cre.Promise[*BalanceAtReply]

evm.BalanceAtRequest

FieldTypeDescription
Account[]byteThe 20-byte address of the account to query.
BlockNumber*pb.BigIntOptional. The block number to query. Defaults to latest.

evm.BalanceAtReply

FieldTypeDescription
Balance*pb.BigIntThe balance of the account in Wei.

FilterLogs

Queries historical event logs that match a specific set of filter criteria defined in an evm.FilterLogsRequest. The function returns a promise that resolves to an evm.FilterLogsReply containing an array of matching logs.

Signature:

func (c *Client) FilterLogs(runtime cre.Runtime, input *FilterLogsRequest) cre.Promise[*FilterLogsReply]

evm.FilterLogsRequest

Field
Type
Description
FilterQuery*evm.FilterQueryA struct defining the filters for the log query, such as block range, addresses, and topics.

evm.FilterLogsReply

FieldTypeDescription
Logs[]*evm.LogAn array of log objects that match the filter query.

GetTransactionByHash

Retrieves a transaction by its hash. You provide the hash in an evm.GetTransactionByHashRequest, and the function returns a promise that resolves to an evm.GetTransactionByHashReply containing the transaction object.

Signature:

func (c *Client) GetTransactionByHash(runtime cre.Runtime, input *GetTransactionByHashRequest) cre.Promise[*GetTransactionByHashReply]

evm.GetTransactionByHashRequest

FieldTypeDescription
Hash[]byteThe 32-byte hash of the transaction to look up.

evm.GetTransactionByHashReply

FieldTypeDescription
Transaction*evm.TransactionThe transaction object, if found.

GetTransactionReceipt

Fetches the receipt for a transaction given its hash. You provide the hash in an evm.GetTransactionReceiptRequest, and the function returns a promise that resolves to an evm.GetTransactionReceiptReply containing the receipt.

Signature:

func (c *Client) GetTransactionReceipt(runtime cre.Runtime, input *GetTransactionReceiptRequest) cre.Promise[*GetTransactionReceiptReply]

evm.GetTransactionReceiptRequest

FieldTypeDescription
Hash[]byteThe 32-byte hash of the transaction.

evm.GetTransactionReceiptReply

FieldTypeDescription
Receipt*evm.ReceiptThe transaction receipt object, if found.

HeaderByNumber

Retrieves a block header by its number. You provide the block number in an evm.HeaderByNumberRequest, and the function returns a promise that resolves to an evm.HeaderByNumberReply containing the header object.

Signature:

func (c *Client) HeaderByNumber(runtime cre.Runtime, input *HeaderByNumberRequest) cre.Promise[*HeaderByNumberReply]

evm.HeaderByNumberRequest

FieldTypeDescription
BlockNumber*pb.BigIntThe number of the block to retrieve. If nil, retrieves the latest block.

evm.HeaderByNumberReply

FieldTypeDescription
Header*evm.HeaderThe block header object, if found.

EstimateGas

Estimates the gas required to execute a specific transaction. You provide the transaction details in an evm.EstimateGasRequest, and the function returns a promise that resolves to an evm.EstimateGasReply with the gas estimate.

Signature:

func (c *Client) EstimateGas(runtime cre.Runtime, input *EstimateGasRequest) cre.Promise[*EstimateGasReply]

evm.EstimateGasRequest

FieldTypeDescription
Msg*evm.CallMsgThe transaction message to simulate for gas estimation.

evm.EstimateGasReply

FieldTypeDescription
Gasuint64The estimated amount of gas in gas units.

Write methods

WriteReport

Executes a state-changing transaction by submitting a report to a designated receiver contract. You provide the transaction details in an evm.WriteCreReportRequest, and the function returns a promise that resolves to an evm.WriteReportReply with the transaction status.

Signature:

func (c *Client) WriteReport(runtime cre.Runtime, input *WriteCreReportRequest) cre.Promise[*WriteReportReply]

evm.WriteCreReportRequest

FieldTypeDescription
Receiver[]byteThe 20-byte address of the receiver contract to call.
Report*cre.ReportThe report data generated by the DON to be submitted.
GasConfig*evm.GasConfigOptional. Gas limit configuration for the transaction.

evm.WriteReportReply

FieldTypeDescription
TxStatusTxStatusThe final status of the transaction: SUCCESS, REVERTED, or FATAL.
ReceiverContractExecutionStatus*ReceiverContractExecutionStatusOptional. The status of the receiver contract's execution: SUCCESS or REVERTED.
TxHash[]byteOptional. The 32-byte transaction hash of the onchain submission.
TransactionFee*pb.BigIntOptional. The total fee paid for the transaction in Wei.
ErrorMessage*stringOptional. An error message if the transaction failed.

Chain Selectors

A chain selector is a unique identifier for a blockchain network used throughout the CRE platform. The same chain can be referenced in three different ways depending on the context. All three formats are equivalent and refer to the same blockchain.

Understanding the three formats

FormatExampleUsed In
String Name (kebab-case)"ethereum-testnet-sepolia"project.yaml configuration files, workflow config.json files, ChainSelectorFromName() helper
Go Constant (PascalCase)evm.EthereumTestnetSepoliaDirectly in your workflow Go code when you need the numeric ID
Numeric ID (uint64)16015286601757825753evm.Client instantiation in Go code

Complete chain selector reference

This table shows all three equivalent formats for each supported chain:

Chain
String Name
Go Constant
Numeric ID
Arbitrum Oneethereum-mainnet-arbitrum-1evm.EthereumMainnetArbitrum14949039107694359620
Arbitrum Sepoliaethereum-testnet-sepolia-arbitrum-1evm.EthereumTestnetSepoliaArbitrum13478487238524512106
Avalanche Mainnetavalanche-mainnetevm.AvalancheMainnet6433500567565415381
Avalanche Fujiavalanche-testnet-fujievm.AvalancheTestnetFuji14767482510784806043
Base Mainnetethereum-mainnet-base-1evm.EthereumMainnetBase115971525489660198786
Base Sepoliaethereum-testnet-sepolia-base-1evm.EthereumTestnetSepoliaBase110344971235874465080
BNB Chain Mainnetbinance_smart_chain-mainnetevm.BinanceSmartChainMainnet11344663589394136015
BNB Chain Testnetbinance_smart_chain-testnetevm.BinanceSmartChainTestnet5142893604156789321
Ethereum Mainnetethereum-mainnetevm.EthereumMainnet5009297550715157269
Ethereum Sepoliaethereum-testnet-sepoliaevm.EthereumTestnetSepolia16015286601757825753
OP Mainnetethereum-mainnet-optimism-1evm.EthereumMainnetOptimism13734403246176062136
OP Sepoliaethereum-testnet-sepolia-optimism-1evm.EthereumTestnetSepoliaOptimism15224473277236331295
Polygon Mainnetpolygon-mainnetevm.PolygonMainnet4051577828743386545
Polygon Amoypolygon-testnet-amoyevm.PolygonTestnetAmoy16281711391670634445

Usage examples

In your project.yaml file (RPC configuration):

local-simulation:
  rpcs:
    - chain-name: ethereum-testnet-sepolia # String name for RPC endpoint
      url: https://your-rpc-url.com

In your workflow's config.json file (workflow-specific settings):

Your workflow configuration can include chain selector names as part of your custom config structure. For example:

{
  "schedule": "*/30 * * * * *",
  "evms": [
    {
      "storageAddress": "0x1234...",
      "chainName": "ethereum-testnet-sepolia" // Use string name in your config
    }
  ]
}

In your workflow Go code (Option 1 - Using the constant):

evmClient := &evm.Client{
    ChainSelector: evm.EthereumTestnetSepolia,  // Direct constant
}

In your workflow Go code (Option 2 - Using the helper function with config):

// Read chain name from your config and convert to numeric selector
sepoliaSelector, err := evm.ChainSelectorFromName(config.Evms[0].ChainName)
if err != nil {
    return err
}
evmClient := &evm.Client{
    ChainSelector: sepoliaSelector,
}

ChainSelectorFromName

A helper function to convert a string name to its numeric chain selector ID.

Signature:

func ChainSelectorFromName(name string) (uint64, error)

Parameters:

  • name: The kebab-case string identifier for the chain (e.g., "ethereum-testnet-sepolia")

Returns:

  • The numeric chain selector ID
  • An error if the chain name is not recognized

Example:

selector, err := evm.ChainSelectorFromName("ethereum-testnet-sepolia")
if err != nil {
    return fmt.Errorf("invalid chain name: %w", err)
}
// selector now holds 16015286601757825753

Get the latest Chainlink content straight to your inbox.