Options
Public
  • Public
  • Public/Protected
  • All
Menu

Class EthereumApi

Hierarchy

  • EthereumApi

Implements

  • Api

Indexable

[index: string]: function
    • (...args: any): Promise<any>
    • Parameters

      • Rest ...args: any

      Returns Promise<any>

Index

Constructors

Properties

Methods

Constructors

constructor

  • new EthereumApi(options: EthereumInternalOptions, wallet: Wallet, blockchain: Blockchain): EthereumApi
  • This is the Ethereum API that the provider interacts with. The only methods permitted on the prototype are the supported json-rpc methods.

    Parameters

    • options: EthereumInternalOptions
    • wallet: Wallet
    • blockchain: Blockchain

    Returns EthereumApi

Properties

Readonly Private #blockchain

#blockchain: Blockchain

Readonly Private #filters

#filters: Map<string, object> = new Map<string, Filter>()

Readonly Private #getId

#getId: (Anonymous function) = (id => () => Quantity.from(++id))(0)

Readonly Private #options

#options: EthereumInternalOptions

Readonly Private #subscriptions

#subscriptions: Map<string, function> = new Map<string, Emittery.UnsubscribeFn>()

Readonly Private #wallet

#wallet: Wallet

Methods

bzz_hive

  • bzz_hive(): Promise<any[]>
  • Returns the kademlia table in a readable table format.

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

    Returns Promise<any[]>

    Returns the kademlia table in a readable table format.

bzz_info

  • bzz_info(): Promise<any[]>
  • Returns details about the swarm node.

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

    Returns Promise<any[]>

    Returns details about the swarm node.

db_getHex

  • db_getHex(dbName: string, key: string): Promise<string>
  • Returns binary data from the local database.

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

    Parameters

    • dbName: string

      Database name.

    • key: string

      Key name.

    Returns Promise<string>

    The previously stored data.

db_getString

  • db_getString(dbName: string, key: string): Promise<string>
  • Returns string from the local database.

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

    Parameters

    • dbName: string

      Database name.

    • key: string

      Key name.

    Returns Promise<string>

    The previously stored string.

db_putHex

  • db_putHex(dbName: string, key: string, data: DATA): Promise<boolean>
  • Stores binary data in the local database.

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

    Parameters

    • dbName: string

      Database name.

    • key: string

      Key name.

    • data: DATA

      Data to store.

    Returns Promise<boolean>

    true if the value was stored, otherwise false.

db_putString

  • db_putString(dbName: string, key: string, value: string): Promise<boolean>
  • Stores a string in the local database.

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

    Parameters

    • 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.

debug_storageRangeAt

  • debug_storageRangeAt(blockHash: DATA, transactionIndex: number, contractAddress: DATA, startKey: DATA, maxResult: number): Promise<StorageRangeResult>
  • 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.

    example
    // Simple.sol
    // // SPDX-License-Identifier: MIT
    //  pragma solidity ^0.7.4;
    //
    //  contract Simple {
    //      uint256 public value;
    //      constructor() payable {
    //          value = 5;
    //      }
    //  }
    const simpleSol = "0x6080604052600560008190555060858060196000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80633fa4f24514602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea26469706673582212200897f7766689bf7a145227297912838b19bcad29039258a293be78e3bf58e20264736f6c63430007040033";
    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 }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    
    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 }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    
    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);

    Parameters

    • blockHash: DATA

      Hash of a block.

    • transactionIndex: number

      Integer of the transaction index position.

    • contractAddress: DATA

      Address of the contract.

    • startKey: DATA

      Hash of the start key for grabbing storage entries.

    • maxResult: number

      Integer of maximum number of storage entries to return.

    Returns Promise<StorageRangeResult>

    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.

debug_traceTransaction

  • debug_traceTransaction(transactionHash: DATA, options?: TransactionTraceOptions): 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).
    example
    // Simple.sol
    // // SPDX-License-Identifier: MIT
    //  pragma solidity ^0.7.4;
    //
    //  contract Simple {
    //      uint256 public value;
    //      constructor() payable {
    //          value = 5;
    //      }
    //  }
    const simpleSol = "0x6080604052600560008190555060858060196000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80633fa4f24514602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea26469706673582212200897f7766689bf7a145227297912838b19bcad29039258a293be78e3bf58e20264736f6c63430007040033";
    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 }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    const transactionTrace = await provider.request({ method: "debug_traceTransaction", params: [txHash] });
    console.log(transactionTrace);

    Parameters

    • transactionHash: DATA

      Hash of the transaction to trace.

    • Optional options: TransactionTraceOptions

      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.

eth_accounts

  • eth_accounts(): Promise<string[]>
  • Returns a list of addresses owned by client.

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

    Returns Promise<string[]>

    Array of 20 Bytes - addresses owned by the client.

eth_blockNumber

  • eth_blockNumber(): Promise<Quantity>
  • Returns the number of the most recent block.

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

    Returns Promise<Quantity>

    The current block number the client is on.

eth_call

  • eth_call(transaction: any, blockNumber?: QUANTITY | Tag): 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.
    example
    // Simple.sol
    // // SPDX-License-Identifier: MIT
    //  pragma solidity ^0.7.4;
    //
    //  contract Simple {
    //      uint256 public value;
    //      constructor() payable {
    //          value = 5;
    //      }
    //  }
    const simpleSol = "0x6080604052600560008190555060858060196000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80633fa4f24514602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea26469706673582212200897f7766689bf7a145227297912838b19bcad29039258a293be78e3bf58e20264736f6c63430007040033";
    const [from] = await provider.request({ method: "eth_accounts", params: [] });
    const txObj = { from, gas: "0x5b8d80", gasPrice: "0x1dfd14000", value:"0x0", data: simpleSol };
    const result = await provider.request({ method: "eth_call", params: [txObj, "latest"] });
    console.log(result);

    Parameters

    • transaction: any

      The transaction call object as seen in source.

    • Default value blockNumber: QUANTITY | Tag = Tag.LATEST

      Integer block number, or the string "latest", "earliest" or "pending".

    Returns Promise<Data>

    The return value of executed contract.

eth_chainId

  • eth_chainId(): Promise<Quantity>

eth_coinbase

  • eth_coinbase(): Promise<Address>
  • Returns the client coinbase address.

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

    Returns Promise<Address>

    The current coinbase address.

eth_estimateGas

  • eth_estimateGas(transaction: any, blockNumber?: QUANTITY | Tag): 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.
    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);

    Parameters

    • transaction: any

      The transaction call object as seen in source.

    • Default value blockNumber: QUANTITY | Tag = Tag.LATEST

      Integer block number, or the string "latest", "earliest" or "pending".

    Returns Promise<Quantity>

    The amount of gas used.

eth_gasPrice

  • eth_gasPrice(): Promise<Quantity>
  • Returns the current price per gas in wei.

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

    Returns Promise<Quantity>

    Integer of the current gas price in wei.

eth_getBalance

  • eth_getBalance(address: DATA, blockNumber?: QUANTITY | Tag): Promise<Quantity>
  • Returns the balance of the account of given address.

    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);

    Parameters

    • address: DATA

      Address to check for balance.

    • Default value blockNumber: QUANTITY | Tag = Tag.LATEST

      Integer block number, or the string "latest", "earliest" or "pending".

    Returns Promise<Quantity>

    Integer of the account balance in wei.

eth_getBlockByHash

  • eth_getBlockByHash(hash: DATA, transactions?: boolean): Promise<any>
  • Returns information about a block by block hash.

    example
    // Simple.sol
    // // SPDX-License-Identifier: MIT
    //  pragma solidity ^0.7.4;
    //
    //  contract Simple {
    //      uint256 public value;
    //      constructor() payable {
    //          value = 5;
    //      }
    //  }
    const simpleSol = "0x6080604052600560008190555060858060196000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80633fa4f24514602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea26469706673582212200897f7766689bf7a145227297912838b19bcad29039258a293be78e3bf58e20264736f6c63430007040033";
    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 }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    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);

    Parameters

    • hash: DATA

      Hash of a block.

    • Default value transactions: boolean = false

      If true it returns the full transaction objects, if false only the hashes of the transactions.

    Returns Promise<any>

    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.

eth_getBlockByNumber

  • eth_getBlockByNumber(number: QUANTITY | Tag, transactions?: boolean): Promise<any>
  • Returns information about a block by block number.

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

    Parameters

    • number: QUANTITY | Tag

      Integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.

    • Default value transactions: boolean = false

      If true it returns the full transaction objects, if false only the hashes of the transactions.

    Returns Promise<any>

    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.

eth_getBlockTransactionCountByHash

  • eth_getBlockTransactionCountByHash(hash: DATA): Promise<Quantity>
  • Returns the number of transactions in a block from a block matching the given block hash.

    example
    // Simple.sol
    // // SPDX-License-Identifier: MIT
    //  pragma solidity ^0.7.4;
    //
    //  contract Simple {
    //      uint256 public value;
    //      constructor() payable {
    //          value = 5;
    //      }
    //  }
    const simpleSol = "0x6080604052600560008190555060858060196000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80633fa4f24514602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea26469706673582212200897f7766689bf7a145227297912838b19bcad29039258a293be78e3bf58e20264736f6c63430007040033";
    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 }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    const txReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });
    const txCount = await provider.request({ method: "eth_getBlockTransactionCountByHash", params: [txReceipt.blockHash] });
    console.log(txCount);

    Parameters

    • hash: DATA

      Hash of a block.

    Returns Promise<Quantity>

    Number of transactions in the block.

eth_getBlockTransactionCountByNumber

  • eth_getBlockTransactionCountByNumber(blockNumber: QUANTITY | Tag): Promise<Quantity>
  • Returns the number of transactions in a block from a block matching the given block number.

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

    Parameters

    • blockNumber: QUANTITY | Tag

    Returns Promise<Quantity>

    Integer of the number of transactions in the block.

eth_getCode

  • eth_getCode(address: DATA, blockNumber?: QUANTITY | Tag): Promise<Data>
  • Returns code at a given address.

    example
    // Simple.sol
    // // SPDX-License-Identifier: MIT
    //  pragma solidity ^0.7.4;
    //
    //  contract Simple {
    //      uint256 public value;
    //      constructor() payable {
    //          value = 5;
    //      }
    //  }
    const simpleSol = "0x6080604052600560008190555060858060196000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80633fa4f24514602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea26469706673582212200897f7766689bf7a145227297912838b19bcad29039258a293be78e3bf58e20264736f6c63430007040033";
    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 }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    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);

    Parameters

    • address: DATA

      Address.

    • Default value blockNumber: QUANTITY | Tag = Tag.LATEST

      Integer block number, or the string "latest", "earliest" or "pending".

    Returns Promise<Data>

    The code from the given address.

eth_getCompilers

  • eth_getCompilers(): Promise<string[]>
  • Returns a list of available compilers.

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

    Returns Promise<string[]>

    List of available compilers.

eth_getFilterChanges

  • eth_getFilterChanges(filterId: QUANTITY): 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.

    example
    // Logs.sol
    // // SPDX-License-Identifier: MIT
    // pragma solidity ^0.7.4;
    // contract Logs {
    //   event Event(uint256 indexed first, uint256 indexed second);
    //   constructor() {
    //     emit Event(1, 2);
    //   }
    //
    //   function logNTimes(uint8 n) public {
    //     for (uint8 i = 0; i < n; i++) {
    //       emit Event(i, i);
    //     }
    //   }
    // }
    
    const logsContract = "0x608060405234801561001057600080fd5b50600260017f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a360e58061004f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80635e19e69f14602d575b600080fd5b605960048036036020811015604157600080fd5b81019080803560ff169060200190929190505050605b565b005b60005b8160ff168160ff16101560ab578060ff168160ff167f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a38080600101915050605e565b505056fea26469706673582212201af9c13c7b00e2b628c1258d45f9f62d2aad8cd32fc32fd9515d8ad1e792679064736f6c63430007040033";
    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" }] );
    await provider.once("message");
    
    const changes = await provider.request({ method: "eth_getFilterChanges", params: [filterId] });
    console.log(changes);
    
    await provider.send("eth_unsubscribe", [subscriptionId]);

    Parameters

    • filterId: QUANTITY

      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.

eth_getFilterLogs

  • eth_getFilterLogs(filterId: QUANTITY): Promise<object[]>
  • Returns an array of all logs matching filter with given id.

    example
    // Logs.sol
    // // SPDX-License-Identifier: MIT
    // pragma solidity ^0.7.4;
    // contract Logs {
    //   event Event(uint256 indexed first, uint256 indexed second);
    //   constructor() {
    //     emit Event(1, 2);
    //   }
    //
    //   function logNTimes(uint8 n) public {
    //     for (uint8 i = 0; i < n; i++) {
    //       emit Event(i, i);
    //     }
    //   }
    // }
    
    const logsContract = "0x608060405234801561001057600080fd5b50600260017f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a360e58061004f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80635e19e69f14602d575b600080fd5b605960048036036020811015604157600080fd5b81019080803560ff169060200190929190505050605b565b005b60005b8160ff168160ff16101560ab578060ff168160ff167f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a38080600101915050605e565b505056fea26469706673582212201af9c13c7b00e2b628c1258d45f9f62d2aad8cd32fc32fd9515d8ad1e792679064736f6c63430007040033";
    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" }] );
    await provider.once("message");
    
    const logs = await provider.request({ method: "eth_getFilterLogs", params: [filterId] });
    console.log(logs);

    Parameters

    • filterId: QUANTITY

      The filter id.

    Returns Promise<object[]>

    Array of log objects, or an empty array.

eth_getLogs

  • eth_getLogs(filter: FilterArgs): Promise<object[]>
  • 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 topcis. 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.
    example
    // Logs.sol
    // // SPDX-License-Identifier: MIT
    // pragma solidity ^0.7.4;
    // contract Logs {
    //   event Event(uint256 indexed first, uint256 indexed second);
    //   constructor() {
    //     emit Event(1, 2);
    //   }
    //
    //   function logNTimes(uint8 n) public {
    //     for (uint8 i = 0; i < n; i++) {
    //       emit Event(i, i);
    //     }
    //   }
    // }
    
    const logsContract = "0x608060405234801561001057600080fd5b50600260017f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a360e58061004f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80635e19e69f14602d575b600080fd5b605960048036036020811015604157600080fd5b81019080803560ff169060200190929190505050605b565b005b60005b8160ff168160ff16101560ab578060ff168160ff167f34e802e5ebd1f132e05852c5064046c1b535831ec52f1c4997fc6fdc4d5345b360405160405180910390a38080600101915050605e565b505056fea26469706673582212201af9c13c7b00e2b628c1258d45f9f62d2aad8cd32fc32fd9515d8ad1e792679064736f6c63430007040033";
    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" }] );
    await provider.once("message");
    
    const { contractAddress } = await provider.send("eth_getTransactionReceipt", [txHash] );
    
    const logs = await provider.request({ method: "eth_getLogs", params: [{ address: contractAddress }] });
    console.log(logs);

    Parameters

    • filter: FilterArgs

      The filter options as seen in source.

    Returns Promise<object[]>

    Array of log objects, or an empty array.

eth_getStorageAt

  • eth_getStorageAt(address: DATA, position: QUANTITY, blockNumber?: QUANTITY | Tag): Promise<Data>
  • Returns the value from a storage position at a given address.

    example
    // Simple.sol
    // // SPDX-License-Identifier: MIT
    //  pragma solidity ^0.7.4;
    //
    //  contract Simple {
    //      uint256 public value;
    //      constructor() payable {
    //          value = 5;
    //      }
    //  }
    const simpleSol = "0x6080604052600560008190555060858060196000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80633fa4f24514602d575b600080fd5b60336049565b6040518082815260200191505060405180910390f35b6000548156fea26469706673582212200897f7766689bf7a145227297912838b19bcad29039258a293be78e3bf58e20264736f6c63430007040033";
    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 }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    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);

    Parameters

    • address: DATA

      Address of the storage.

    • position: QUANTITY

      Integer of the position in the storage.

    • Default value blockNumber: QUANTITY | Tag = Tag.LATEST

      Integer block number, or the string "latest", "earliest" or "pending".

    Returns Promise<Data>

    The value in storage at the requested position.

eth_getTransactionByBlockHashAndIndex

  • eth_getTransactionByBlockHashAndIndex(hash: DATA, index: QUANTITY): Promise<any>
  • Returns information about a transaction by block hash and transaction index position.

    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" }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    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);

    Parameters

    • hash: DATA

      Hash of a block.

    • index: QUANTITY

      Integer of the transaction index position.

    Returns Promise<any>

    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.

eth_getTransactionByBlockNumberAndIndex

  • eth_getTransactionByBlockNumberAndIndex(number: QUANTITY | Tag, index: QUANTITY): Promise<any>
  • Returns information about a transaction by block number and transaction index position.

    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" }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    const { transactionIndex } = await provider.request({ method: "eth_getTransactionReceipt", params: [txHash] });
    
    const tx = await provider.request({ method: "eth_getTransactionByBlockNumberAndIndex", params: [ "latest", transactionIndex ] });
    console.log(tx);

    Parameters

    • number: QUANTITY | Tag

      A block number, or the string "earliest", "latest" or "pending".

    • index: QUANTITY

      Integer of the transaction index position.

    Returns Promise<any>

    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.

eth_getTransactionByHash

  • eth_getTransactionByHash(transactionHash: DATA): Promise<object>
  • Returns the information about a transaction requested 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" }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    
    const tx = await provider.request({ method: "eth_getTransactionByHash", params: [ txHash ] });
    console.log(tx);

    Parameters

    • transactionHash: DATA

      Hash of a transaction.

    Returns Promise<object>

    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.

eth_getTransactionCount

  • eth_getTransactionCount(address: DATA, blockNumber?: QUANTITY | Tag): Promise<Quantity>
  • Returns the number of transactions sent from an 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" }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    
    const txCount = await provider.request({ method: "eth_getTransactionCount", params: [ from, "latest" ] });
    console.log(txCount);

    Parameters

    • address: DATA

      DATA, 20 Bytes - The address to get number of transactions sent from

    • Default value blockNumber: QUANTITY | Tag = Tag.LATEST

      Integer block number, or the string "latest", "earliest" or "pending".

    Returns Promise<Quantity>

    Number of transactions sent from this address.

eth_getTransactionReceipt

  • eth_getTransactionReceipt(transactionHash: DATA): Promise<object>
  • Returns the receipt of a transaction by transaction hash.

    Note: The receipt is not available for pending transactions.

    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" }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    
    const txReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [ txHash ] });
    console.log(txReceipt);

    Parameters

    • transactionHash: DATA

      Hash of a transaction.

    Returns Promise<object>

    Returns the receipt of a transaction by transaction hash.

eth_getUncleByBlockHashAndIndex

  • eth_getUncleByBlockHashAndIndex(hash: DATA, index: QUANTITY): Promise<any>
  • Returns information about a uncle of a block by hash and uncle index position.

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

    Parameters

    • hash: DATA

      Hash of a block.

    • index: QUANTITY

      The uncle's index position.

    Returns Promise<any>

    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.
    • transactions: Array - Array of transaction objects or 32 Bytes transaction hashes depending on the last parameter.
    • uncles: Array - Array of uncle hashes.

eth_getUncleByBlockNumberAndIndex

  • eth_getUncleByBlockNumberAndIndex(blockNumber: QUANTITY | Tag, uncleIndex: QUANTITY): Promise<any>
  • Returns information about a uncle of a block by hash and uncle index position.

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

    Parameters

    • blockNumber: QUANTITY | Tag

      A block number, or the string "earliest", "latest" or "pending".

    • uncleIndex: QUANTITY

      The uncle's index position.

    Returns Promise<any>

    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.
    • transactions: Array - Array of transaction objects or 32 Bytes transaction hashes depending on the last parameter.
    • uncles: Array - Array of uncle hashes.

eth_getUncleCountByBlockHash

  • eth_getUncleCountByBlockHash(hash: DATA): Promise<Quantity>
  • Returns the number of uncles in a block from a block matching the given block hash.

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

    Parameters

    • hash: DATA

      Hash of a block.

    Returns Promise<Quantity>

    The number of uncles in a block.

eth_getUncleCountByBlockNumber

  • eth_getUncleCountByBlockNumber(number: QUANTITY | Tag): Promise<Quantity>
  • Returns the number of uncles in a block from a block matching the given block hash.

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

    Parameters

    • number: QUANTITY | Tag

    Returns Promise<Quantity>

    The number of uncles in a block.

eth_getWork

  • eth_getWork(filterId: QUANTITY): 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.

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

    Parameters

    • filterId: QUANTITY

      A filter id.

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

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

eth_hashrate

  • eth_hashrate(): Promise<Quantity>
  • Returns the number of hashes per second that the node is mining with.

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

    Returns Promise<Quantity>

    Number of hashes per second.

eth_mining

  • eth_mining(): Promise<boolean>
  • Returns true if client is actively mining new blocks.

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

    Returns Promise<boolean>

    returns true if the client is mining, otherwise false.

eth_newBlockFilter

  • 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.

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

    Returns Promise<Quantity>

    A filter id.

eth_newFilter

  • 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 topcis. Topics are order-dependent. Each topic can also be an array of DATA with "or" options.
    example
    const filterId = await provider.request({ method: "eth_newFilter", params: [] });
    console.log(filterId);

    Parameters

    • Default value filter: RangeFilterArgs = {}

      The filter options as seen in source.

    Returns Promise<Quantity>

    A filter id.

eth_newPendingTransactionFilter

  • 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.

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

    Returns Promise<Quantity>

    A filter id.

eth_protocolVersion

  • eth_protocolVersion(): Promise<Data>
  • Returns the current ethereum protocol version.

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

    Returns Promise<Data>

    The current ethereum protocol version.

eth_sendRawTransaction

  • eth_sendRawTransaction(transaction: string): Promise<Data>
  • Creates new message call transaction or a contract creation for signed transactions.

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

    Parameters

    • transaction: string

      The signed transaction data.

    Returns Promise<Data>

    The transaction hash.

eth_sendTransaction

  • eth_sendTransaction(transaction: RpcTransaction): 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.
    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" }] });
    await provider.once("message"); // Note: `await provider.once` is non-standard
    console.log(txHash);

    Parameters

    • transaction: RpcTransaction

      The transaction call object as seen in source.

    Returns Promise<Data>

    The transaction hash.

eth_sign

  • eth_sign(address: DATA, message: DATA): 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.

    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);

    Parameters

    • address: DATA

      Address to sign with.

    • message: DATA

      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.

eth_signTransaction

  • eth_signTransaction(transaction: RpcTransaction): Promise<string>
  • 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.
    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)

    Parameters

    • transaction: RpcTransaction

      The transaction call object as seen in source.

    Returns Promise<string>

    The raw, signed transaction.

eth_signTypedData

  • eth_signTypedData(address: DATA, typedData: TypedData): Promise<string>
  • 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.
    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)
    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);
    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);

    Parameters

    • address: DATA

      Address of the account that will sign the messages.

    • typedData: TypedData

      Typed structured data to be signed.

    Returns Promise<string>

    The raw, signed transaction.

eth_signTypedData

  • eth_submitHashrate(hashRate: DATA, clientID: DATA): Promise<boolean>
  • Used for submitting mining hashrate.

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

    Parameters

    • hashRate: DATA

      A hexadecimal string representation (32 bytes) of the hash rate.

    • clientID: DATA

      A random hexadecimal(32 bytes) ID identifying the client.

    Returns Promise<boolean>

    true if submitting went through succesfully and false otherwise.

eth_submitWork

  • eth_submitWork(nonce: DATA, powHash: DATA, digest: DATA): Promise<boolean>
  • Used for submitting a proof-of-work solution.

    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);

    Parameters

    • nonce: DATA

      The nonce found (64 bits).

    • powHash: DATA

      The header's pow-hash (256 bits).

    • digest: DATA

      The mix digest (256 bits).

    Returns Promise<boolean>

    true if the provided solution is valid, otherwise false.

eth_subscribe

  • eth_subscribe(subscriptionName: SubscriptionName): PromiEvent<Quantity>
  • eth_subscribe(subscriptionName: "logs", options: BaseFilterArgs): 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.

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

    Parameters

    • subscriptionName: SubscriptionName

      Name for the subscription.

    Returns PromiEvent<Quantity>

    A subscription id.

  • 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.

    Parameters

    • subscriptionName: "logs"
    • options: BaseFilterArgs

      Filter options:

      • address: either an address or an array of addresses. Only logs that are created from these addresses are returned
      • topics, only logs which match the specified topics

    Returns PromiEvent<Quantity>

    A subscription id.

eth_syncing

  • eth_syncing(): Promise<boolean>
  • Returns an object containing data about the sync status or false when not syncing.

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

    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.

eth_uninstallFilter

  • eth_uninstallFilter(filterId: QUANTITY): Promise<boolean>
  • Uninstalls a filter with given id. Should always be called when watch is no longer needed.

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

    Parameters

    • filterId: QUANTITY

      The filter id.

    Returns Promise<boolean>

    true if the filter was successfully uninstalled, otherwise false.

eth_unsubscribe

  • eth_unsubscribe(subscriptionId: SubscriptionId): Promise<boolean>
  • Cancel a subscription to a particular event. Returns a boolean indicating if the subscription was successfully cancelled.

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

    Parameters

    • subscriptionId: SubscriptionId

      The ID of the subscription to unsubscribe to.

    Returns Promise<boolean>

    true if subscription was cancelled successfully, otherwise false.

evm_increaseTime

  • evm_increaseTime(seconds: QUANTITY): Promise<number>
  • Jump forward in time by the given amount of time, in seconds.

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

    Parameters

    • seconds: QUANTITY

      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.

evm_lockUnknownAccount

  • evm_lockUnknownAccount(address: DATA): Promise<boolean>
  • Locks any unknown account.

    Note: accounts known to the personal namespace and accounts returned by eth_accounts cannot be locked using this method.

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

    Parameters

    • address: DATA

      The address of the account to lock.

    Returns Promise<boolean>

    true if the account was locked successfully, false if the account was already locked. Throws an error if the account could not be locked.

evm_mine

  • evm_mine(timestamp?: number): Promise<"0x0">
  • evm_mine(options?: object): 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.

    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"));

    Parameters

    • Optional timestamp: number

      The timestamp the block should be mined with. EXPERIEMENTAL: Optionally, specify an options object with timestamp and/or blocks fields. If blocks is given, it will mine exactly blocks number of blocks, regardless of any other blocks mined or reverted during it's operation. This behavior is subject to change!

    Returns Promise<"0x0">

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

  • Parameters

    • Optional options: object
      • Optional blocks?: number
      • Optional timestamp?: number

    Returns Promise<"0x0">

evm_revert

  • evm_revert(snapshotId: QUANTITY): 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 (Ex: reverting to id 0x1 will delete snapshots with ids 0x1, 0x2, etc... If no snapshot id is passed it will revert to the latest snapshot.

    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"}] );
    await provider.once("message"); // Note: `await provider.once` is non-standard
    
    // 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});

    Parameters

    • snapshotId: QUANTITY

      The snapshot id to revert.

    Returns Promise<boolean>

    true if a snapshot was reverted, otherwise false.

evm_setAccountNonce

  • evm_setAccountNonce(address: DATA, nonce: QUANTITY): 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.

    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);

    Parameters

    • address: DATA

      The account address to update.

    • nonce: QUANTITY

      The nonce value to be set.

    Returns Promise<boolean>

    true if it worked, otherwise false.

evm_setTime

  • evm_setTime(time: QUANTITY | 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 is will result in an invalid state.

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

    Parameters

    • time: QUANTITY | Date

      JavaScript timestamp (millisecond precision).

    Returns Promise<number>

    The amount of seconds between the given timestamp and now.

evm_snapshot

  • 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.

    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"}] );
    await provider.once("message"); // Note: `await provider.once` is non-standard
    
    // 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});

    Returns Promise<Quantity>

    The hex-encoded identifier for this snapshot.

evm_unlockUnknownAccount

  • evm_unlockUnknownAccount(address: DATA, duration?: number): Promise<boolean>
  • Unlocks any unknown account.

    Note: accounts known to the personal namespace and accounts returned by eth_accounts cannot be unlocked using this method.

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

    Parameters

    • address: DATA

      The address of the account to unlock.

    • Default value duration: number = 0

      (Default: disabled) Duration in seconds how long the account should remain unlocked for. Set to 0 to disable automatic locking.

    Returns Promise<boolean>

    true if the account was unlocked successfully, false if the account was already unlocked. Throws an error if the account could not be unlocked.

miner_setEtherbase

  • miner_setEtherbase(address: DATA): Promise<boolean>
  • Sets the etherbase, where mining rewards will go.

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

    Parameters

    • address: DATA

      The address where the mining rewards will go.

    Returns Promise<boolean>

    true.

miner_setExtra

  • miner_setExtra(extra: DATA): Promise<boolean>
  • Set the extraData block header field a miner can include.

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

    Parameters

    • extra: DATA

      The extraData to include.

    Returns Promise<boolean>

    If successfully set returns true, otherwise returns an error.

miner_setGasPrice

  • miner_setGasPrice(number: QUANTITY): Promise<boolean>
  • Sets the minimal accepted gas price when mining transactions. Any transactions that are below this limit are excluded from the mining process.

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

    Parameters

    • number: QUANTITY

      Minimal accepted gas price.

    Returns Promise<boolean>

    true.

miner_start

  • miner_start(threads?: number): Promise<boolean>
  • Resume the CPU mining process with the given number of threads.

    Note: threads is ignored.

    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"));

    Parameters

    • Default value threads: number = 1

      Number of threads to resume the CPU mining process with.

    Returns Promise<boolean>

    true.

miner_stop

  • miner_stop(): Promise<boolean>
  • Stop the CPU mining operation.

    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"));

    Returns Promise<boolean>

    true.

net_listening

  • net_listening(): Promise<boolean>
  • Returns true if client is actively listening for network connections.

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

    Returns Promise<boolean>

    true when listening, otherwise false.

net_peerCount

  • net_peerCount(): Promise<Quantity>
  • Returns number of peers currently connected to the client.

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

    Returns Promise<Quantity>

    Number of connected peers.

net_version

  • net_version(): Promise<string>
  • Returns the current network id.

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

    Returns Promise<string>

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

personal_importRawKey

  • personal_importRawKey(rawKey: DATA, passphrase: string): Promise<Address>
  • Imports the given unencrypted private key (hex string) into the key store, encrypting it with the passphrase.

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

    Parameters

    • rawKey: DATA

      The raw, unencrypted private key to import.

    • passphrase: string

      The passphrase to encrypt with.

    Returns Promise<Address>

    Returns the address of the new account.

personal_listAccounts

  • personal_listAccounts(): Promise<string[]>
  • Returns all the Ethereum account addresses of all keys that have been added.

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

    Returns Promise<string[]>

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

personal_lockAccount

  • personal_lockAccount(address: DATA): Promise<boolean>
  • Locks the account. The account can no longer be used to send transactions.

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

    Parameters

    • address: DATA

      The account address to be locked.

    Returns Promise<boolean>

    Returns true if the account was locked, otherwise false.

personal_newAccount

  • personal_newAccount(passphrase: string): Promise<Address>
  • Generates a new account with private key. Returns the address of the new account.

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

    Parameters

    • passphrase: string

      The passphrase to encrypt the private key with.

    Returns Promise<Address>

    The new account's address.

personal_sendTransaction

  • personal_sendTransaction(transaction: any, 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.
    example
    const passphrase = "passphrase";
    const newAccount = await provider.send("personal_newAccount", [passphrase] );
    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);

    Parameters

    • transaction: any
    • passphrase: string

      The passphrase to decrpyt the private key belonging to tx.from.

    Returns Promise<Data>

    The transaction hash or if unsuccessful an error.

personal_signTransaction

  • personal_signTransaction(transaction: RpcTransaction, passphrase: string): Promise<string>
  • 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 belogging 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.
    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)

    Parameters

    • transaction: RpcTransaction

      The transaction call object as seen in source.

    • passphrase: string

    Returns Promise<string>

    The raw, signed transaction.

personal_unlockAccount

  • personal_unlockAccount(address: DATA, 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.

    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);

    Parameters

    • address: DATA

      The address of the account to unlock.

    • passphrase: string

      Passphrase to unlock the account.

    • Default value duration: number = 300

      (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.

rpc_modules

  • rpc_modules(): Promise<object>

shh_addToGroup

  • shh_addToGroup(address: DATA): Promise<boolean>
  • Adds a whisper identity to the group.

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

    Parameters

    • address: DATA

      The identity address to add to a group.

    Returns Promise<boolean>

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

shh_getFilterChanges

  • shh_getFilterChanges(id: QUANTITY): Promise<any[]>

shh_getMessages

  • shh_getMessages(id: QUANTITY): Promise<boolean>
  • Get all messages matching a filter. Unlike shh_getFilterChanges this returns all messages.

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

    Parameters

    • id: QUANTITY

      The filter id. Ex: "0x7"

    Returns Promise<boolean>

    See: shh_getFilterChanges.

shh_hasIdentity

  • shh_hasIdentity(address: DATA): Promise<boolean>
  • Checks if the client hold the private keys for a given identity.

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

    Parameters

    • address: DATA

      The identity address to check.

    Returns Promise<boolean>

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

shh_newFilter

  • shh_newFilter(to: DATA, topics: DATA[]): Promise<boolean>
  • Creates filter to notify, when client receives whisper message matching the filter options.

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

    Parameters

    • to: DATA

      (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: DATA[]

      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.

shh_newGroup

  • shh_newGroup(): Promise<string>

shh_newIdentity

  • shh_newIdentity(): Promise<string>
  • Creates new whisper identity in the client.

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

    Returns Promise<string>

    The address of the new identity.

shh_post

  • shh_post(postData: WhisperPostObject): Promise<boolean>
  • Creates a whisper message and injects it into the network for distribution.

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

    Parameters

    • postData: WhisperPostObject

    Returns Promise<boolean>

    Returns true if the message was sent, otherwise false.

shh_uninstallFilter

  • shh_uninstallFilter(id: QUANTITY): 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.

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

    Parameters

    • id: QUANTITY

      The filter id. Ex: "0x7"

    Returns Promise<boolean>

    true if the filter was successfully uninstalled, otherwise false.

shh_version

  • shh_version(): Promise<string>
  • Returns the current whisper protocol version.

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

    Returns Promise<string>

    The current whisper protocol version.

web3_clientVersion

  • web3_clientVersion(): Promise<string>
  • Returns the current client version.

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

    Returns Promise<string>

    The current client version.

web3_sha3

  • web3_sha3(data: DATA): Promise<Data>
  • Returns Keccak-256 (not the standardized SHA3-256) of the given data.

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

    Parameters

    • data: DATA

      The data to convert into a SHA3 hash.

    Returns Promise<Data>

    The SHA3 result of the given string.

Generated using TypeDoc