Lightweight wrapper library on top of Ethereum JSON RPC.
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('totalSupply()', CONTRACT_ADDRESS);
console.log(totalSupply); // 0x00000000000000000000000000000000000000000000d3c21bcecceda1000000
// Send transaction to contract.
const transactionHash = await ethRpc.eth.transaction('mint(uint256)', CONTRACT_ADDRESS, [100], PRIVATE_KEY);
console.log(transactionHash); // 0x36af4c76dd7f2a204b1a340fb6327ae8ff9e2efe2f974b054d3a36314635a10c
})();
- lightweight
- support of batch RPC requests
- minimum level of abstraction layers
- ease of work with contracts
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.
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.
npm run docs # generate docs
npm run http-docs # start HTTP server serving docs
npm test
The eth-json-rpc library is licensed under the GNU GENERAL PUBLIC LICENSE, which can be found in this repository in the LICENSE
file.
- This library was written with support of Wings Project