1use jsonrpsee::{core::RpcResult, proc_macros::rpc};
2
3use alloy_primitives::{Address, Bytes, B256, U256};
4use alloy_rpc_types_anvil::{Forking, Metadata, MineOptions, NodeInfo};
5use alloy_rpc_types_eth::Block;
6
7#[rpc(server, namespace = "anvil")]
10pub trait AnvilApi {
11 #[method(name = "impersonateAccount")]
13 async fn anvil_impersonate_account(&self, address: Address) -> RpcResult<()>;
14
15 #[method(name = "stopImpersonatingAccount")]
17 async fn anvil_stop_impersonating_account(&self, address: Address) -> RpcResult<()>;
18
19 #[method(name = "autoImpersonateAccount")]
21 async fn anvil_auto_impersonate_account(&self, enabled: bool) -> RpcResult<()>;
22
23 #[method(name = "getAutomine")]
25 async fn anvil_get_automine(&self) -> RpcResult<bool>;
26
27 #[method(name = "mine")]
29 async fn anvil_mine(&self, blocks: Option<U256>, interval: Option<U256>) -> RpcResult<()>;
30
31 #[method(name = "setAutomine")]
34 async fn anvil_set_automine(&self, enabled: bool) -> RpcResult<()>;
35
36 #[method(name = "setIntervalMining")]
38 async fn anvil_set_interval_mining(&self, interval: u64) -> RpcResult<()>;
39
40 #[method(name = "anvil_dropTransaction")]
42 async fn anvil_drop_transaction(&self, tx_hash: B256) -> RpcResult<Option<B256>>;
43
44 #[method(name = "reset")]
48 async fn anvil_reset(&self, fork: Option<Forking>) -> RpcResult<()>;
49
50 #[method(name = "setRpcUrl")]
52 async fn anvil_set_rpc_url(&self, url: String) -> RpcResult<()>;
53
54 #[method(name = "setBalance")]
56 async fn anvil_set_balance(&self, address: Address, balance: U256) -> RpcResult<()>;
57
58 #[method(name = "setCode")]
60 async fn anvil_set_code(&self, address: Address, code: Bytes) -> RpcResult<()>;
61
62 #[method(name = "setNonce")]
64 async fn anvil_set_nonce(&self, address: Address, nonce: U256) -> RpcResult<()>;
65
66 #[method(name = "setStorageAt")]
68 async fn anvil_set_storage_at(
69 &self,
70 address: Address,
71 slot: U256,
72 value: B256,
73 ) -> RpcResult<bool>;
74
75 #[method(name = "setCoinbase")]
77 async fn anvil_set_coinbase(&self, address: Address) -> RpcResult<()>;
78
79 #[method(name = "setChainId")]
81 async fn anvil_set_chain_id(&self, chain_id: u64) -> RpcResult<()>;
82
83 #[method(name = "setLoggingEnabled")]
85 async fn anvil_set_logging_enabled(&self, enabled: bool) -> RpcResult<()>;
86
87 #[method(name = "setMinGasPrice")]
89 async fn anvil_set_min_gas_price(&self, gas_price: U256) -> RpcResult<()>;
90
91 #[method(name = "setNextBlockBaseFeePerGas")]
93 async fn anvil_set_next_block_base_fee_per_gas(&self, base_fee: U256) -> RpcResult<()>;
94
95 #[method(name = "setTime")]
97 async fn anvil_set_time(&self, timestamp: u64) -> RpcResult<u64>;
98
99 #[method(name = "dumpState")]
102 async fn anvil_dump_state(&self) -> RpcResult<Bytes>;
103
104 #[method(name = "loadState")]
107 async fn anvil_load_state(&self, state: Bytes) -> RpcResult<bool>;
108
109 #[method(name = "nodeInfo")]
111 async fn anvil_node_info(&self) -> RpcResult<NodeInfo>;
112
113 #[method(name = "metadata")]
115 async fn anvil_metadata(&self) -> RpcResult<Metadata>;
116
117 #[method(name = "snapshot")]
119 async fn anvil_snapshot(&self) -> RpcResult<U256>;
120
121 #[method(name = "revert")]
124 async fn anvil_revert(&self, id: U256) -> RpcResult<bool>;
125
126 #[method(name = "increaseTime")]
128 async fn anvil_increase_time(&self, seconds: U256) -> RpcResult<i64>;
129
130 #[method(name = "setNextBlockTimestamp")]
132 async fn anvil_set_next_block_timestamp(&self, seconds: u64) -> RpcResult<()>;
133
134 #[method(name = "setBlockGasLimit")]
136 async fn anvil_set_block_gas_limit(&self, gas_limit: U256) -> RpcResult<bool>;
137
138 #[method(name = "setBlockTimestampInterval")]
140 async fn anvil_set_block_timestamp_interval(&self, seconds: u64) -> RpcResult<()>;
141
142 #[method(name = "removeBlockTimestampInterval")]
144 async fn anvil_remove_block_timestamp_interval(&self) -> RpcResult<bool>;
145
146 #[method(name = "mine_detailed")] async fn anvil_mine_detailed(&self, opts: Option<MineOptions>) -> RpcResult<Vec<Block>>;
155
156 #[method(name = "enableTraces")]
159 async fn anvil_enable_traces(&self) -> RpcResult<()>;
160
161 #[method(name = "removePoolTransactions")]
163 async fn anvil_remove_pool_transactions(&self, address: Address) -> RpcResult<()>;
164}