0.3.4 • Published 4 years ago

eth-json-rpc v0.3.4

Weekly downloads
8
License
GPL-3.0
Repository
github
Last release
4 years ago

ETH RPC

npm.io 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

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago