try_read_contract_at

Calls a contract function at an explicit block number like read_contract_at; a revert, an address without code or an undecodable return gives NULL instead of an error. A transport, rate-limit or archive failure raises.

Scalar functionLive RPC RPC

Example

Live RPC

-- symbol() of each token, NULL where the call reverts or does not decode as string
WITH tokens(token) AS (
  VALUES ('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'::ADDRESS), -- Ethereum mainnet WETH
         ('0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2'::ADDRESS)  -- Ethereum mainnet MKR: bytes32 symbol
)
SELECT
  token,
  try_read_contract_at(
    $client,
    token,
    '[{"type":"function","name":"symbol","inputs":[],"outputs":[{"name":"","type":"string"}],"stateMutability":"view"}]'::JSON,
    'symbol()',
    21000000
  ) AS symbol
FROM tokens;

API reference

try_read_contract_at(CLIENT, ADDRESS, JSON, VARCHAR, BIGINT, ...args) # RPC required

As read_contract_at. A revert, empty return data or a decode failure gives NULL; RPC transport failures, encoding and argument errors still raise.

Inputs

Name Type Use
client CLIENT

Live, pinned, or retained execution CLIENT. Pinned and execution state require the resolved block selector to be latest and reject other selectors.

required positional
to ADDRESS

Contract address to call.

required positional
abi JSON

Literal or foldable JSON ABI used for argument encoding and output types.

required positional
function_name VARCHAR

Literal or foldable ABI function name.

required positional
block_number BIGINT

Non-negative BIGINT block number. NULL produces NULL without issuing an RPC call.

required positional
...args dynamic ANY

Pass one SQL value per ABI input. The ABI determines how many values are accepted and how each value is cast. The ABI and function name must be literal or foldable so the return type can be inferred during planning.

positional

Returns

Name Type
result dynamic ABI-derived scalar or STRUCT

The ABI-decoded value, or NULL when the call reverts, returns no data or does not decode.