Skip to content

Read your own contract ​

Start from a contract's address, find out what you can call on it, and read your first values from it.

The example here is Chainlink's ETH/USD price feed on Ethereum. Replace its address with yours.

1. Name the contract ​

Give the address a name with let. An address always starts with its chain, as ethereum:, base: or arbitrum: (Chains and costs lists them all).

cql
let feed = ethereum:0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;

from feed as f
| project { contract: f.$address }

Open in workbench →

Run this. You get one row with the address in it.

2. See what it offers ​

There are two ways to see the functions you can call:

  • In the editor. Type f. inside the project. The completion list shows the contract's functions, read from its verified ABI. Hover a function to see its arguments and what it returns.
  • In the Contract tab. Hover the address in the Results grid and click the ⓘ beside it. The Contract tab lists every function and event, and says where the ABI came from.

You write nothing about the ABI yourself. CQL finds the verified ABI, and it follows a proxy to its implementation if it has to. If CQL finds no ABI, the editor underlines the call with CQL3008. Then see Read a contract nobody has verified, or call the function by its signature with .call().

3. Read some values ​

Call the functions you want inside the project, one column each:

cql
let feed = ethereum:0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;

from feed at 26_000_000 as f
| project {
    description: f.description(),
    decimals:    f.decimals(),
    ethUsd:      format(f.latestAnswer(), 8)
  }

Open in workbench →

descriptiondecimalsethUsd
ETH / USD82451.31

at 26_000_000 reads the contract at that block, so you get the same row every time. Remove it to read the newest block. latestAnswer() returns a whole number with 8 decimals, which decimals() says. format(…, 8) moves the decimal point so the price reads in dollars.

Next steps ​