Appearance
Finding a contract's ABI
To call s.getPooledEthByShares(1e18), CQL needs the contract's ABI, and it looks in four places in a fixed order.
Most of the time you write nothing and it just works. The address is verified somewhere public, and CQL fetches the ABI. This page is for the other times: a contract that nobody verified, a proxy, or an interface that you already have on disk. It also helps you read what the workbench tells you about where an ABI came from.
The four places, in order
- An ABI in the query.
let lido = abi [...]declares one inline, as JSON or as a list of signatures, andwith { abi: lido }uses it. - A built-in.
erc20,erc721,erc1155,erc4626andmulticall3are always available by name:with { abi: erc20 }. - Your library. CQL searches for a name in quotes, such as
with { abi: 'lido' }, in the ABIs that you uploaded. They live under ABI library in the workbench's left rail, below Recent. Your library says how to add one. - The address itself. With no
abiat all, CQL asks the public verification services for the source that was verified at that address. It asks Sourcify first, then Etherscan, and takes the ABI of that source.
The first three are yours to write. The fourth is the default. After CQL resolves an ABI, the ABI stays with that address, so the second query against the same contract does not wait.
cql
let lido = abi ['function getPooledEthByShares(uint256) view returns (uint256)'];
let stETH = ethereum:0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84;
from stETH with { abi: lido } as s // 1: inline
| project { ethPerShare: format(s.getPooledEthByShares(1e18), 18) }cql
let stETH = ethereum:0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84;
from stETH with { abi: erc20 } as t // 2: built-in
| project { supply: format(t.totalSupply(), 18) }cql
let stETH = ethereum:0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84 with { abi: 'lido' };
from stETH as s // 3: your library, attached to the name
| project { ethPerShare: format(s.getPooledEthByShares(1e18), 18) }with { abi: … } can sit on the let, on the from, or after a single call. The innermost one wins. with options has the rules.
An address that the query finds
The four places are for an address that you write in the query: a let, a from, or a column that holds the address of a from. Some addresses come from the chain while the query runs. A call can give back an address or a list of them, and expand makes one row for each item of a list. Such an address has no ABI until you attach one, and CQL does not guess one.
Attach the ABI where the address starts. After that, every call through it uses that ABI:
cql
let vault = abi ['function getDestinations() view returns (address[])'];
let destAbi = abi ['function getDebt() view returns (uint256)'];
let autoETH = ethereum:0x0A2b94F6871c1D7A32Fe58E1ab5e6deA2f114E56;
from autoETH with { abi: vault } as pool
| expand pool.getDestinations() as dest with { abi: destAbi } // each item gets destAbi
| project { dest, debt: dest.getDebt() }The ABI stays with the column. A later project that copies or renames dest, a distinct, a summarize … by dest, a where, an order and a join all keep it.
There are two more places to attach it:
- On a column that you make.
extend v = dest with { abi: destAbi }. For a call's result, put the call in parentheses:project { first: (pool.getDestinations()[0]) with { abi: destAbi } }. Without the parentheses, thewithapplies to the call itself. - On one call.
dest.getDebt() with { abi: destAbi }.
With no ABI in any of these places, CQL refuses the query before it runs:
CQL2063 · error · A call through `dest` needs an ABI: `dest` holds an address found at run timeThe hint names the place to attach one. A call by its signature, dest.call('getDebt()(uint256)'), needs no ABI.
Proxies
Many contracts are proxies. The address that you hold forwards every call to an implementation somewhere else. It is the implementation's ABI that describes what you can call.
stETH is a proxy. The ABI verified at its address is an Aragon app proxy's ABI. It has five functions about upgrades: implementation, kernel, appId, proxyType and isDepositable. None of them is getPooledEthByShares.
CQL finds a proxy's implementation in the answers of the verification services, not in the proxy's code. Sourcify names the implementation of common patterns, such as EIP-1967 proxies, beacons and diamonds. Etherscan names it for the proxies that it knows, and stETH is one of them.
CQL follows the proxy one step, to the implementation, and adds its ABI to the proxy's own. For stETH, the implementation is 0x028271e30a695c0527a0c50ca30603fed004cdb0. The query with no abi at all calls getPooledEthByShares as if it were the proxy's own function.
When that happens, the Contract tab in the workbench shows a line borrowed from that names the implementation. To open the tab, press the ⓘ beside any address in the grid. For a diamond, CQL adds the ABI of every verified facet, and the line names only the first facet.
A proxy that no service verified has no ABI. A call on it ends in CQL3008, as for any contract with no ABI.
CQL can also miss a verified proxy whose ABI has more than four functions and no function or event such as implementation, upgradeTo or Upgraded. When CQL does not follow a verified proxy, it keeps the proxy's own ABI. A call to a function of the implementation then ends in CQL3013. Read a proxy says what to do then.
Over a range, CQL decodes every row with the one ABI that the Contract tab shows. That includes the rows from before an upgrade. Read a proxy says what this means for the older rows.
When nothing is found
If no service has verified source for the address, CQL refuses the query at the call:
CQL3008 · error · ethereum:0x… has no ABI on ethereum; only .call('<sig>') is availableThere are three ways forward:
- Check again. A check again button sits beside the message in the Diagnostics tab. Some contracts are verified after the fact, and CQL remembers a not verified answer for a while. The button clears that answer and asks the services again.
- Add the ABI to your library. If you have the ABI, from the contract's team or from a compiler's output, upload it once and name it in your queries. Read a contract nobody has verified shows each step.
- Call it by its signature. If you know a function's signature,
.call()reaches it with no ABI:s.call('balanceOf(address)(uint256)', holder). See.call().
A service can also fail to answer. It can be busy for a short time. It can also refuse every request for a chain, or every request with heto's key. Then CQL does not know if the contract is verified, and it does not remember that answer. When you run the query, CQL refuses it with CQL3009, which names the service.
Run the query again after a short time. If CQL3009 stays, add the ABI to your library, or call the function by its signature with .call().
Your library
ABI library in the rail holds the ABIs you uploaded, by name. A query names one with with { abi: 'lido' }, and the library is the third of the four places above. Your ABI library lists the forms the dialog accepts, the name rules and what each action on an entry does. A change shows in the editor at once, without a reload.
Reading a function nobody agrees on
When an ABI has two functions of the same name and the same number of parameters, that is an overload. CQL calls the one whose parameter types match the types of your arguments. If the ABI has get(uint256) and get(address), s.get(5) calls get(uint256). If your arguments match more than one, CQL cannot pick, and says CQL2011 · Ambiguous overload. For example, a number matches both get(uint256) and get(int256). Name the exact one with .call: s.call('getPooledEthByShares(uint256)(uint256)', 1e18).
See also
withoptions —abi,caller,block,value.- Read a proxy — what you see when stETH resolves.
- Read a contract nobody has verified —
.call()and the library.