1

I successfully installed and used anvil from the wsl shell.

I have some rust code, where i want to import foundry anvil instead of running from shell, cause i want to be able to control it from the app itself , reset it, fork a newblock, simulate transactions. Im trying this for 2 days already, without success.

1 Answer 1

2
async fn anvil_mine() -> Result<(), reqwest::Error> {
   let client = reqwest::Client::new();
   let res = client.post("http://127.0.0.1:8545")
       .json(&serde_json::json!({
           "jsonrpc": "2.0",
           "method": "anvil_mine",
           "params": [],
           "id": 1
       }))
       .send()
       .await?;
   println!("{:#?}", res.text().await?);
   Ok(())
}

Run

anvil

in a terminal (default RPC url is http://127.0.0.1:8545). Then use this code to interact with it.
You can replace "anvil_mine" by any of these:

https://book.getfoundry.sh/reference/anvil

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.