Skip to main content

reth_rpc_api/
hardhat.rs

1use alloy_primitives::{Address, Bytes, B256, U256};
2use alloy_rpc_types_anvil::{Forking, Metadata};
3use jsonrpsee::{core::RpcResult, proc_macros::rpc};
4
5/// Hardhat rpc interface.
6/// https://hardhat.org/hardhat-network/docs/reference#hardhat-network-methods
7#[rpc(server, namespace = "hardhat")]
8pub trait HardhatApi {
9    /// Removes the given transaction from the mempool, if it exists.
10    ///
11    /// Returns `true` if successful, otherwise `false`.
12    #[method(name = "hardhat_dropTransaction")]
13    async fn hardhat_drop_transaction(&self, tx_hash: B256) -> RpcResult<bool>;
14
15    /// Allows Hardhat Network to sign transactions as the given address.
16    #[method(name = "impersonateAccount")]
17    async fn hardhat_impersonate_account(&self, address: Address) -> RpcResult<()>;
18
19    /// Returns `true` if automatic mining is enabled, and `false` otherwise.
20    #[method(name = "getAutomine")]
21    async fn hardhat_get_automine(&self) -> RpcResult<bool>;
22
23    /// Returns an object with metadata about the instance of the Hardhat network.
24    #[method(name = "metadata")]
25    async fn hardhat_metadata(&self) -> RpcResult<Metadata>;
26
27    /// Mines a specified number of blocks at a given interval.
28    #[method(name = "mine")]
29    async fn hardhat_mine(&self, blocks: Option<U256>, interval: Option<U256>) -> RpcResult<()>;
30
31    /// Resets back to a fresh forked state, fork from another block number or disable forking.
32    #[method(name = "reset")]
33    async fn hardhat_reset(&self, fork: Option<Forking>) -> RpcResult<()>;
34
35    /// Sets the balance for the given address.
36    #[method(name = "setBalance")]
37    async fn hardhat_set_balance(&self, address: Address, balance: U256) -> RpcResult<()>;
38
39    /// Modifies the bytecode stored at an account's address.
40    #[method(name = "setCode")]
41    async fn hardhat_set_code(&self, address: Address, code: Bytes) -> RpcResult<()>;
42
43    /// Sets the coinbase address to be used in new blocks.
44    #[method(name = "setCoinbase")]
45    async fn hardhat_set_coinbase(&self, address: Address) -> RpcResult<()>;
46
47    /// Enables or disables logging.
48    #[method(name = "setLoggingEnabled")]
49    async fn hardhat_set_logging_enabled(&self, enabled: bool) -> RpcResult<()>;
50
51    /// Changes the minimum gas price accepted by the network (in wei).
52    #[method(name = "setMinGasPrice")]
53    async fn hardhat_set_min_gas_price(&self, gas_price: U256) -> RpcResult<()>;
54
55    /// Sets the base fee of the next block.
56    #[method(name = "setNextBlockBaseFeePerGas")]
57    async fn hardhat_set_next_block_base_fee_per_gas(
58        &self,
59        base_fee_per_gas: U256,
60    ) -> RpcResult<()>;
61
62    /// Sets the `PREVRANDAO` value of the next block.
63    #[method(name = "setPrevRandao")]
64    async fn hardhat_set_prev_randao(&self, prev_randao: B256) -> RpcResult<()>;
65
66    /// Modifies an account's nonce by overwriting it.
67    #[method(name = "setNonce")]
68    async fn hardhat_set_nonce(&self, address: Address, nonce: U256) -> RpcResult<()>;
69
70    /// Writes a single position of an account's storage.
71    #[method(name = "setStorageAt")]
72    async fn hardhat_set_storage_at(
73        &self,
74        address: Address,
75        slot: U256,
76        value: B256,
77    ) -> RpcResult<()>;
78
79    /// Stops impersonating the given address.
80    #[method(name = "stopImpersonatingAccount")]
81    async fn hardhat_stop_impersonating_account(&self, address: Address) -> RpcResult<()>;
82}