Skip to content

Lightweight wrapper library on top of Ethereum JSON RPC

License

Notifications You must be signed in to change notification settings

romfrolov/eth-json-rpc

Repository files navigation

ETH RPC

npm version Coverage Status install size

Lightweight wrapper library on top of Ethereum JSON RPC.

Quick start

npm install eth-json-rpc
const ethRpc = require('eth-json-rpc')('https://mainnet.infura.io');

(async () => {

    // Get block number.
    const blockNumber = await ethRpc.eth.blockNumber();

    console.log(blockNumber); // 7280000

    // Call contract method.
    const totalSupply = await ethRpc.eth.call({methodSignature: 'totalSupply()', to: CONTRACT_ADDRESS});

    console.log(totalSupply); // 0x00000000000000000000000000000000000000000000d3c21bcecceda1000000

    // Send transaction to contract.
     const transactionHash = await ethRpc.eth.transaction({methodSignature: 'mint(uint256)', to: CONTRACT_ADDRESS, args: [100], privateKey: PRIVATE_KEY});

     console.log(transactionHash); // 0x36af4c76dd7f2a204b1a340fb6327ae8ff9e2efe2f974b054d3a36314635a10c

})();

Features

  • lightweight
  • support of batch RPC requests
  • minimum level of abstraction layers
  • ease of work with contracts

API

eth

  • call - Call contract method.
  • transaction - Create transaction object, sign transaction, serialize transaction, send transaction.
  • gasPrice - Get gas price.
  • getCode - Get code at address.
  • getTransactionReceipt - Get transaction receipt.
  • getTransactionCount - Get number of transactions the address sent.
  • blockNumber - Get number of the latest block.
  • getBlock - Get block by number.
  • getLogs - Get logs from blocks.
  • getBlocks - Get blocks with logs in a batch RPC request.
  • getBlocksFromArray - Get blocks with logs in a batch RPC request with optional consistency.

utils

  • isZeroAddress - Check whether address is zero or not.
  • isValidAddress - Validate address.
  • getMethodOutputParameters - Get method output parameter types from contract ABI.
  • decodeRawOutput - Decode raw data returned from the contract call.

For a complete documentation visit documentation section.

Documentation

npm run docs      # generate docs
npm run http-docs # start HTTP server serving docs

Tests

npm test

License

The eth-json-rpc library is licensed under the GNU GENERAL PUBLIC LICENSE, which can be found in this repository in the LICENSE file.

Acknowledgments

About

Lightweight wrapper library on top of Ethereum JSON RPC

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published