gasless contract simulation

simulating contracts without spending gas is obviously useful. for example this can be used to build security scanners, secure your contract interactions, etc.

i’ll note a couple pocs to try it in javascript, solidity, and rust.


javascript is a good way to get started. lets use bun to write a quick proof of concept using a bit from ethers.

import { Contract } from "ethers"

const c = new Contract(
  ["function transfer(address,uint256) public"],

// access the contract through .staticCall to simulate
const sim = c.staticCall.transfer()

cool. you can find the documentation for this here.


in solidity, i find it’s easiest to use a node and fork some blockchain. anvil from foundry is one of the best.

you can fork any chain locally like so:

anvil --fork-url

if you use forge from foundry to manage your project, it’s very easy to write tests and then pass the same flag, for example.

contract TestExample is Test {
  function setUp() {


  function testExample() {


then you can test it against your desired network by using

forge test --fork-url


the above options are highly convenient but very slow.

if you find your project needs to test with more performance, rust is always a fun choice 🦀


use ethers::prelude::*;

async fn main() {

another paradigm open source project mimics ethers on rust aptly named ethers-rs. here is a minimal poc mirroring the above examples, they have many high quality ones that may be way more interesting, but yknow