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