Ethereum Virtual Script
Write read-only EVM scripts in TypeScript. evs compiles them to bytecode and runs them as one
eth_call, so reads that depend on earlier reads cost a single round trip.bun add @maxencerb/evs viem- One eth_call
- Dependent reads run inside a single RPC round trip.
- Typed through viem
- The script is its own ABI; readContract infers args and result.
- Nothing to deploy
- Deployless by default, state override when msg.sender matters.
- solc 0.8 semantics
- Checked arithmetic, verbatim revert bubbling, panic codes.
Dependent reads in one call
Section titled “Dependent reads in one call”Read a Uniswap V3 pool’s two tokens, then each token’s symbol.
import { evscript, t } from '@maxencerb/evs';import { erc20Abi } from 'viem';import { poolAbi } from './abi';
export const poolTokens = evscript( { name: 'poolTokens', args: [t.address] }, (s, pool) => { const token0 = s.read({ address: pool, abi: poolAbi, functionName: 'token0' }); const token1 = s.read({ address: pool, abi: poolAbi, functionName: 'token1' }); const symbol0 = s.read({ address: token0, abi: erc20Abi, functionName: 'symbol' }); const symbol1 = s.read({ address: token1, abi: erc20Abi, functionName: 'symbol' }); return s.return({ token0, token1, symbol0, symbol1 }); },);import { parseAbi } from 'viem';
export const poolAbi = parseAbi([ 'function token0() view returns (address)', 'function token1() view returns (address)',]);import { compile } from '@maxencerb/evs';import { createPublicClient, http } from 'viem';import { mainnet } from 'viem/chains';import { poolTokens } from './script';
const client = createPublicClient({ chain: mainnet, transport: http() });const compiled = compile(poolTokens);
const result = await client.readContract({ ...compiled.toViem(), functionName: 'poolTokens', args: ['0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640'], // USDC/WETH 0.05% pool});// { token0: `0x${string}`; token1: `0x${string}`; symbol0: string; symbol1: string }A multicall encodes every call before the request leaves, so it cannot read symbol from an
address that the same batch returns.
Quick startWrite, compile and run a script in three steps.
Writing scriptsWhat runs at build time and what runs on-chain.
Calling contractsRead views, call quoters and dry-run writes.
Executing scriptsDeployless or state override, and which providers support each.
ExamplesPool metadata, batch token balances and more patterns.
API referenceOne page per function, each with usage, returns and parameters.