ganache logo

Ganache

Ganache JSON-RPC Documentation

This reference describes all Ganache JSON-RPC methods and provides interactive examples for each method. The interactive examples are powered by Ganache in the Browser and demonstrate using Ganache programmatically as an EIP-1193 provider. Try running these examples to see Ganache in action! Each editor can be changed to further test Ganache features.

Pro Tip: You can define your own provider by adding const provider = ganache.provider({}) to the start of any example and passing in your startup options.

eth namespace

eth_accounts(): Promise<string[]>

Returns a list of addresses owned by client.

returns
Promise<string[]>

: Array of 20 Bytes - addresses owned by the client.

example
const accounts = await provider.request({ method: "eth_accounts", params: [] });
console.log(accounts);

eth_blockNumber(): Promise<QUANTITY>

Returns the number of the most recent block.

returns
Promise<QUANTITY>

: The current block number the client is on.

example
const blockNumber = await provider.request({ method: "eth_blockNumber" });
console.log(blockNumber);

eth_call(transaction: Transaction, blockNumber: string, overrides: CallOverrides): Promise<DATA>

Executes a new message call immediately without creating a transaction on the block chain.

Transaction call object:

  • from: DATA, 20 bytes (optional) - The address the transaction is sent from.
  • to: DATA, 20 bytes - The address the transaction is sent to.
  • gas: QUANTITY (optional) - Integer of the maximum gas allowance for the transaction.
  • gasPrice: QUANTITY (optional) - Integer of the price of gas in wei.
  • value: QUANTITY (optional) - Integer of the value in wei.
  • data: DATA (optional) - Hash of the method signature and the ABI encoded parameters.

State Override object - An address-to-state mapping, where each entry specifies some state to be ephemerally overridden prior to executing the call. Each address maps to an object containing:

  • balance: QUANTITY (optional) - The balance to set for the account before executing the call.
  • nonce: QUANTITY (optional) - The nonce to set for the account before executing the call.
  • code: DATA (optional) - The EVM bytecode to set for the account before executing the call.
  • state: OBJECT (optional*) - Key-value mapping to override all slots in the account storage before executing the call.
  • stateDiff: OBJECT (optional*) - Key-value mapping to override individual slots in the account storage before executing the call.
  • *Note - state and stateDiff fields are mutually exclusive.
arguments
  • transaction: Transaction: The transaction call object as seen in source.
  • blockNumber: string: Integer block number, or the string "latest", "earliest" or "pending".
  • overrides: CallOverrides: State overrides to apply during the simulation.
returns
Promise<DATA>

: The return value of executed contract.

example
// Simple.sol
// // SPDX-License-Identifier: MIT
//  pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
//  contract Simple {
//      uint256 public value;
//      constructor() payable {
//          console.log("Called Simple contract constructor. Setting value to 5.");
//          value = 5;
//      }
//  }
const simpleSol = "0x608060405261002f6040518060600160405280603781526020016104016037913961003c60201b6100541760201c565b60056000819055506101bb565b6100d8816040516024016100509190610199565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100db60201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561013a57808201518184015260208101905061011f565b83811115610149576000848401525b50505050565b6000601f19601f8301169050919050565b600061016b82610100565b610175818561010b565b935061018581856020860161011c565b61018e8161014f565b840191505092915050565b600060208201905081810360008301526101b38184610160565b905092915050565b610237806101ca6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80633fa4f24514610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b60005481565b6100ea8160405160240161006891906101df565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100ed565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b6000819050919050565b61012581610112565b82525050565b6000602082019050610140600083018461011c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610180578082015181840152602081019050610165565b8381111561018f576000848401525b50505050565b6000601f19601f8301169050919050565b60006101b182610146565b6101bb8185610151565b93506101cb818560208601610162565b6101d481610195565b840191505092915050565b600060208201905081810360008301526101f981846101a6565b90509291505056fea26469706673582212205402181d93a2ec38e277cfd7fa6bdb14ae069535ac31572e1c94c713cddb891264736f6c634300080b003343616c6c65642053696d706c6520636f6e747261637420636f6e7374727563746f722e2053657474696e672076616c756520746f20352e";
const [from] = await provider.request({ method: "eth_accounts", params: [] });
const txObj = { from, gas: "0x5b8d80", gasPrice: "0x1dfd14000", value:"0x0", data: simpleSol };
const slot = "0x0000000000000000000000000000000000000000000000000000000000000005"
const overrides = { [from]: { balance: "0x3e8", nonce: "0x5", code: "0xbaddad42", stateDiff: { [slot]: "0x00000000000000000000000000000000000000000000000000000000baddad42"}}};
const result = await provider.request({ method: "eth_call", params: [txObj, "latest", overrides] });
console.log(result);

eth_chainId(): Promise<QUANTITY>

Returns the currently configured chain id, a value used in replay-protected transaction signing as introduced by EIP-155.

returns
Promise<QUANTITY>

: The chain id as a string.

example
const chainId = await provider.send("eth_chainId");
console.log(chainId);

eth_coinbase(): Promise<Address>

Returns the client coinbase address.

returns
Promise<Address>

: The current coinbase address.

example
const coinbaseAddress = await provider.request({ method: "eth_coinbase" });
console.log(coinbaseAddress);

eth_estimateGas(transaction: Transaction, blockNumber: string): Promise<QUANTITY>

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain. Note that the estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance.

Transaction call object:

  • from: DATA, 20 bytes (optional) - The address the transaction is sent from.
  • to: DATA, 20 bytes - The address the transaction is sent to.
  • gas: QUANTITY (optional) - Integer of the maximum gas allowance for the transaction.
  • gasPrice: QUANTITY (optional) - Integer of the price of gas in wei.
  • value: QUANTITY (optional) - Integer of the value in wei.
  • data: DATA (optional) - Hash of the method signature and the ABI encoded parameters.
arguments
  • transaction: Transaction: The transaction call object as seen in source.
  • blockNumber: string: Integer block number, or the string "latest", "earliest" or "pending".
returns
Promise<QUANTITY>

: The amount of gas used.

example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
const gasEstimate = await provider.request({ method: "eth_estimateGas", params: [{ from, to }, "latest" ] });
console.log(gasEstimate);

eth_feeHistory(blockCount: string, newestBlock: string, rewardPercentiles: number[]): Promise<FeeHistory>

Returns a collection of historical block gas data and optional effective fee spent per unit of gas for a given percentile of block gas usage.

arguments
  • blockCount: string: Range of blocks between 1 and 1024. Will return less than the requested range if not all blocks are available.
  • newestBlock: string: Highest block of the requested range.
  • rewardPercentiles: number[]: A monotonically increasing list of percentile values. For each block in the requested range, the transactions will be sorted in ascending order by effective tip per gas and the corresponding effective tip for the percentile will be determined, accounting for gas consumed.
returns
Promise<FeeHistory>

: Transaction base fee per gas and effective priority fee per gas for the requested/supported block range

  • oldestBlock: - Lowest number block of the returned range.
  • baseFeePerGas: - An array of block base fees per gas. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks.
  • gasUsedRatio: - An array of block gas used ratios. These are calculated as the ratio of gasUsed and gasLimit.
  • reward: - An array of effective priority fee per gas data points from a single block. All zeroes are returned if the block is empty.
example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_sendTransaction", params: [{ from, to }] });
const feeHistory = await provider.request({ method: "eth_feeHistory", params: ["0x1", "0x1", [10, 100]] });
console.log(feeHistory);

eth_gasPrice(): Promise<QUANTITY>

Returns the current price per gas in wei.

returns
Promise<QUANTITY>

: Integer of the current gas price in wei.

example
const gasPrice = await provider.request({ method: "eth_gasPrice", params: [] });
console.log(gasPrice);

eth_getBalance(address: string, blockNumber: string): Promise<QUANTITY>

Returns the balance of the account of given address.

arguments
  • address: string: Address to check for balance.
  • blockNumber: string: Integer block number, or the string "latest", "earliest" or "pending".
returns
Promise<QUANTITY>

: Integer of the account balance in wei.

example
const accounts = await provider.request({ method: "eth_accounts", params: [] });
const balance = await provider.request({ method: "eth_getBalance", params: [accounts[0], "latest"] });
console.log(balance);

eth_getBlockByHash(hash: string, transactions?: IncludeTransactions): Promise<{ hash: DATA, size: QUANTITY, transactions: IncludeTransactions, uncles: DATA[], withdrawals: Withdrawal[] } & BlockHeader>

Returns information about a block by block hash.

arguments
  • hash: string: Hash of a block.
  • transactions?: IncludeTransactions: If true it returns the full transaction objects, if false only the hashes of the transactions.
returns
Promise<{ hash: DATA, size: QUANTITY, transactions: IncludeTransactions, uncles: DATA[], withdrawals: Withdrawal[] } & BlockHeader>

: The block, null if the block doesn't exist.

  • hash: DATA, 32 Bytes - Hash of the block. null when pending.
  • parentHash: DATA, 32 Bytes - Hash of the parent block.
  • sha3Uncles: DATA, 32 Bytes - SHA3 of the uncles data in the block.
  • miner: DATA, 20 Bytes - Address of the miner.
  • stateRoot: DATA, 32 Bytes - The root of the state trie of the block.
  • transactionsRoot: DATA, 32 Bytes - The root of the transaction trie of the block.
  • receiptsRoot: DATA, 32 Bytes - The root of the receipts trie of the block.
  • logsBloom: DATA, 256 Bytes - The bloom filter for the logs of the block. null when pending.
  • difficulty: QUANTITY - Integer of the difficulty of this block.
  • number: QUANTITY - The block number. null when pending.
  • gasLimit: QUANTITY - The maximum gas allowed in the block.
  • gasUsed: QUANTITY - Total gas used by all transactions in the block.
  • timestamp: QUANTITY - The unix timestamp for when the block was collated.
  • extraData: DATA - Extra data for the block.
  • mixHash: DATA, 256 Bytes - Hash identifier for the block.
  • nonce: DATA, 8 Bytes - Hash of the generated proof-of-work. null when pending.
  • totalDifficulty: QUANTITY - Integer of the total difficulty of the chain until this block.
  • size: QUANTITY - Integer the size of the block in bytes.
  • transactions: Array - Array of transaction objects or 32 Bytes transaction hashes depending on the last parameter.
  • uncles: Array - Array of uncle hashes.
example
// Simple.sol
// // SPDX-License-Identifier: MIT
//  pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
//  contract Simple {
//      uint256 public value;
//      constructor() payable {
//          console.log("Called Simple contract constructor. Setting value to 5.");
//          value = 5;
//      }
//  }
const simpleSol = "0x608060405261002f6040518060600160405280603781526020016104016037913961003c60201b6100541760201c565b60056000819055506101bb565b6100d8816040516024016100509190610199565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100db60201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561013a57808201518184015260208101905061011f565b83811115610149576000848401525b50505050565b6000601f19601f8301169050919050565b600061016b82610100565b610175818561010b565b935061018581856020860161011c565b61018e8161014f565b840191505092915050565b600060208201905081810360008301526101b38184610160565b905092915050565b610237806101ca6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80633fa4f24514610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b60005481565b6100ea8160405160240161006891906101df565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100ed565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b6000819050919050565b61012581610112565b82525050565b6000602082019050610140600083018461011c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610180578082015181840152602081019050610165565b8381111561018f576000848401525b50505050565b6000601f19601f8301169050919050565b60006101b182610146565b6101bb8185610151565b93506101cb818560208601610162565b6101d481610195565b840191505092915050565b600060208201905081810360008301526101f981846101a6565b90509291505056fea26469706673582212205402181d93a2ec38e277cfd7fa6bdb14ae069535ac31572e1c94c713cddb891264736f6c634300080b003343616c6c65642053696d706c6520636f6e747261637420636f6e7374727563746f722e2053657474696e672076616c756520746f20352e";
const [from] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", data: simpleSol }] });
const txReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });
const block = await provider.request({ method: "eth_getBlockByHash", params: [txReceipt.blockHash, true] });
console.log(block);

eth_getBlockByNumber(number: string, transactions?: IncludeTransactions): Promise<{ hash: DATA, size: QUANTITY, transactions: IncludeTransactions, uncles: DATA[], withdrawals: Withdrawal[] } & BlockHeader>

Returns information about a block by block number.

arguments
  • number: string: Integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
  • transactions?: IncludeTransactions: If true it returns the full transaction objects, if false only the hashes of the transactions.
returns
Promise<{ hash: DATA, size: QUANTITY, transactions: IncludeTransactions, uncles: DATA[], withdrawals: Withdrawal[] } & BlockHeader>

: The block, null if the block doesn't exist.

  • hash: DATA, 32 Bytes - Hash of the block. null when pending.
  • parentHash: DATA, 32 Bytes - Hash of the parent block.
  • sha3Uncles: DATA, 32 Bytes - SHA3 of the uncles data in the block.
  • miner: DATA, 20 Bytes - Address of the miner.
  • stateRoot: DATA, 32 Bytes - The root of the state trie of the block.
  • transactionsRoot: DATA, 32 Bytes - The root of the transaction trie of the block.
  • receiptsRoot: DATA, 32 Bytes - The root of the receipts trie of the block.
  • logsBloom: DATA, 256 Bytes - The bloom filter for the logs of the block. null when pending.
  • difficulty: QUANTITY - Integer of the difficulty of this block.
  • number: QUANTITY - The block number. null when pending.
  • gasLimit: QUANTITY - The maximum gas allowed in the block.
  • gasUsed: QUANTITY - Total gas used by all transactions in the block.
  • timestamp: QUANTITY - The unix timestamp for when the block was collated.
  • extraData: DATA - Extra data for the block.
  • mixHash: DATA, 256 Bytes - Hash identifier for the block.
  • nonce: DATA, 8 Bytes - Hash of the generated proof-of-work. null when pending.
  • totalDifficulty: QUANTITY - Integer of the total difficulty of the chain until this block.
  • size: QUANTITY - Integer the size of the block in bytes.
  • transactions: Array - Array of transaction objects or 32 Bytes transaction hashes depending on the last parameter.
  • uncles: Array - Array of uncle hashes.
example
const block = await provider.request({ method: "eth_getBlockByNumber", params: ["0x0", false] });
console.log(block);

eth_getBlockTransactionCountByHash(hash: string): Promise<QUANTITY>

Returns the number of transactions in a block from a block matching the given block hash.

arguments
  • hash: string: Hash of a block.
returns
Promise<QUANTITY>

: Number of transactions in the block.

example
// Simple.sol
// // SPDX-License-Identifier: MIT
//  pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
//  contract Simple {
//      uint256 public value;
//      constructor() payable {
//          console.log("Called Simple contract constructor. Setting value to 5.");
//          value = 5;
//      }
//  }
const simpleSol = "0x608060405261002f6040518060600160405280603781526020016104016037913961003c60201b6100541760201c565b60056000819055506101bb565b6100d8816040516024016100509190610199565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100db60201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561013a57808201518184015260208101905061011f565b83811115610149576000848401525b50505050565b6000601f19601f8301169050919050565b600061016b82610100565b610175818561010b565b935061018581856020860161011c565b61018e8161014f565b840191505092915050565b600060208201905081810360008301526101b38184610160565b905092915050565b610237806101ca6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80633fa4f24514610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b60005481565b6100ea8160405160240161006891906101df565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100ed565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b6000819050919050565b61012581610112565b82525050565b6000602082019050610140600083018461011c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610180578082015181840152602081019050610165565b8381111561018f576000848401525b50505050565b6000601f19601f8301169050919050565b60006101b182610146565b6101bb8185610151565b93506101cb818560208601610162565b6101d481610195565b840191505092915050565b600060208201905081810360008301526101f981846101a6565b90509291505056fea26469706673582212205402181d93a2ec38e277cfd7fa6bdb14ae069535ac31572e1c94c713cddb891264736f6c634300080b003343616c6c65642053696d706c6520636f6e747261637420636f6e7374727563746f722e2053657474696e672076616c756520746f20352e";
const [from] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", data: simpleSol }] });
const txReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });
const txCount = await provider.request({ method: "eth_getBlockTransactionCountByHash", params: [txReceipt.blockHash] });
console.log(txCount);

eth_getBlockTransactionCountByNumber(blockNumber: string): Promise<QUANTITY>

Returns the number of transactions in a block from a block matching the given block number.

arguments
  • blockNumber: string
returns
Promise<QUANTITY>

: Integer of the number of transactions in the block.

example
const txCount = await provider.request({ method: "eth_getBlockTransactionCountByNumber", params: ["0x0"] });
console.log(txCount);

eth_getCode(address: string, blockNumber: string): Promise<DATA>

Returns code at a given address.

arguments
  • address: string: Address.
  • blockNumber: string: Integer block number, or the string "latest", "earliest" or "pending".
returns
Promise<DATA>

: The code from the given address.

example
// Simple.sol
// // SPDX-License-Identifier: MIT
//  pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
//  contract Simple {
//      uint256 public value;
//      constructor() payable {
//          console.log("Called Simple contract constructor. Setting value to 5.");
//          value = 5;
//      }
//  }
const simpleSol = "0x608060405261002f6040518060600160405280603781526020016104016037913961003c60201b6100541760201c565b60056000819055506101bb565b6100d8816040516024016100509190610199565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100db60201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561013a57808201518184015260208101905061011f565b83811115610149576000848401525b50505050565b6000601f19601f8301169050919050565b600061016b82610100565b610175818561010b565b935061018581856020860161011c565b61018e8161014f565b840191505092915050565b600060208201905081810360008301526101b38184610160565b905092915050565b610237806101ca6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80633fa4f24514610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b60005481565b6100ea8160405160240161006891906101df565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100ed565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b6000819050919050565b61012581610112565b82525050565b6000602082019050610140600083018461011c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610180578082015181840152602081019050610165565b8381111561018f576000848401525b50505050565b6000601f19601f8301169050919050565b60006101b182610146565b6101bb8185610151565b93506101cb818560208601610162565b6101d481610195565b840191505092915050565b600060208201905081810360008301526101f981846101a6565b90509291505056fea26469706673582212205402181d93a2ec38e277cfd7fa6bdb14ae069535ac31572e1c94c713cddb891264736f6c634300080b003343616c6c65642053696d706c6520636f6e747261637420636f6e7374727563746f722e2053657474696e672076616c756520746f20352e";
const [from] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", data: simpleSol }] });
const txReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });
const code = await provider.request({ method: "eth_getCode", params: [txReceipt.contractAddress, "latest"] });
console.log(code);

eth_getCompilers(): Promise<string[]>

Returns a list of available compilers.

returns
Promise<string[]>

: List of available compilers.

example
const compilers = await provider.send("eth_getCompilers");
console.log(compilers);

eth_getFilterChanges(filterId: string): Promise<DATA[]>

Polling method for a filter, which returns an array of logs, block hashes, or transaction hashes, depending on the filter type, which occurred since last poll.

arguments
  • filterId: string: The filter id.
returns
Promise<DATA[]>

: An array of logs, block hashes, or transaction hashes, depending on the filter type, which occurred since last poll.

For filters created with eth_newBlockFilter the return are block hashes (DATA, 32 Bytes).

For filters created with eth_newPendingTransactionFilter the return are transaction hashes (DATA, 32 Bytes).

For filters created with eth_newFilter the return are log objects with the following parameters:

  • removed: TAG - true when the log was removed, false if its a valid log.
  • logIndex: QUANTITY - Integer of the log index position in the block. null when pending.
  • transactionIndex: QUANTITY - Integer of the transactions index position. null when pending.
  • transactionHash: DATA, 32 Bytes - Hash of the transaction where the log was. null when pending.
  • blockHash: DATA, 32 Bytes - Hash of the block where the log was. null when pending.
  • blockNumber: QUANTITY - The block number where the log was in. null when pending.
  • address: DATA, 20 Bytes - The address from which the log originated.
  • data: DATA - Contains one or more 32 Bytes non-indexed arguments of the log.
  • topics: Array of DATA - Array of 0 to 4 32 Bytes DATA of indexed log arguments.
example
// Logs.sol
// // SPDX-License-Identifier: MIT
// pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
// contract Logs {
//   event Event(uint256 indexed first, uint256 indexed second);
//   constructor() {
//     console.log("Entered Logs contract constructor.");
//     emit Event(1, 2);
//   }
//
//   function logNTimes(uint8 n) public {
//     console.log("Called logNTimes with the parameter: %o", n);
//     for (uint8 i = 0; i < n; i++) {
//       emit Event(i, i);
//     }
//   }
// }

const logsContract = "0x608060405234801561001057600080fd5b5061003c60405180606001604052806022815260200161064b6022913961007160201b6100cd1760201c565b600260017f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a36101f0565b61010d8160405160240161008591906101ce565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061011060201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561016f578082015181840152602081019050610154565b8381111561017e576000848401525b50505050565b6000601f19601f8301169050919050565b60006101a082610135565b6101aa8185610140565b93506101ba818560208601610151565b6101c381610184565b840191505092915050565b600060208201905081810360008301526101e88184610195565b905092915050565b61044c806101ff6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80635e19e69f14610030575b600080fd5b61004a60048036038101906100459190610265565b61004c565b005b6100716040518060600160405280602781526020016103f0602791398260ff16610166565b60005b8160ff168160ff1610156100c9578060ff168160ff167f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a380806100c1906102c1565b915050610074565b5050565b610163816040516024016100e19190610384565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610202565b50565b6101fe828260405160240161017c9291906103bf565b6040516020818303038152906040527fb60e72cc000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610202565b5050565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600080fd5b600060ff82169050919050565b6102428161022c565b811461024d57600080fd5b50565b60008135905061025f81610239565b92915050565b60006020828403121561027b5761027a610227565b5b600061028984828501610250565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006102cc8261022c565b915060ff8214156102e0576102df610292565b5b600182019050919050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561032557808201518184015260208101905061030a565b83811115610334576000848401525b50505050565b6000601f19601f8301169050919050565b6000610356826102eb565b61036081856102f6565b9350610370818560208601610307565b6103798161033a565b840191505092915050565b6000602082019050818103600083015261039e818461034b565b905092915050565b6000819050919050565b6103b9816103a6565b82525050565b600060408201905081810360008301526103d9818561034b565b90506103e860208301846103b0565b939250505056fe43616c6c6564206c6f674e54696d657320776974682074686520706172616d657465723a20256fa2646970667358221220efe39b9dc769a10eb54b65df8344ee92d584288e80e1c170636e1ede5dd7c3e064736f6c634300080b0033456e7465726564204c6f677320636f6e747261637420636f6e7374727563746f722e";
const [from] = await provider.send("eth_accounts");
const filterId = await provider.send("eth_newFilter");

const subscriptionId = await provider.send("eth_subscribe", ["newHeads"]);
await provider.send("eth_sendTransaction", [{ from, data: logsContract, gas: "0x5b8d80" }] );

const changes = await provider.request({ method: "eth_getFilterChanges", params: [filterId] });
console.log(changes);

await provider.send("eth_unsubscribe", [subscriptionId]);

eth_getFilterLogs(filterId: string): Promise<Logs>

Returns an array of all logs matching filter with given id.

arguments
  • filterId: string: The filter id.
returns
Promise<Logs>

: Array of log objects, or an empty array.

example
// Logs.sol
// // SPDX-License-Identifier: MIT
// pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
// contract Logs {
//   event Event(uint256 indexed first, uint256 indexed second);
//   constructor() {
//     console.log("Entered Logs contract constructor.");
//     emit Event(1, 2);
//   }
//
//   function logNTimes(uint8 n) public {
//     console.log("Called logNTimes with the parameter: %o", n);
//     for (uint8 i = 0; i < n; i++) {
//       emit Event(i, i);
//     }
//   }
// }

const logsContract = "0x608060405234801561001057600080fd5b5061003c60405180606001604052806022815260200161064b6022913961007160201b6100cd1760201c565b600260017f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a36101f0565b61010d8160405160240161008591906101ce565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061011060201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561016f578082015181840152602081019050610154565b8381111561017e576000848401525b50505050565b6000601f19601f8301169050919050565b60006101a082610135565b6101aa8185610140565b93506101ba818560208601610151565b6101c381610184565b840191505092915050565b600060208201905081810360008301526101e88184610195565b905092915050565b61044c806101ff6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80635e19e69f14610030575b600080fd5b61004a60048036038101906100459190610265565b61004c565b005b6100716040518060600160405280602781526020016103f0602791398260ff16610166565b60005b8160ff168160ff1610156100c9578060ff168160ff167f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a380806100c1906102c1565b915050610074565b5050565b610163816040516024016100e19190610384565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610202565b50565b6101fe828260405160240161017c9291906103bf565b6040516020818303038152906040527fb60e72cc000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610202565b5050565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600080fd5b600060ff82169050919050565b6102428161022c565b811461024d57600080fd5b50565b60008135905061025f81610239565b92915050565b60006020828403121561027b5761027a610227565b5b600061028984828501610250565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006102cc8261022c565b915060ff8214156102e0576102df610292565b5b600182019050919050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561032557808201518184015260208101905061030a565b83811115610334576000848401525b50505050565b6000601f19601f8301169050919050565b6000610356826102eb565b61036081856102f6565b9350610370818560208601610307565b6103798161033a565b840191505092915050565b6000602082019050818103600083015261039e818461034b565b905092915050565b6000819050919050565b6103b9816103a6565b82525050565b600060408201905081810360008301526103d9818561034b565b90506103e860208301846103b0565b939250505056fe43616c6c6564206c6f674e54696d657320776974682074686520706172616d657465723a20256fa2646970667358221220efe39b9dc769a10eb54b65df8344ee92d584288e80e1c170636e1ede5dd7c3e064736f6c634300080b0033456e7465726564204c6f677320636f6e747261637420636f6e7374727563746f722e";
const [from] = await provider.send("eth_accounts");
const filterId = await provider.send("eth_newFilter");

await provider.send("eth_subscribe", ["newHeads"]);
await provider.send("eth_sendTransaction", [{ from, data: logsContract, gas: "0x5b8d80" }] );

const logs = await provider.request({ method: "eth_getFilterLogs", params: [filterId] });
console.log(logs);

eth_getLogs(filter: FilterArgs): Promise<Logs>

Returns an array of all logs matching a given filter object.

Filter options:

  • fromBlock: QUANTITY | TAG (optional) - Integer block number, or the string "latest", "earliest" or "pending".
  • toBlock: QUANTITY | TAG (optional) - Integer block number, or the string "latest", "earliest" or "pending".
  • address: DATA | Array (optional) - Contract address or a list of addresses from which the logs should originate.
  • topics: Array of DATA (optional) - Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options.
  • blockHash: DATA, 32 Bytes (optional) - Hash of the block to restrict logs from. If blockHash is present, then neither fromBlock or toBlock are allowed.
arguments
  • filter: FilterArgs: The filter options as seen in source.
returns
Promise<Logs>

: Array of log objects, or an empty array.

example
// Logs.sol
// // SPDX-License-Identifier: MIT
// pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
// contract Logs {
//   event Event(uint256 indexed first, uint256 indexed second);
//   constructor() {
//     console.log("Entered Logs contract constructor.");
//     emit Event(1, 2);
//   }
//
//   function logNTimes(uint8 n) public {
//     console.log("Called logNTimes with the parameter: %o", n);
//     for (uint8 i = 0; i < n; i++) {
//       emit Event(i, i);
//     }
//   }
// }

const logsContract = "0x608060405234801561001057600080fd5b5061003c60405180606001604052806022815260200161064b6022913961007160201b6100cd1760201c565b600260017f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a36101f0565b61010d8160405160240161008591906101ce565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061011060201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561016f578082015181840152602081019050610154565b8381111561017e576000848401525b50505050565b6000601f19601f8301169050919050565b60006101a082610135565b6101aa8185610140565b93506101ba818560208601610151565b6101c381610184565b840191505092915050565b600060208201905081810360008301526101e88184610195565b905092915050565b61044c806101ff6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80635e19e69f14610030575b600080fd5b61004a60048036038101906100459190610265565b61004c565b005b6100716040518060600160405280602781526020016103f0602791398260ff16610166565b60005b8160ff168160ff1610156100c9578060ff168160ff167f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a380806100c1906102c1565b915050610074565b5050565b610163816040516024016100e19190610384565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610202565b50565b6101fe828260405160240161017c9291906103bf565b6040516020818303038152906040527fb60e72cc000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050610202565b5050565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600080fd5b600060ff82169050919050565b6102428161022c565b811461024d57600080fd5b50565b60008135905061025f81610239565b92915050565b60006020828403121561027b5761027a610227565b5b600061028984828501610250565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006102cc8261022c565b915060ff8214156102e0576102df610292565b5b600182019050919050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561032557808201518184015260208101905061030a565b83811115610334576000848401525b50505050565b6000601f19601f8301169050919050565b6000610356826102eb565b61036081856102f6565b9350610370818560208601610307565b6103798161033a565b840191505092915050565b6000602082019050818103600083015261039e818461034b565b905092915050565b6000819050919050565b6103b9816103a6565b82525050565b600060408201905081810360008301526103d9818561034b565b90506103e860208301846103b0565b939250505056fe43616c6c6564206c6f674e54696d657320776974682074686520706172616d657465723a20256fa2646970667358221220efe39b9dc769a10eb54b65df8344ee92d584288e80e1c170636e1ede5dd7c3e064736f6c634300080b0033456e7465726564204c6f677320636f6e747261637420636f6e7374727563746f722e";
const [from] = await provider.send("eth_accounts");

await provider.send("eth_subscribe", ["newHeads"]);
const txHash = await provider.send("eth_sendTransaction", [{ from, data: logsContract, gas: "0x5b8d80" }] );

const { contractAddress } = await provider.send("eth_getTransactionReceipt", [txHash] );

const logs = await provider.request({ method: "eth_getLogs", params: [{ address: contractAddress }] });
console.log(logs);

eth_getProof(address: string, storageKeys: string[], blockNumber: string): Promise<AccountProof>

Returns the details for the account at the specified address and block number, the account's Merkle proof, and the storage values for the specified storage keys with their Merkle-proofs.

arguments
  • address: string: Address of the account
  • storageKeys: string[]: Array of storage keys to be proofed.
  • blockNumber: string: A block number, or the string "earliest", "latest", or "pending".
returns
Promise<AccountProof>

: An object containing the details for the account at the specified address and block number, the account's Merkle proof, and the storage-values for the specified storage keys with their Merkle-proofs:

  • balance: QUANTITY - the balance of the account.
  • codeHash: DATA - 32 Bytes - hash of the account. A simple account without code will return "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
  • nonce: QUANTITY - the nonce of the account.
  • storageHash: DATA - 32 Bytes - SHA3 of the StorageRoot. All storage will deliver a MerkleProof starting with this rootHash.
  • accountProof: Array - Array of rlp-serialized MerkleTree-Nodes, starting with the stateRoot-NODE, following the path of the SHA3 (address) as key.
  • storageProof: Array - Array of storage entries as requested. Each entry is an object with the following properties:
    • key: DATA - the requested storage key.
    • value: QUANTITY - the storage value.
    • proof: Array - Array of rlp-serialized MerkleTree-Nodes, starting with the storageHash-Node, following the path of the SHA3 (key) as path.
example
// Simple.sol
// // SPDX-License-Identifier: MIT
//  pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
//  contract Simple {
//      uint256 public value;
//      constructor() payable {
//          console.log("Called Simple contract constructor. Setting `value` to 5.");
//          value = 5;
//      }
//  }
const simpleSol = "0x608060405261002f6040518060600160405280603781526020016104016037913961003c60201b6100541760201c565b60056000819055506101bb565b6100d8816040516024016100509190610199565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100db60201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561013a57808201518184015260208101905061011f565b83811115610149576000848401525b50505050565b6000601f19601f8301169050919050565b600061016b82610100565b610175818561010b565b935061018581856020860161011c565b61018e8161014f565b840191505092915050565b600060208201905081810360008301526101b38184610160565b905092915050565b610237806101ca6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80633fa4f24514610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b60005481565b6100ea8160405160240161006891906101df565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100ed565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b6000819050919050565b61012581610112565b82525050565b6000602082019050610140600083018461011c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610180578082015181840152602081019050610165565b8381111561018f576000848401525b50505050565b6000601f19601f8301169050919050565b60006101b182610146565b6101bb8185610151565b93506101cb818560208601610162565b6101d481610195565b840191505092915050565b600060208201905081810360008301526101f981846101a6565b90509291505056fea26469706673582212205402181d93a2ec38e277cfd7fa6bdb14ae069535ac31572e1c94c713cddb891264736f6c634300080b003343616c6c65642053696d706c6520636f6e747261637420636f6e7374727563746f722e2053657474696e672076616c756520746f20352e";
const [from] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", data: simpleSol }] });
const txReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });
const proof = await provider.request({ method: "eth_getProof", params: [txReceipt.contractAddress, ["0x0", "0x1"], "latest"] });
console.log(proof);

eth_getStorageAt(address: string, position: string, blockNumber: string): Promise<DATA>

Returns the value from a storage position at a given address.

arguments
  • address: string: Address of the storage.
  • position: string: Integer of the position in the storage.
  • blockNumber: string: Integer block number, or the string "latest", "earliest" or "pending".
returns
Promise<DATA>

: The value in storage at the requested position.

example
// Simple.sol
// // SPDX-License-Identifier: MIT
//  pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
//  contract Simple {
//      uint256 public value;
//      constructor() payable {
//          console.log("Called Simple contract constructor. Setting value to 5.");
//          value = 5;
//      }
//  }
const simpleSol = "0x608060405261002f6040518060600160405280603781526020016104016037913961003c60201b6100541760201c565b60056000819055506101bb565b6100d8816040516024016100509190610199565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100db60201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561013a57808201518184015260208101905061011f565b83811115610149576000848401525b50505050565b6000601f19601f8301169050919050565b600061016b82610100565b610175818561010b565b935061018581856020860161011c565b61018e8161014f565b840191505092915050565b600060208201905081810360008301526101b38184610160565b905092915050565b610237806101ca6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80633fa4f24514610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b60005481565b6100ea8160405160240161006891906101df565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100ed565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b6000819050919050565b61012581610112565b82525050565b6000602082019050610140600083018461011c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610180578082015181840152602081019050610165565b8381111561018f576000848401525b50505050565b6000601f19601f8301169050919050565b60006101b182610146565b6101bb8185610151565b93506101cb818560208601610162565b6101d481610195565b840191505092915050565b600060208201905081810360008301526101f981846101a6565b90509291505056fea26469706673582212205402181d93a2ec38e277cfd7fa6bdb14ae069535ac31572e1c94c713cddb891264736f6c634300080b003343616c6c65642053696d706c6520636f6e747261637420636f6e7374727563746f722e2053657474696e672076616c756520746f20352e";
const [from] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", data: simpleSol }] });
const txReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });
const storageValue = await provider.request({ method: "eth_getStorageAt", params: [txReceipt.contractAddress, "0x0", "latest"] });
console.log(storageValue);

eth_getTransactionByBlockHashAndIndex(hash: string, index: string): Promise<LegacyTransactionJSON | EIP1559FeeMarketTransactionJSON | EIP2930AccessListTransactionJSON>

Returns information about a transaction by block hash and transaction index position.

arguments
  • hash: string: Hash of a block.
  • index: string: Integer of the transaction index position.
returns
Promise<LegacyTransactionJSON | EIP1559FeeMarketTransactionJSON | EIP2930AccessListTransactionJSON>

: The transaction object or null if no transaction was found.

  • hash: DATA, 32 Bytes - The transaction hash.
  • nonce: QUANTITY - The number of transactions made by the sender prior to this one.
  • blockHash: DATA, 32 Bytes - The hash of the block the transaction is in. null when pending.
  • blockNumber: QUANTITY - The number of the block the transaction is in. null when pending.
  • transactionIndex: QUANTITY - The index position of the transaction in the block.
  • from: DATA, 20 Bytes - The address the transaction is sent from.
  • to: DATA, 20 Bytes - The address the transaction is sent to.
  • value: QUANTITY - The value transferred in wei.
  • gas: QUANTITY - The gas provided by the sender.
  • gasPrice: QUANTITY - The price of gas in wei.
  • input: DATA - The data sent along with the transaction.
  • v: QUANTITY - ECDSA recovery id.
  • r: DATA, 32 Bytes - ECDSA signature r.
  • s: DATA, 32 Bytes - ECDSA signature s.
example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, to, gas: "0x5b8d80" }] });
const { blockHash, transactionIndex } = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });

const tx = await provider.request({ method: "eth_getTransactionByBlockHashAndIndex", params: [ blockHash, transactionIndex ] });
console.log(tx);

eth_getTransactionByBlockNumberAndIndex(number: string, index: string): Promise<LegacyTransactionJSON | EIP1559FeeMarketTransactionJSON | EIP2930AccessListTransactionJSON>

Returns information about a transaction by block number and transaction index position.

arguments
  • number: string: A block number, or the string "earliest", "latest" or "pending".
  • index: string: Integer of the transaction index position.
returns
Promise<LegacyTransactionJSON | EIP1559FeeMarketTransactionJSON | EIP2930AccessListTransactionJSON>

: The transaction object or null if no transaction was found.

  • hash: DATA, 32 Bytes - The transaction hash.
  • nonce: QUANTITY - The number of transactions made by the sender prior to this one.
  • blockHash: DATA, 32 Bytes - The hash of the block the transaction is in. null when pending.
  • blockNumber: QUANTITY - The number of the block the transaction is in. null when pending.
  • transactionIndex: QUANTITY - The index position of the transaction in the block.
  • from: DATA, 20 Bytes - The address the transaction is sent from.
  • to: DATA, 20 Bytes - The address the transaction is sent to.
  • value: QUANTITY - The value transferred in wei.
  • gas: QUANTITY - The gas provided by the sender.
  • gasPrice: QUANTITY - The price of gas in wei.
  • input: DATA - The data sent along with the transaction.
  • v: QUANTITY - ECDSA recovery id.
  • r: DATA, 32 Bytes - ECDSA signature r.
  • s: DATA, 32 Bytes - ECDSA signature s.
example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, to, gas: "0x5b8d80" }] });
const { transactionIndex } = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });

const tx = await provider.request({ method: "eth_getTransactionByBlockNumberAndIndex", params: [ "latest", transactionIndex ] });
console.log(tx);

eth_getTransactionByHash(transactionHash: string): Promise<LegacyTransactionJSON | EIP1559FeeMarketTransactionJSON | EIP2930AccessListTransactionJSON | Transaction>

Returns the information about a transaction requested by transaction hash.

arguments
  • transactionHash: string: Hash of a transaction.
returns
Promise<LegacyTransactionJSON | EIP1559FeeMarketTransactionJSON | EIP2930AccessListTransactionJSON | Transaction>

: The transaction object or null if no transaction was found.

  • hash: DATA, 32 Bytes - The transaction hash.
  • nonce: QUANTITY - The number of transactions made by the sender prior to this one.
  • blockHash: DATA, 32 Bytes - The hash of the block the transaction is in. null when pending.
  • blockNumber: QUANTITY - The number of the block the transaction is in. null when pending.
  • transactionIndex: QUANTITY - The index position of the transaction in the block.
  • from: DATA, 20 Bytes - The address the transaction is sent from.
  • to: DATA, 20 Bytes - The address the transaction is sent to.
  • value: QUANTITY - The value transferred in wei.
  • gas: QUANTITY - The gas provided by the sender.
  • gasPrice: QUANTITY - The price of gas in wei.
  • input: DATA - The data sent along with the transaction.
  • v: QUANTITY - ECDSA recovery id.
  • r: DATA, 32 Bytes - ECDSA signature r.
  • s: DATA, 32 Bytes - ECDSA signature s.
example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, to, gas: "0x5b8d80" }] });

const tx = await provider.request({ method: "eth_getTransactionByHash", params: [ txHash ] });
console.log(tx);

eth_getTransactionCount(address: string, blockNumber: string): Promise<QUANTITY>

Returns the number of transactions sent from an address.

arguments
  • address: string: DATA, 20 Bytes - The address to get number of transactions sent from
  • blockNumber: string: Integer block number, or the string "latest", "earliest" or "pending".
returns
Promise<QUANTITY>

: Number of transactions sent from this address.

example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
await provider.request({ method: "eth_sendTransaction", params: [{ from, to, gas: "0x5b8d80" }] });

const txCount = await provider.request({ method: "eth_getTransactionCount", params: [ from, "latest" ] });
console.log(txCount);

eth_getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>

Returns the receipt of a transaction by transaction hash.

Note: The receipt is not available for pending transactions.

arguments
  • transactionHash: string: Hash of a transaction.
returns
Promise<TransactionReceipt>

: Returns the receipt of a transaction by transaction hash.

example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, to, gas: "0x5b8d80" }] });

const txReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [ txHash ] });
console.log(txReceipt);

eth_getUncleByBlockHashAndIndex(hash: string, index: string): Promise<Omit>

Returns information about a uncle of a block by hash and uncle index position.

arguments
  • hash: string: Hash of a block.
  • index: string: The uncle's index position.
returns
Promise<Omit>

: A block object or null when no block is found.

  • hash: DATA, 32 Bytes - Hash of the block. null when pending.
  • parentHash: DATA, 32 Bytes - Hash of the parent block.
  • sha3Uncles: DATA, 32 Bytes - SHA3 of the uncles data in the block.
  • miner: DATA, 20 Bytes - Address of the miner.
  • stateRoot: DATA, 32 Bytes - The root of the state trie of the block.
  • transactionsRoot: DATA, 32 Bytes - The root of the transaction trie of the block.
  • receiptsRoot: DATA, 32 Bytes - The root of the receipts trie of the block.
  • logsBloom: DATA, 256 Bytes - The bloom filter for the logs of the block. null when pending.
  • difficulty: QUANTITY - Integer of the difficulty of this block.
  • number: QUANTITY - The block number. null when pending.
  • gasLimit: QUANTITY - The maximum gas allowed in the block.
  • gasUsed: QUANTITY - Total gas used by all transactions in the block.
  • timestamp: QUANTITY - The unix timestamp for when the block was collated.
  • extraData: DATA - Extra data for the block.
  • mixHash: DATA, 256 Bytes - Hash identifier for the block.
  • nonce: DATA, 8 Bytes - Hash of the generated proof-of-work. null when pending.
  • totalDifficulty: QUANTITY - Integer of the total difficulty of the chain until this block.
  • size: QUANTITY - Integer the size of the block in bytes.
  • uncles: Array - Array of uncle hashes.

**NOTE: **The return does not contain a list of transactions in the uncle block, to get this, make another request to eth_getBlockByHash.

example
const blockHash = await provider.send("eth_getBlockByNumber", ["latest"] );
const block = await provider.send("eth_getUncleByBlockHashAndIndex", [blockHash, "0x0"] );
console.log(block);

eth_getUncleByBlockNumberAndIndex(blockNumber: string, uncleIndex: string): Promise<Omit>

Returns information about a uncle of a block by hash and uncle index position.

arguments
  • blockNumber: string: A block number, or the string "earliest", "latest" or "pending".
  • uncleIndex: string: The uncle's index position.
returns
Promise<Omit>

: A block object or null when no block is found.

  • hash: DATA, 32 Bytes - Hash of the block. null when pending.

  • parentHash: DATA, 32 Bytes - Hash of the parent block.

  • sha3Uncles: DATA, 32 Bytes - SHA3 of the uncles data in the block.

  • miner: DATA, 20 Bytes - Address of the miner.

  • stateRoot: DATA, 32 Bytes - The root of the state trie of the block.

  • transactionsRoot: DATA, 32 Bytes - The root of the transaction trie of the block.

  • receiptsRoot: DATA, 32 Bytes - The root of the receipts trie of the block.

  • logsBloom: DATA, 256 Bytes - The bloom filter for the logs of the block. null when pending.

  • difficulty: QUANTITY - Integer of the difficulty of this block.

  • number: QUANTITY - The block number. null when pending.

  • gasLimit: QUANTITY - The maximum gas allowed in the block.

  • gasUsed: QUANTITY - Total gas used by all transactions in the block.

  • timestamp: QUANTITY - The unix timestamp for when the block was collated.

  • extraData: DATA - Extra data for the block.

  • mixHash: DATA, 256 Bytes - Hash identifier for the block.

  • nonce: DATA, 8 Bytes - Hash of the generated proof-of-work. null when pending.

  • totalDifficulty: QUANTITY - Integer of the total difficulty of the chain until this block.

  • size: QUANTITY - Integer the size of the block in bytes.

  • uncles: Array - Array of uncle hashes.

  • **NOTE: **The return does not contain a list of transactions in the uncle block, to get this, make another request to eth_getBlockByHash.

example
const block = await provider.send("eth_getUncleByBlockNumberAndIndex", ["latest", "0x0"] );
console.log(block);

eth_getUncleCountByBlockHash(hash: string): Promise<QUANTITY>

Returns the number of uncles in a block from a block matching the given block hash.

arguments
  • hash: string: Hash of a block.
returns
Promise<QUANTITY>

: The number of uncles in a block.

example
const blockHash = await provider.send("eth_getBlockByNumber", ["latest"] );
const uncleCount = await provider.send("eth_getUncleCountByBlockHash", [blockHash] );
console.log(uncleCount);

eth_getUncleCountByBlockNumber(blockNumber: string): Promise<QUANTITY>

Returns the number of uncles in a block from a block matching the given block hash.

arguments
  • blockNumber: string: A block number, or the string "earliest", "latest" or "pending".
returns
Promise<QUANTITY>

: The number of uncles in a block.

example
const uncleCount = await provider.send("eth_getUncleCountByBlockNumber", ["latest"] );
console.log(uncleCount);

eth_getWork(): Promise<[] | [string, string, string]>

Returns: An Array with the following elements 1: DATA, 32 Bytes - current block header pow-hash 2: DATA, 32 Bytes - the seed hash used for the DAG. 3: DATA, 32 Bytes - the boundary condition ("target"), 2^256 / difficulty.

returns
Promise<[] | [string, string, string]>

: The hash of the current block, the seedHash, and the boundary condition to be met ("target").

example
console.log(await provider.send("eth_getWork", [] ));

eth_hashrate(): Promise<QUANTITY>

Returns the number of hashes per second that the node is mining with.

returns
Promise<QUANTITY>

: Number of hashes per second.

example
const hashrate = await provider.request({ method: "eth_hashrate", params: [] });
console.log(hashrate);

eth_maxPriorityFeePerGas(): Promise<QUANTITY>

Returns a maxPriorityFeePerGas value suitable for quick transaction inclusion.

returns
Promise<QUANTITY>

: The maxPriorityFeePerGas in wei.

example
const suggestedTip = await provider.request({ method: "eth_maxPriorityFeePerGas", params: [] });
console.log(suggestedTip);

eth_mining(): Promise<boolean>

Returns true if client is actively mining new blocks.

returns
Promise<boolean>

: returns true if the client is mining, otherwise false.

example
const isMining = await provider.request({ method: "eth_mining", params: [] });
console.log(isMining);

eth_newBlockFilter(): Promise<QUANTITY>

Creates a filter in the node, to notify when a new block arrives. To check if the state has changed, call eth_getFilterChanges.

returns
Promise<QUANTITY>

: A filter id.

example
const filterId = await provider.request({ method: "eth_newBlockFilter", params: [] });
console.log(filterId);

eth_newFilter(filter?: RangeFilterArgs): Promise<QUANTITY>

Creates a filter object, based on filter options, to notify when the state changes (logs). To check if the state has changed, call eth_getFilterChanges.

If the from fromBlock or toBlock option are equal to "latest" the filter continually append logs for whatever block is seen as latest at the time the block was mined, not just for the block that was "latest" when the filter was created.

A note on specifying topic filters:

Topics are order-dependent. A transaction with a log with topics [A, B] will be matched by the following topic filters:

  • [] “anything”
  • [A] “A in first position (and anything after)”
  • [null, B] “anything in first position AND B in second position (and anything after)”
  • [A, B] “A in first position AND B in second position (and anything after)”
  • [[A, B], [A, B]] “(A OR B) in first position AND (A OR B) in second position (and anything after)”

Filter options:

  • fromBlock: QUANTITY | TAG (optional) - Integer block number, or the string "latest", "earliest" or "pending".
  • toBlock: QUANTITY | TAG (optional) - Integer block number, or the string "latest", "earliest" or "pending".
  • address: DATA | Array (optional) - Contract address or a list of addresses from which the logs should originate.
  • topics: Array of DATA (optional) - Array of 32 Bytes DATA topics. Topics are order-dependent. Each topic can also be an array of DATA with "or" options.
arguments
  • filter?: RangeFilterArgs: The filter options as seen in source.
returns
Promise<QUANTITY>

: A filter id.

example
const filterId = await provider.request({ method: "eth_newFilter", params: [] });
console.log(filterId);

eth_newPendingTransactionFilter(): Promise<QUANTITY>

Creates a filter in the node, to notify when new pending transactions arrive. To check if the state has changed, call eth_getFilterChanges.

returns
Promise<QUANTITY>

: A filter id.

example
const filterId = await provider.request({ method: "eth_newPendingTransactionFilter", params: [] });
console.log(filterId);

eth_protocolVersion(): Promise<DATA>

Returns the current ethereum protocol version.

returns
Promise<DATA>

: The current ethereum protocol version.

example
const version = await provider.request({ method: "eth_protocolVersion", params: [] });
console.log(version);

eth_sendRawTransaction(transaction: string): Promise<DATA>

Creates new message call transaction or a contract creation for signed transactions.

arguments
  • transaction: string: The signed transaction data.
returns
Promise<DATA>

: The transaction hash.

example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
const signedTx = await provider.request({ method: "eth_signTransaction", params: [{ from, to, gas: "0x5b8d80", maxFeePerGas: "0xffffffff" }] });
const txHash = await provider.send("eth_sendRawTransaction", [signedTx] );
console.log(txHash);

eth_sendTransaction(transaction: Transaction): Promise<DATA>

Creates new message call transaction or a contract creation, if the data field contains code.

Transaction call object:

  • from: DATA, 20 bytes (optional) - The address the transaction is sent from.
  • to: DATA, 20 bytes - The address the transaction is sent to.
  • gas: QUANTITY (optional) - Integer of the maximum gas allowance for the transaction.
  • gasPrice: QUANTITY (optional) - Integer of the price of gas in wei.
  • value: QUANTITY (optional) - Integer of the value in wei.
  • data: DATA (optional) - Hash of the method signature and the ABI encoded parameters.
arguments
  • transaction: Transaction: The transaction call object as seen in source.
returns
Promise<DATA>

: The transaction hash.

example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, to, gas: "0x5b8d80" }] });
console.log(txHash);

eth_sign(address: string, message: string): Promise<string>

The sign method calculates an Ethereum specific signature with: sign(keccak256("\x19Ethereum Signed Message:\n" + message.length + message))).

By adding a prefix to the message makes the calculated signature recognizable as an Ethereum specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim.

Note the address to sign with must be unlocked.

arguments
  • address: string: Address to sign with.
  • message: string: Message to sign.
returns
Promise<string>

: Signature - a hex encoded 129 byte array starting with 0x. It encodes the r, s, and v parameters from appendix F of the yellow paper in big-endian format. Bytes 0...64 contain the r parameter, bytes 64...128 the s parameter, and the last byte the v parameter. Note that the v parameter includes the chain id as specified in EIP-155.

example
const [account] = await provider.request({ method: "eth_accounts", params: [] });
const msg = "0x307866666666666666666666";
const signature = await provider.request({ method: "eth_sign", params: [account, msg] });
console.log(signature);

eth_signTransaction(transaction: Transaction): Promise<DATA>

Signs a transaction that can be submitted to the network at a later time using eth_sendRawTransaction.

Transaction call object:

  • from: DATA, 20 bytes (optional) - The address the transaction is sent from.
  • to: DATA, 20 bytes - The address the transaction is sent to.
  • gas: QUANTITY (optional) - Integer of the maximum gas allowance for the transaction.
  • gasPrice: QUANTITY (optional) - Integer of the price of gas in wei.
  • value: QUANTITY (optional) - Integer of the value in wei.
  • data: DATA (optional) - Hash of the method signature and the ABI encoded parameters.
arguments
  • transaction: Transaction: The transaction call object as seen in source.
returns
Promise<DATA>

: The raw, signed transaction.

example
const [from, to] = await provider.request({ method: "eth_accounts", params: [] });
const signedTx = await provider.request({ method: "eth_signTransaction", params: [{ from, to }] });
console.log(signedTx)

eth_signTypedData(address: string, typedData: TypedMessage): Promise<string>

Identical to eth_signTypedData_v4.

arguments
  • address: string: Address of the account that will sign the messages.
  • typedData: TypedMessage: Typed structured data to be signed.
returns
Promise<string>

: Signature. As in eth_sign, it is a hex encoded 129 byte array starting with 0x. It encodes the r, s, and v parameters from appendix F of the yellow paper in big-endian format. Bytes 0...64 contain the r parameter, bytes 64...128 the s parameter, and the last byte the v parameter. Note that the v parameter includes the chain id as specified in EIP-155.

EIP

712

example
const [account] = await provider.request({ method: "eth_accounts", params: [] });
const typedData = {
 types: {
   EIP712Domain: [
     { name: 'name', type: 'string' },
     { name: 'version', type: 'string' },
     { name: 'chainId', type: 'uint256' },
     { name: 'verifyingContract', type: 'address' },
   ],
   Person: [
     { name: 'name', type: 'string' },
     { name: 'wallet', type: 'address' }
   ],
   Mail: [
     { name: 'from', type: 'Person' },
     { name: 'to', type: 'Person' },
     { name: 'contents', type: 'string' }
   ],
 },
 primaryType: 'Mail',
 domain: {
   name: 'Ether Mail',
   version: '1',
   chainId: 1,
   verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
 },
 message: {
   from: {
     name: 'Cow',
     wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
   },
   to: {
     name: 'Bob',
     wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
   },
   contents: 'Hello, Bob!',
 },
};
const signature = await provider.request({ method: "eth_signTypedData", params: [account, typedData] });
console.log(signature);

eth_signTypedData_v4(address: string, typedData: TypedMessage): Promise<string>

arguments
  • address: string: Address of the account that will sign the messages.
  • typedData: TypedMessage: Typed structured data to be signed.
returns
Promise<string>

: Signature. As in eth_sign, it is a hex encoded 129 byte array starting with 0x. It encodes the r, s, and v parameters from appendix F of the yellow paper in big-endian format. Bytes 0...64 contain the r parameter, bytes 64...128 the s parameter, and the last byte the v parameter. Note that the v parameter includes the chain id as specified in EIP-155.

EIP

712

example
const [account] = await provider.request({ method: "eth_accounts", params: [] });
const typedData = {
 types: {
   EIP712Domain: [
     { name: 'name', type: 'string' },
     { name: 'version', type: 'string' },
     { name: 'chainId', type: 'uint256' },
     { name: 'verifyingContract', type: 'address' },
   ],
   Person: [
     { name: 'name', type: 'string' },
     { name: 'wallet', type: 'address' }
   ],
   Mail: [
     { name: 'from', type: 'Person' },
     { name: 'to', type: 'Person' },
     { name: 'contents', type: 'string' }
   ],
 },
 primaryType: 'Mail',
 domain: {
   name: 'Ether Mail',
   version: '1',
   chainId: 1,
   verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
 },
 message: {
   from: {
     name: 'Cow',
     wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
   },
   to: {
     name: 'Bob',
     wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
   },
   contents: 'Hello, Bob!',
 },
};
const signature = await provider.request({ method: "eth_signTypedData_v4", params: [account, typedData] });
console.log(signature);

eth_submitHashrate(hashRate: string, clientID: string): Promise<boolean>

Used for submitting mining hashrate.

arguments
  • hashRate: string: A hexadecimal string representation (32 bytes) of the hash rate.
  • clientID: string: A random hexadecimal(32 bytes) ID identifying the client.
returns
Promise<boolean>

: true if submitting went through successfully and false otherwise.

example
const hashRate = "0x0000000000000000000000000000000000000000000000000000000000000001";
const clientId = "0xb2222a74119abd18dbcb7d1f661c6578b7bbeb4984c50e66ed538347f606b971";
const result = await provider.request({ method: "eth_submitHashrate", params: [hashRate, clientId] });
console.log(result);

eth_submitWork(nonce: string, powHash: string, digest: string): Promise<boolean>

Used for submitting a proof-of-work solution.

arguments
  • nonce: string: The nonce found (64 bits).
  • powHash: string: The header's pow-hash (256 bits).
  • digest: string: The mix digest (256 bits).
returns
Promise<boolean>

: true if the provided solution is valid, otherwise false.

example
const nonce = "0xe0df4bd14ab39a71";
const powHash = "0x0000000000000000000000000000000000000000000000000000000000000001";
const digest = "0xb2222a74119abd18dbcb7d1f661c6578b7bbeb4984c50e66ed538347f606b971";
const result = await provider.request({ method: "eth_submitWork", params: [nonce, powHash, digest] });
console.log(result);

eth_subscribe(subscriptionName: SubscriptionName): PromiEvent<QUANTITY>

Starts a subscription to a particular event. For every event that matches the subscription a JSON-RPC notification with event details and subscription ID will be sent to a client.

arguments
  • subscriptionName: SubscriptionName: Name for the subscription.
returns
PromiEvent<QUANTITY>

: A subscription id.

example
const subscriptionId = await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
console.log(subscriptionId);

eth_syncing(): Promise<boolean>

Returns an object containing data about the sync status or false when not syncing.

returns
Promise<boolean>

: An object with sync status data or false, when not syncing.

  • startingBlock: {bigint} The block at which the import started (will only be reset, after the sync reached his head).
  • currentBlock: {bigint} The current block, same as eth_blockNumber.
  • highestBlock: {bigint} The estimated highest block.
example
const result = await provider.request({ method: "eth_syncing", params: [] });
console.log(result);

eth_uninstallFilter(filterId: string): Promise<boolean>

Uninstalls a filter with given id. Should always be called when watch is no longer needed.

arguments
  • filterId: string: The filter id.
returns
Promise<boolean>

: true if the filter was successfully uninstalled, otherwise false.

example
const filterId = await provider.request({ method: "eth_newFilter", params: [] });
const result = await provider.request({ method: "eth_uninstallFilter", params: [filterId] });
console.log(result);

eth_unsubscribe(subscriptionId: string): Promise<boolean>

Cancel a subscription to a particular event. Returns a boolean indicating if the subscription was successfully cancelled.

arguments
  • subscriptionId: string: The ID of the subscription to unsubscribe to.
returns
Promise<boolean>

: true if subscription was cancelled successfully, otherwise false.

example
const subscriptionId = await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const result = await provider.request({ method: "eth_unsubscribe", params: [subscriptionId] });
console.log(result);

debug namespace

debug_storageRangeAt(blockHash: string, transactionIndex: number, contractAddress: string, startKey: string, maxResult: number): Promise<StorageRangeAtResult>

Attempts to replay the transaction as it was executed on the network and return storage data given a starting key and max number of entries to return.

arguments
  • blockHash: string: Hash of a block.
  • transactionIndex: number: Integer of the transaction index position.
  • contractAddress: string: Address of the contract.
  • startKey: string: Hash of the start key for grabbing storage entries.
  • maxResult: number: Integer of maximum number of storage entries to return.
returns
Promise<StorageRangeAtResult>

: Returns a storage object with the keys being keccak-256 hashes of the storage keys, and the values being the raw, unhashed key and value for that specific storage slot. Also returns a next key which is the keccak-256 hash of the next key in storage for continuous downloading.

example
// Simple.sol
// // SPDX-License-Identifier: MIT
//  pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
//  contract Simple {
//      uint256 public value;
//      constructor() payable {
//          console.log("Called Simple contract constructor. Setting value to 5.");
//          value = 5;
//      }
//  }
const simpleSol = "0x608060405261002f6040518060600160405280603781526020016104016037913961003c60201b6100541760201c565b60056000819055506101bb565b6100d8816040516024016100509190610199565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100db60201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561013a57808201518184015260208101905061011f565b83811115610149576000848401525b50505050565b6000601f19601f8301169050919050565b600061016b82610100565b610175818561010b565b935061018581856020860161011c565b61018e8161014f565b840191505092915050565b600060208201905081810360008301526101b38184610160565b905092915050565b610237806101ca6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80633fa4f24514610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b60005481565b6100ea8160405160240161006891906101df565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100ed565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b6000819050919050565b61012581610112565b82525050565b6000602082019050610140600083018461011c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610180578082015181840152602081019050610165565b8381111561018f576000848401525b50505050565b6000601f19601f8301169050919050565b60006101b182610146565b6101bb8185610151565b93506101cb818560208601610162565b6101d481610195565b840191505092915050565b600060208201905081810360008301526101f981846101a6565b90509291505056fea26469706673582212205402181d93a2ec38e277cfd7fa6bdb14ae069535ac31572e1c94c713cddb891264736f6c634300080b003343616c6c65642053696d706c6520636f6e747261637420636f6e7374727563746f722e2053657474696e672076616c756520746f20352e";
const [from] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const initialTxHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", data: simpleSol }] });

const {contractAddress} = await provider.request({ method: "eth_getTransactionReceipt", params: [initialTxHash] });

// set value to 19
const data = "0x552410770000000000000000000000000000000000000000000000000000000000000019";
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, to: contractAddress, data }] });

const { blockHash, transactionIndex } = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });
const storage = await provider.request({ method: "debug_storageRangeAt", params: [blockHash, transactionIndex, contractAddress, "0x01", 1] });
console.log(storage);

debug_traceTransaction(transactionHash: string, options: TraceTransactionOptions): Promise<TraceTransactionResult>

Attempt to run the transaction in the exact same manner as it was executed on the network. It will replay any transaction that may have been executed prior to this one before it will finally attempt to execute the transaction that corresponds to the given hash.

In addition to the hash of the transaction you may give it a secondary optional argument, which specifies the options for this specific call. The possible options are:

  • disableStorage: {boolean} Setting this to true will disable storage capture (default = false).
  • disableMemory: {boolean} Setting this to true will disable memory capture (default = false).
  • disableStack: {boolean} Setting this to true will disable stack capture (default = false).
arguments
  • transactionHash: string: Hash of the transaction to trace.
  • options: TraceTransactionOptions: See options in source.
returns
Promise<TraceTransactionResult>

: Returns the gas, structLogs, and returnValue for the traced transaction.

The structLogs are an array of logs, which contains the following fields:

  • depth: The execution depth.
  • error: Information about an error, if one occurred.
  • gas: The number of gas remaining.
  • gasCost: The cost of gas in wei.
  • memory: An array containing the contract's memory data.
  • op: The current opcode.
  • pc: The current program counter.
  • stack: The EVM execution stack.
  • storage: An object containing the contract's storage data.
example
// Simple.sol
// // SPDX-License-Identifier: MIT
//  pragma solidity >= 0.4.22 <0.9.0;
//
// import "console.sol";
//
//  contract Simple {
//      uint256 public value;
//      constructor() payable {
//          console.log("Called Simple contract constructor. Setting value to 5.");
//          value = 5;
//      }
//  }
const simpleSol = "0x608060405261002f6040518060600160405280603781526020016104016037913961003c60201b6100541760201c565b60056000819055506101bb565b6100d8816040516024016100509190610199565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100db60201b60201c565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561013a57808201518184015260208101905061011f565b83811115610149576000848401525b50505050565b6000601f19601f8301169050919050565b600061016b82610100565b610175818561010b565b935061018581856020860161011c565b61018e8161014f565b840191505092915050565b600060208201905081810360008301526101b38184610160565b905092915050565b610237806101ca6000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80633fa4f24514610030575b600080fd5b61003861004e565b604051610045919061012b565b60405180910390f35b60005481565b6100ea8160405160240161006891906101df565b6040516020818303038152906040527f41304fac000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506100ed565b50565b60006a636f6e736f6c652e6c6f6790508151602083016000808383865afa5050505050565b6000819050919050565b61012581610112565b82525050565b6000602082019050610140600083018461011c565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610180578082015181840152602081019050610165565b8381111561018f576000848401525b50505050565b6000601f19601f8301169050919050565b60006101b182610146565b6101bb8185610151565b93506101cb818560208601610162565b6101d481610195565b840191505092915050565b600060208201905081810360008301526101f981846101a6565b90509291505056fea26469706673582212205402181d93a2ec38e277cfd7fa6bdb14ae069535ac31572e1c94c713cddb891264736f6c634300080b003343616c6c65642053696d706c6520636f6e747261637420636f6e7374727563746f722e2053657474696e672076616c756520746f20352e";
const [from] = await provider.request({ method: "eth_accounts", params: [] });
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const txHash = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", data: simpleSol }] });
const transactionTrace = await provider.request({ method: "debug_traceTransaction", params: [txHash] });
console.log(transactionTrace);

evm namespace

evm_addAccount(address: string, passphrase: string): Promise<boolean>

Adds any arbitrary account to the personal namespace.

Note: accounts already known to the personal namespace and accounts returned by eth_accounts cannot be re-added using this method.

arguments
  • address: string: The address of the account to add to the personal namespace.
  • passphrase: string: The passphrase used to encrypt the account's private key. NOTE: this passphrase will be needed for all personal namespace calls that require a password.
returns
Promise<boolean>

: true if the account was successfully added. false if the account is already in the personal namespace.

example
const address = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e";
const passphrase = "passphrase"
const result = await provider.send("evm_addAccount", [address, passphrase] );
console.log(result);

evm_increaseTime(seconds: string | number): Promise<number>

Jump forward in time by the given amount of time, in seconds.

arguments
  • seconds: string | number: Number of seconds to jump forward in time by. Must be greater than or equal to 0.
returns
Promise<number>

: Returns the total time adjustment, in seconds.

example
const seconds = 10;
const timeAdjustment = await provider.send("evm_increaseTime", [seconds] );
console.log(timeAdjustment);

evm_mine(): Promise<"0x0">

Force a single block to be mined.

Mines a block independent of whether or not mining is started or stopped. Will mine an empty block if there are no available transactions to mine.

returns
Promise<"0x0">

: The string "0x0". May return additional meta-data in the future.

example
console.log("start", await provider.send("eth_blockNumber"));
await provider.send("evm_mine", [{blocks: 5}] ); // mines 5 blocks
console.log("end", await provider.send("eth_blockNumber"));

evm_removeAccount(address: string, passphrase: string): Promise<boolean>

Removes an account from the personal namespace.

Note: accounts not known to the personal namespace cannot be removed using this method.

arguments
  • address: string: The address of the account to remove from the personal namespace.
  • passphrase: string: The passphrase used to decrypt the account's private key.
returns
Promise<boolean>

: true if the account was successfully removed. false if the account was not in the personal namespace.

example
const [address] = await provider.request({ method: "eth_accounts", params: [] });
const passphrase = "";
const result = await provider.send("evm_removeAccount", [address, passphrase] );
console.log(result);

evm_revert(snapshotId: string): Promise<boolean>

Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which is the snapshot id to revert to. This deletes the given snapshot, as well as any snapshots taken after (e.g.: reverting to id 0x1 will delete snapshots with ids 0x1, 0x2, etc.)

arguments
  • snapshotId: string: The snapshot id to revert.
returns
Promise<boolean>

: true if a snapshot was reverted, otherwise false.

example
const [from, to] = await provider.send("eth_accounts");
const startingBalance = BigInt(await provider.send("eth_getBalance", [from] ));

// take a snapshot
const snapshotId = await provider.send("evm_snapshot");

// send value to another account (over-simplified example)
await provider.send("eth_subscribe", ["newHeads"] );
await provider.send("eth_sendTransaction", [{from, to, value: "0xffff"}] );

// ensure balance has updated
const newBalance = await provider.send("eth_getBalance", [from] );
assert(BigInt(newBalance) < startingBalance);

// revert the snapshot
const isReverted = await provider.send("evm_revert", [snapshotId] );
assert(isReverted);
console.log({isReverted: isReverted});

// ensure balance has reverted
const endingBalance = await provider.send("eth_getBalance", [from] );
const isBalanceReverted = assert.strictEqual(BigInt(endingBalance), startingBalance);
console.log({isBalanceReverted: isBalanceReverted});

evm_setAccountBalance(address: string, balance: string): Promise<boolean>

Sets the given account's balance to the specified WEI value. Mines a new block before returning.

Warning: this will result in an invalid state tree.

arguments
  • address: string: The account address to update.
  • balance: string: The balance value, in WEI, to be set.
returns
Promise<boolean>

: true if it worked, otherwise false.

example
const balance = "0x3e8";
const [address] = await provider.request({ method: "eth_accounts", params: [] });
const result = await provider.send("evm_setAccountBalance", [address, balance] );
console.log(result);

evm_setAccountCode(address: string, code: string): Promise<boolean>

Sets the given account's code to the specified data. Mines a new block before returning.

Warning: this will result in an invalid state tree.

arguments
  • address: string: The account address to update.
  • code: string: The code to be set.
returns
Promise<boolean>

: true if it worked, otherwise false.

example
const data = "0xbaddad42";
const [address] = await provider.request({ method: "eth_accounts", params: [] });
const result = await provider.send("evm_setAccountCode", [address, data] );
console.log(result);

evm_setAccountNonce(address: string, nonce: string): Promise<boolean>

Sets the given account's nonce to the specified value. Mines a new block before returning.

Warning: this will result in an invalid state tree.

arguments
  • address: string: The account address to update.
  • nonce: string: The nonce value to be set.
returns
Promise<boolean>

: true if it worked, otherwise false.

example
const nonce = "0x3e8";
const [address] = await provider.request({ method: "eth_accounts", params: [] });
const result = await provider.send("evm_setAccountNonce", [address, nonce] );
console.log(result);

evm_setAccountStorageAt(address: string, slot: string, value: string): Promise<boolean>

Sets the given account's storage slot to the specified data. Mines a new block before returning.

Warning: this will result in an invalid state tree.

arguments
  • address: string: The account address to update.
  • slot: string: The storage slot that should be set.
  • value: string: The value to be set.
returns
Promise<boolean>

: true if it worked, otherwise false.

example
const slot = "0x0000000000000000000000000000000000000000000000000000000000000005";
const data = "0xbaddad42";
const [address] = await provider.request({ method: "eth_accounts", params: [] });
const result = await provider.send("evm_setAccountStorageAt", [address, slot, data] );
console.log(result);

evm_setTime(time: string | number | Date): Promise<number>

Sets the internal clock time to the given timestamp.

Warning: This will allow you to move backwards in time, which may cause new blocks to appear to be mined before old blocks. This will result in an invalid state.

arguments
  • time: string | number | Date: JavaScript timestamp (millisecond precision).
returns
Promise<number>

: The amount of seconds between the given timestamp and now.

example
const currentDate = Date.now();
await new Promise(resolve => {
  setTimeout(async () => {
    const time = await provider.send("evm_setTime", [currentDate]);
    console.log(time); // should be about two seconds ago
    resolve();
  }, 1000);
});

evm_snapshot(): Promise<QUANTITY>

Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the id of the snapshot that was created. A snapshot can only be reverted once. After a successful evm_revert, the same snapshot id cannot be used again. Consider creating a new snapshot after each evm_revert if you need to revert to the same point multiple times.

returns
Promise<QUANTITY>

: The hex-encoded identifier for this snapshot.

example
const provider = ganache.provider();
const [from, to] = await provider.send("eth_accounts");
const startingBalance = BigInt(await provider.send("eth_getBalance", [from] ));

// take a snapshot
const snapshotId = await provider.send("evm_snapshot");

// send value to another account (over-simplified example)
await provider.send("eth_subscribe", ["newHeads"] );
await provider.send("eth_sendTransaction", [{from, to, value: "0xffff"}] );

// ensure balance has updated
const newBalance = await provider.send("eth_getBalance", [from] );
assert(BigInt(newBalance) < startingBalance);

// revert the snapshot
const isReverted = await provider.send("evm_revert", [snapshotId] );
assert(isReverted);

// ensure balance has reverted
const endingBalance = await provider.send("eth_getBalance", [from] );
const isBalanceReverted = assert.strictEqual(BigInt(endingBalance), startingBalance);
console.log({isBalanceReverted: isBalanceReverted});

miner namespace

miner_setEtherbase(address: string): Promise<boolean>

Sets the etherbase, where mining rewards will go.

arguments
  • address: string: The address where the mining rewards will go.
returns
Promise<boolean>

: true.

example
const [account] = await provider.request({ method: "eth_accounts", params: [] });
console.log(await provider.send("miner_setEtherbase", [account] ));

miner_setExtra(extra: string): Promise<boolean>

Set the extraData block header field a miner can include.

arguments
  • extra: string: The extraData to include.
returns
Promise<boolean>

: If successfully set returns true, otherwise returns an error.

example
console.log(await provider.send("miner_setExtra", ["0x0"] ));

miner_setGasPrice(number: string): Promise<boolean>

Sets the default accepted gas price when mining transactions. Any transactions that don't specify a gas price will use this amount. Transactions that are below this limit are excluded from the mining process.

arguments
  • number: string: Default accepted gas price.
returns
Promise<boolean>

: true.

example
console.log(await provider.send("miner_setGasPrice", [300000] ));

miner_start(threads: number): Promise<boolean>

Resume the CPU mining process with the given number of threads.

Note: threads is ignored.

arguments
  • threads: number: Number of threads to resume the CPU mining process with.
returns
Promise<boolean>

: true.

example
await provider.send("miner_stop");
// check that eth_mining returns false
console.log(await provider.send("eth_mining"));
await provider.send("miner_start");
// check that eth_mining returns true
console.log(await provider.send("eth_mining"));

miner_stop(): Promise<boolean>

Stop the CPU mining operation.

returns
Promise<boolean>

: true.

example
// check that eth_mining returns true
console.log(await provider.send("eth_mining"));
await provider.send("miner_stop");
// check that eth_mining returns false
console.log(await provider.send("eth_mining"));

personal namespace

personal_importRawKey(rawKey: string, passphrase: string): Promise<Address>

Imports the given unencrypted private key (hex string) into the key store, encrypting it with the passphrase.

arguments
  • rawKey: string: The raw, unencrypted private key to import.
  • passphrase: string: The passphrase to encrypt with.
returns
Promise<Address>

: Returns the address of the new account.

example
const rawKey = "0x0123456789012345678901234567890123456789012345678901234567890123";
const passphrase = "passphrase";

const address = await provider.send("personal_importRawKey",[rawKey, passphrase] );
console.log(address);

personal_listAccounts(): Promise<string[]>

Returns all the Ethereum account addresses of all keys that have been added.

returns
Promise<string[]>

: The Ethereum account addresses of all keys that have been added.

example
console.log(await provider.send("personal_listAccounts"));

personal_lockAccount(address: string): Promise<boolean>

Locks the account. The account can no longer be used to send transactions.

arguments
  • address: string: The account address to be locked.
returns
Promise<boolean>

: Returns true if the account was locked, otherwise false.

example
const [account] = await provider.send("personal_listAccounts");
const isLocked = await provider.send("personal_lockAccount", [account] );
console.log(isLocked);

personal_newAccount(passphrase: string): Promise<Address>

Generates a new account with private key. Returns the address of the new account.

arguments
  • passphrase: string: The passphrase to encrypt the private key with.
returns
Promise<Address>

: The new account's address.

example
const passphrase = "passphrase";
const address = await provider.send("personal_newAccount", [passphrase] );
console.log(address);

personal_sendTransaction(transaction: Transaction, passphrase: string): Promise<DATA>

Validate the given passphrase and submit transaction.

The transaction is the same argument as for eth_sendTransaction and contains the from address. If the passphrase can be used to decrypt the private key belonging to tx.from the transaction is verified, signed and send onto the network. The account is not unlocked globally in the node and cannot be used in other RPC calls.

Transaction call object:

  • from: DATA, 20 bytes (optional) - The address the transaction is sent from.
  • to: DATA, 20 bytes - The address the transaction is sent to.
  • gas: QUANTITY (optional) - Integer of the maximum gas allowance for the transaction.
  • gasPrice: QUANTITY (optional) - Integer of the price of gas in wei.
  • value: QUANTITY (optional) - Integer of the value in wei.
  • data: DATA (optional) - Hash of the method signature and the ABI encoded parameters.
arguments
  • transaction: Transaction
  • passphrase: string: The passphrase to decrpyt the private key belonging to tx.from.
returns
Promise<DATA>

: The transaction hash or if unsuccessful an error.

example
const passphrase = "passphrase";
const newAccount = await provider.send("personal_newAccount", [passphrase] );
// fund the new account
await provider.send("evm_setAccountBalance", [newAccount,"0xffffffffffffff"])
const [to] = await provider.send("personal_listAccounts");

// use account and passphrase to send the transaction
const txHash = await provider.send("personal_sendTransaction", [{ from: newAccount, to, gasLimit: "0x5b8d80" }, passphrase] );
console.log(txHash);

personal_signTransaction(transaction: Transaction, passphrase: string): Promise<DATA>

Validates the given passphrase and signs a transaction that can be submitted to the network at a later time using eth_sendRawTransaction.

The transaction is the same argument as for eth_signTransaction and contains the from address. If the passphrase can be used to decrypt the private key belonging to tx.from the transaction is verified and signed. The account is not unlocked globally in the node and cannot be used in other RPC calls.

Transaction call object:

  • from: DATA, 20 bytes (optional) - The address the transaction is sent from.
  • to: DATA, 20 bytes - The address the transaction is sent to.
  • gas: QUANTITY (optional) - Integer of the maximum gas allowance for the transaction.
  • gasPrice: QUANTITY (optional) - Integer of the price of gas in wei.
  • value: QUANTITY (optional) - Integer of the value in wei.
  • data: DATA (optional) - Hash of the method signature and the ABI encoded parameters.
arguments
  • transaction: Transaction: The transaction call object as seen in source.
  • passphrase: string
returns
Promise<DATA>

: The raw, signed transaction.

example
const [to] = await provider.request({ method: "eth_accounts", params: [] });
const passphrase = "passphrase";
const from = await provider.send("personal_newAccount", [passphrase] );
await provider.request({ method: "eth_subscribe", params: ["newHeads"] });
const signedTx = await provider.request({ method: "personal_signTransaction", params: [{ from, to }, passphrase] });
console.log(signedTx)

personal_unlockAccount(address: string, passphrase: string, duration: number): Promise<boolean>

Unlocks the account for use.

The unencrypted key will be held in memory until the unlock duration expires. The unlock duration defaults to 300 seconds. An explicit duration of zero seconds unlocks the key until geth exits.

The account can be used with eth_sign and eth_sendTransaction while it is unlocked.

arguments
  • address: string: 20 Bytes - The address of the account to unlock.
  • passphrase: string: Passphrase to unlock the account.
  • duration: number: (default: 300) Duration in seconds how long the account should remain unlocked for. Set to 0 to disable automatic locking.
returns
Promise<boolean>

: true if it worked. Throws an error or returns false if it did not.

example
// generate an account
const passphrase = "passphrase";
const newAccount = await provider.send("personal_newAccount", [passphrase] );
const isUnlocked = await provider.send("personal_unlockAccount", [newAccount, passphrase] );
console.log(isUnlocked);

txpool namespace

txpool_content(): Promise<Content>

Returns the current content of the transaction pool.

returns
Promise<Content>

: The transactions currently pending or queued in the transaction pool.

example
const [from] = await provider.request({ method: "eth_accounts", params: [] });
await provider.send("miner_stop")
const pendingTx = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", nonce:"0x0" }] });
const queuedTx = await provider.request({ method: "eth_sendTransaction", params: [{ from, gas: "0x5b8d80", nonce:"0x2" }] });
const pool = await provider.send("txpool_content");
console.log(pool);

web3 namespace

web3_clientVersion(): Promise<string>

Returns the current client version.

returns
Promise<string>

: The current client version.

example
console.log(await provider.send("web3_clientVersion"));

web3_sha3(data: string): Promise<DATA>

Returns Keccak-256 (not the standardized SHA3-256) of the given data.

arguments
  • data: string: the data to convert into a SHA3 hash.
returns
Promise<DATA>

: The SHA3 result of the given string.

example
const data = "0xabcdef0123456789";
const sha3 = await provider.send("web3_sha3", [data] );
console.log(sha3);

db namespace

db_getHex(dbName: string, key: string): Promise<string>

Returns binary data from the local database.

arguments
  • dbName: string: Database name.
  • key: string: Key name.
returns
Promise<string>

: The previously stored data.

example
console.log(await provider.send("db_getHex", ["testDb", "testKey"] ));

db_getString(dbName: string, key: string): Promise<string>

Returns string from the local database.

arguments
  • dbName: string: Database name.
  • key: string: Key name.
returns
Promise<string>

: The previously stored string.

example
console.log(await provider.send("db_getString", ["testDb", "testKey"] ));

db_putHex(dbName: string, key: string, data: string): Promise<boolean>

Stores binary data in the local database.

arguments
  • dbName: string: Database name.
  • key: string: Key name.
  • data: string: Data to store.
returns
Promise<boolean>

: true if the value was stored, otherwise false.

example
console.log(await provider.send("db_putHex", ["testDb", "testKey", "0x0"] ));

db_putString(dbName: string, key: string, value: string): Promise<boolean>

Stores a string in the local database.

arguments
  • dbName: string: Database name.
  • key: string: Key name.
  • value: string: String to store.
returns
Promise<boolean>

: returns true if the value was stored, otherwise false.

example
console.log(await provider.send("db_putString", ["testDb", "testKey", "testValue"] ));

rpc namespace

rpc_modules(): Promise<{ eth: "1.0", evm: "1.0", net: "1.0", personal: "1.0", rpc: "1.0", web3: "1.0" }>

Returns object of RPC modules.

returns
Promise<{ eth: "1.0", evm: "1.0", net: "1.0", personal: "1.0", rpc: "1.0", web3: "1.0" }>

: RPC modules.

example
console.log(await provider.send("rpc_modules"));

net namespace

net_listening(): Promise<boolean>

Returns true if client is actively listening for network connections.

returns
Promise<boolean>

: true when listening, otherwise false.

example
console.log(await provider.send("net_listening"));

net_peerCount(): Promise<QUANTITY>

Returns number of peers currently connected to the client.

returns
Promise<QUANTITY>

: Number of connected peers.

example
console.log(await provider.send("net_peerCount"));

net_version(): Promise<string>

Returns the current network id.

returns
Promise<string>

: The current network id. This value should NOT be JSON-RPC Quantity/Data encoded.

example
console.log(await provider.send("net_version"));

bzz namespace

bzz_hive(): Promise<any[]>

Returns the kademlia table in a readable table format.

returns
Promise<any[]>

: Returns the kademlia table in a readable table format.

example
console.log(await provider.send("bzz_hive"));

bzz_info(): Promise<any[]>

Returns details about the swarm node.

returns
Promise<any[]>

: Returns details about the swarm node.

example
console.log(await provider.send("bzz_info"));

shh namespace

shh_addToGroup(address: string): Promise<boolean>

Adds a whisper identity to the group.

arguments
  • address: string: The identity address to add to a group.
returns
Promise<boolean>

: true if the identity was successfully added to the group, otherwise false.

example
console.log(await provider.send("shh_addToGroup", ["0x0"] ));

shh_getFilterChanges(id: string): Promise<[]>

Polling method for whisper filters. Returns new messages since the last call of this method.

arguments
  • id: string: The filter id. Ex: "0x7"
example
console.log(await provider.send("shh_getFilterChanges", ["0x0"] ));

shh_getMessages(id: string): Promise<boolean>

Get all messages matching a filter. Unlike shh_getFilterChanges this returns all messages.

arguments
  • id: string: The filter id. Ex: "0x7"
returns
Promise<boolean>

: See: shh_getFilterChanges.

example
console.log(await provider.send("shh_getMessages", ["0x0"] ));

shh_hasIdentity(address: string): Promise<boolean>

Checks if the client hold the private keys for a given identity.

arguments
  • address: string: The identity address to check.
returns
Promise<boolean>

: Returns true if the client holds the private key for that identity, otherwise false.

example
console.log(await provider.send("shh_hasIdentity", ["0x0"] ));

shh_newFilter(to: string, topics: string[]): Promise<boolean>

Creates filter to notify, when client receives whisper message matching the filter options.

arguments
  • to: string: (optional) Identity of the receiver. When present it will try to decrypt any incoming message if the client holds the private key to this identity.
  • topics: string[]: Array of topics which the incoming message's topics should match.
returns
Promise<boolean>

: Returns true if the identity was successfully added to the group, otherwise false.

example
console.log(await provider.send("shh_newFilter", ["0x0", []] ));

shh_newGroup(): Promise<string>

Creates a new group.

returns
Promise<string>

: The address of the new group.

shh_newIdentity(): Promise<string>

Creates new whisper identity in the client.

returns
Promise<string>

: - The address of the new identity.

example
console.log(await provider.send("shh_newIdentity"));

shh_post(postData: any): Promise<boolean>

Creates a whisper message and injects it into the network for distribution.

arguments
  • postData: any
returns
Promise<boolean>

: Returns true if the message was sent, otherwise false.

example
console.log(await provider.send("shh_post", [{}] ));

shh_uninstallFilter(id: string): Promise<boolean>

Uninstalls a filter with given id. Should always be called when watch is no longer needed. Additionally filters timeout when they aren't requested with shh_getFilterChanges for a period of time.

arguments
  • id: string: The filter id. Ex: "0x7"
returns
Promise<boolean>

: true if the filter was successfully uninstalled, otherwise false.

example
console.log(await provider.send("shh_uninstallFilter", ["0x0"] ));

shh_version(): Promise<string>

Returns the current whisper protocol version.

returns
Promise<string>

: The current whisper protocol version.

example
console.log(await provider.send("shh_version"));