Skip to content

Call.key

Gives a stable name for a call. The same call has the same key, so it can be a cache key. It cannot fail.

import { Call, Erc20, type Address } from "@ethect/core";
// One entry of a cache per call, whatever library holds the cache.
const cache = new Map<string, bigint>();
const remember = (token: Address.Address, user: Address.Address, balance: bigint) => {
const call = Erc20.at(token).balanceOf(user);
cache.set(Call.key(call), balance);
// '["0xa0b8…eb48","balanceOf(address)",["0xf39f…2266"],"0"]'
};

A query library needs a key for what it fetches. The key of a read is the key of its call.

string

The address, the signature of the function, the arguments and the value, written as text.

Call Key
Erc20.at(token).balanceOf(user) ["0xa0b8…","balanceOf(address)",["0xf39f…"],"0"]
Erc4626.at(vault).deposit(100n, user) ["0x5fbd…","deposit(uint256,address)",["100","0xf39f…"],"0"]
Call.make({ to: user, value: 10n ** 17n }) ["0xf39f…","0x",[],"100000000000000000"]
  • Type: Call.Call<any, any>

Any call.

  • It encodes nothing, so it cannot fail. A call whose arguments do not encode still has a key.
  • A bigint is written as a string. So is the value of the call.
  • A struct is written by the names of its fields, in the order of the names. Two objects with the same fields have the same key, in whatever order they were written.
  • A raw call is named by its bytes, where a call of a function is named by its signature.
  • The key does not hold the options of a read. Two reads of one call at two blocks have one key: add the block to your own key when it matters.
  • Do not parse it. It is a name. Its format may change between versions.