A Mockthereum node provides default behaviours and allows defining custom behaviour rules to simulate interactions with the Ethereum network without requiring a full node, access to the real Ethereum network, or real transactions with the delays and costs that might involve.

This should not be created directly: instead, call then getLocal() or getRemote() methods exported from this module.

Once you have a Mockthereum node, you can start defining rules using any of the forX() methods. Each method returns a rule builder, allowing you to add extra matching constraints, followed by a thenX() final method which enables the rule, returning a promise that resolves once the rule is constructed and active.

Hierarchy

  • MockthereumNode

Constructors

Accessors

  • get url(): string
  • Get the URL for this Mockthereum node. You can pass this directly to libraries like Web3 as your Ethereum RPC endpoint to intercept all Web3 Ethereum interactions.

    Returns string

Methods

  • Mock all wallet balance queries, either for all addresses (by default) or for one specific wallet address, if specified.

    This returns a rule builder that you can use to configure the rule. Call a thenX() method and wait for the returned promise to complete the rule and activate it.

    Parameters

    • Optional address: `0x${string}`

    Returns BalanceRuleBuilder

  • Mock all contract calls, either for all contracts (by default) or for one specific contract address, if specified.

    This returns a rule builder that you can use to configure the rule. Call a thenX() method and wait for the returned promise to complete the rule and activate it.

    Parameters

    • Optional address: `0x${string}`

    Returns CallRuleBuilder

  • Mock all gas price queries.

    This returns a rule builder that you can use to configure the rule. Call a thenX() method and wait for the returned promise to complete the rule and activate it.

    Returns GasPriceRuleBuilder

  • Mock all transactions sent to a specific address.

    This returns a rule builder that you can use to configure the rule. Call a thenX() method and wait for the returned promise to complete the rule and activate it.

    Parameters

    • address: `0x${string}`

    Returns TransactionRuleBuilder

  • Query the list of requests seen by this node for a specific method.

    This returns a promise, resolving to an array of objects containing method (the Ethereum method called), parameters (the method parameters) and rawRequest (the full raw HTTP request data).

    Parameters

    • methodName: string

    Returns Promise<{
        method?: string;
        params?: any[];
        rawRequest: CompletedRequest;
    }[]>

  • Query the list of requests seen by this node. This returns a promise, resolving to an array of objects containing method (the Ethereum method called), parameters (the method parameters) and rawRequest (the full raw HTTP request data).

    Returns Promise<{
        method?: string;
        params?: any[];
        rawRequest: CompletedRequest;
    }[]>

  • The node must be started before use. Starting the node resets it, removing any rules that may have been added previously and configuring default behaviours for unmatched requests.

    This method returns a promise, which you should wait for to ensure the node is fully started before using it.

    Returns Promise<void>

  • Stop the node when you're finished with it to close down the underlying server and any remaining connections.

    This method returns a promise, which you should wait for to ensure the node is fully stopped, especially if you intend to start it again later.

    Returns Promise<void>

Generated using TypeDoc