EVM (Ethereum)

Read & Decode

Read EVM smart contract state and decode ABI-encoded return values with Zafeguard components.

Read & Decode

Components for reading on-chain state and decoding ABI-encoded data — without sending any transactions.

Public RPC URLs enforce rate limits per IP address and can fail under concurrent load. Use a private endpoint (Alchemy, Infura, QuickNode, or self-hosted). See Connecting to any chain.


READ_EVM_CONTRACT

READ_EVM_CONTRACT Workflow Component

Call a read-only (view / pure) contract function using eth_call. Returns the raw ABI-encoded result — pipe into DECODE_EVM_FUNCTION_RESULT to extract the values.

Config

None.

Inputs

FieldTypeDescription
jsonRpcUrlstringJSON-RPC endpoint
contractAddressstringTarget contract address
calldatastringABI-encoded calldata (from BUILD_EVM_CALLDATA)

Outputs

FieldTypeDescription
resultstringRaw ABI-encoded return data (hex)

Example: read ERC-20 balance

BUILD_EVM_CALLDATA (balanceOf ABI, [holder_address])
        │ calldata

READ_EVM_CONTRACT (jsonRpcUrl, token_contract)
        │ result

DECODE_EVM_FUNCTION_RESULT (balanceOf ABI, result)

        ▼ balance (uint256 as string)

DECODE_EVM_FUNCTION_RESULT

DECODE_EVM_FUNCTION_RESULT Workflow Component

ABI-decode the raw bytes returned from a contract call into typed values.

Config

FieldTypeRequiredDescription
functionNamestringYesName of the function whose return type should be used for decoding (e.g. "balanceOf")

Inputs

FieldTypeDescription
abiAbiItem[]ABI containing the function definition
encodedResultstringRaw hex-encoded return data (output of READ_EVM_CONTRACT)

Outputs

Outputs are dynamic — one output per return value in the function's ABI definition. They are indexed as 0, 1, 2, etc. (matching the order of outputs in the ABI).

FieldTypeDescription
0depends on ABIFirst decoded return value
1depends on ABISecond decoded return value (if any)
...depends on ABIAdditional return values

SDK example

import { WorkspaceClient, ComponentModule } from '@zafeguard/caller-sdk';
const workspace = new WorkspaceClient({ apiKey: process.env.ZAFEGUARD_API_KEY! });

// 1. Encode balanceOf(address) call
const calldata = await workspace.call(ComponentModule.BUILD_EVM_CALLDATA, {
  abi: [{
    type: 'function',
    name: 'balanceOf',
    inputs: [{ name: 'account', type: 'address' }],
    outputs: [{ name: '', type: 'uint256' }],
    stateMutability: 'view',
  }],
  args: ['0xHolderAddress'],
}).promise();

// 2. Read contract
const raw = await workspace.call(ComponentModule.READ_EVM_CONTRACT, {
  jsonRpcUrl: 'https://eth-mainnet.g.alchemy.com/v2/KEY',
  contractAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
  calldata: calldata.calldata,
}).promise();

// 3. Decode
const decoded = await workspace.call(ComponentModule.DECODE_EVM_FUNCTION_RESULT, {
  abi: [/* same ABI */],
  encodedResult: raw.result,
}).promise();

console.log(decoded.decoded[0]); // "1000000" (1 USDC)

EVM_KECCAK256

EVM_KECCAK256 Workflow Component

Compute the keccak256 hash of any hex-encoded data. Used for signature preimages, topic filters, and function selectors.

Config

None.

Inputs

FieldTypeDescription
datastringHex-encoded data to hash (0x... or without prefix)

Outputs

FieldTypeDescription
hashstringkeccak256 hash (0x..., 32 bytes)

SDK example

import { WorkspaceClient, ComponentModule } from '@zafeguard/caller-sdk';
const workspace = new WorkspaceClient({ apiKey: process.env.ZAFEGUARD_API_KEY! });

const hash = await workspace.call(ComponentModule.EVM_KECCAK256, {
  data: '0x095ea7b3', // approve(address,uint256) selector input
}).promise();
console.log(hash.hash); // "0x..."

On this page