Skip to Content

State

Set code, nonce, and storage on any account on your Stagenet.

Use this to:

  • Replace a contract’s bytecode with a mock for testing.
  • Force-set a storage slot to put a contract into an exact state.
  • Bump an account’s nonce to match a production scenario.

How it works

Each method writes directly to your Stagenet’s chain state.

After a value is set, it behaves like normal EVM state: transactions can modify it, and reads return the latest value.

This matches the behaviour of hardhat_setStorageAt, anvil_setStorageAt, and Foundry’s vm.store.

setCode

Replace the code at an address with arbitrary bytecode. Pass "0x" to wipe the code.

const addr = "0x0000000000000000000000000000000000001234"; await stagenet.setCode(addr, "0x6042"); await stagenet.setCode(addr, "0x"); // empty
ParameterTypeDescription
addressstringA 0x-prefixed Ethereum address
bytecodestringThe bytecode as 0x-prefixed hex. Pass "0x" for empty code.

Returns { success, address }.

setNonce

Set the nonce on an account. Transaction-driven nonce increments after this proceed from the new value.

await stagenet.setNonce(alice, 42); await stagenet.setNonce(alice, "0x10"); // hex also accepted (= 16)
ParameterTypeDescription
addressstringA 0x-prefixed Ethereum address
noncestring | bigint | numberNon-negative integer

Returns { success, address, newNonce }.

setStorageAt

Write a 32-byte value into a specific storage slot.

Both slot and value must be exactly 32-byte hex words (0x + 64 hex chars). The same convention as Hardhat, Anvil, and Foundry’s vm.store — the caller encodes their value explicitly so there is no ambiguity between uint-style (left-padded) and bytes-style (right-padded).

// Encode a number as a uint256-style 32-byte word const toUint = (n: bigint) => "0x" + n.toString(16).padStart(64, "0"); await stagenet.setStorageAt(token, toUint(0n), toUint(42n));

Or use a helper from viem:

import { pad, toHex } from "viem"; await stagenet.setStorageAt(token, pad(toHex(0)), pad(toHex(42n)));

Short hex inputs like "0x42" are rejected — encode them explicitly.

ParameterTypeDescription
addressstringA 0x-prefixed Ethereum address
slotstringStorage slot key — exactly 32 bytes (0x + 64 hex chars)
valuestringValue to write — exactly 32 bytes (0x + 64 hex chars)

Returns { success, address, slot }.

Last updated on