Function Override
Force a contract function on your Stagenet to return a fixed value, without changing its code.
Use this to:
- Mock a price oracle, vault rate, or any external view function during testing.
- Force a contract into a specific branch (e.g.
paused() = true) without writing to storage. - Reproduce a production state that depends on a registry, ACL, or feed you can’t easily seed.
This CLI is a thin wrapper over the SDK. See RPC routes for the full schema and EVM semantics.
Usage
With a contract.dev.js at your project root (see Setup):
contract.dev function-override <subcommand>function-override add
Install an override for a contract function.
contract.dev function-override add 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
--abi 'function totalSupply() view returns (uint256)' \
--returns '["1000000000000"]'| Argument | Description |
|---|---|
<address> | The contract whose function to override |
--abi <abi> | JSON ABI fragment or a human-readable signature (e.g. 'function getCount() view returns (uint256)') |
--returns <json> | JSON array of return values matching the fragment’s outputs |
--input-params <json> | Optional. JSON array of input params to scope this override to a specific call. Omit for a wildcard. |
The same selector can have several overrides — one per --input-params set, plus an optional wildcard. Exact-input overrides take precedence over wildcards on the same selector.
Examples:
# Wildcard: every call to balanceOf returns 1,000,000 (6dp USDC)
contract.dev function-override add 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
--abi 'function balanceOf(address) view returns (uint256)' \
--returns '["1000000000000"]'
# Scoped: only this holder reads as 500
contract.dev function-override add 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
--abi 'function balanceOf(address) view returns (uint256)' \
--input-params '["0x1111111111111111111111111111111111111111"]' \
--returns '["500000000"]'
# Pretend the protocol is paused
contract.dev function-override add 0xVault... \
--abi 'function paused() view returns (bool)' \
--returns '["true"]'Prints the created override id — keep it to update / disable / remove later.
function-override list
List active overrides.
# Every override on this stagenet
contract.dev function-override list
# Just for one contract
contract.dev function-override list --contract 0xVault...| Argument | Description |
|---|---|
--contract <address> | Filter to overrides for a single contract |
Output is one override per line: <id> <contract> <enabled|disabled> returns=<json> [inputs=<json>].
function-override update
Replace the return values of an existing override. The contract address, selector, and inputParams are immutable — remove and re-add to change them.
contract.dev function-override update fov_abc123 --returns '["2000000000000"]'| Argument | Description |
|---|---|
<id> | The override id (from add or list) |
--returns <json> | New JSON array of return values |
function-override enable / disable
Toggle an override on or off without removing it. A disabled override stays in the DB but is not applied — calls fall through to the real contract.
contract.dev function-override disable fov_abc123
# ... later ...
contract.dev function-override enable fov_abc123| Argument | Description |
|---|---|
<id> | The override id |
function-override remove
Delete an override.
contract.dev function-override remove fov_abc123Aliases: rm.
Notes
- Overrides intercept at the EVM layer, so a contract that
staticcalls the overridden function sees the override too — not justeth_callfrom outside. - When both a wildcard and an exact-input override exist for the same selector, the exact-input one wins.
- See RPC routes → function-overrides for the full RPC schema if you’d rather call the methods directly.