# 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.

Canonical HTML: <https://determica.com/docs/functions/try_read_contract_at>

- Kind: scalar function
- Category: [Chain reads](/docs/category/chain-reads.md)
- Tags: RPC

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.

## Overload 1: try_read_contract_at(CLIENT, ADDRESS, JSON, VARCHAR, BIGINT, ...args)

```sql
try_read_contract_at(CLIENT, ADDRESS, JSON, VARCHAR, BIGINT, ...args)
```

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

- Kind: scalar
- Execution context: Live RPC
- Behavior: Transform
- Execution modes: Live Client
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: External State
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: network_io

### Requirements

- attached_live_client
- rpc

### Risks

- provider_limits
- chain_reorganization

### Inputs

- `client` (CLIENT; required; positional) — Live, pinned, or retained execution CLIENT. Pinned and execution state require the resolved block selector to be latest and reject other selectors.
- `to` (ADDRESS; required; positional) — Contract address to call.
- `abi` (JSON; required; positional) — Literal or foldable JSON ABI used for argument encoding and output types.
- `function_name` (VARCHAR; required; positional) — Literal or foldable ABI function name.
- `block_number` (BIGINT; required; positional) — Non-negative BIGINT block number. NULL produces NULL without issuing an RPC call.
- `function_args` (ANY; positional; variadic) — 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.

### Returns

ABI-derived scalar or STRUCT

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

- `result` (ABI-derived scalar or STRUCT; dynamic) — The ABI-decoded value, or NULL when the call reverts, returns no data or does not decode.

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

### Examples

_Named parameters · Needs RPC · RPC required_

```sql
-- 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;
```
