Skip to content
LogoLogo

tevm sol

tevm sol is the shortest path from a Solidity file to a return value: it compiles one source file, deploys the contract into an in-process EVM, calls one function, and prints the result. No session, no artifacts directory, no project config.

Working example

The commands below were run with @tevm/cli@1.0.0-rc.151.

npm install --global @tevm/cli@1.0.0-rc.151
cat > Counter.sol <<'SOLIDITY'
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
 
contract Counter {
    uint256 public number = 42;
 
    function setNumber(uint256 next) public {
        number = next;
    }
}
SOLIDITY
tevm sol Counter.sol --function number --json
{
  "ok": true,
  "command": "sol",
  "result": {
    "contract": "Counter",
    "address": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
    "data": "42",
    "executionGasUsed": "2424"
  }
}

result.data is the decoded return value. result.address is the deterministic address the contract was deployed to for this one-shot run.

Arguments and flags

The command schema in packages/tevm-cli/src/commands/sol.tsx exposes:

KindSyntaxDescription
Argument<source>Path to one Solidity source file.
Flag--function <name>Function to call after deployment. Required.
Flag--contract <name>Contract name, when the source defines more than one contract.
Flag--args <json>Function arguments as a JSON array. Defaults to [].
Flag--jsonEmit the stable { ok, command, result } envelope.

Passing arguments

--args takes a JSON array, so it composes cleanly with jq and with shell variables. Large integers are accepted as JSON strings:

tevm sol Counter.sol --contract Counter --function setNumber --args '["1000"]' --json

When to reach for something else

Neighbours

Solidity guide · tevm compile · tevm deploy