package
RSK API using Simple JSON RPC, a web3 replacement
npm install rskapiGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
RSK API, accesing a running node using JSON RPC. It's a simple replacement to the usual web3 interface.
This is a personal project, not related with or endorsed by RSK.
Via npm on Node:
npm install rskapiCreate the RSK API Object by calling the host function.
const rskapi = require('rskapi');
const client
Examples:
const client = rskapi.client('http://localhost:8545') // ie ganache-client
// or
const client = rskapi.client('http://localhost:4444') // local rsk regtest
// or
const client = rskapi.client('https://public-node.testnet.rsk.co:443') // rsk testnet public node
// or
const client = rskapi.client('https://public-node.rsk.co:443') // rsk mainnet public nodeGiven a client object, it can be invoked using a callback or as promise:
// get best block number
console.log(await client.number());
// or
client.number(function (err, number) {
if (err)
console.log('error', err);
else
console.log(number);
});In the following descriptions, a promise is used.
const number = await client.number();const accounts = await client.accounts();const balance = await client.balance(address);const nonce = await client.nonce(address);const tx = await client.transaction(hash);const tx = await client.receipt(hash, nseconds);where nseconds is the number of seconds to try (one request per second). If zero,
it waits forever.
const txhash = await client.transfer(sender, receiver, value, options);sender and receiver are accounts, represented by their public address, or
by an object with address and privateKey properties.
options is an object with properties like gas, gasPrice and nonce.
If no nonce is provided, the next nonce available for the sender will be use.
If no gas price is provided, the one informed by the host will be used.
const txhash = await client.deploy(sender, bytecodes, args, options);sender is an account (an address or an object with properties address and privateKey).
bytecodes is an hexadecimal string starting with 0x.
args is an array with the constructor arguments. It could be null.
options is an object with properties like gas, gasPrice, value and nonce.
If no nonce is provided, the next nonce available for the sender will be use.
If no gas price is provided, the one informed by the host will be used.
const txhash = await client.invoke(sender, receiver, fn, args, options);sender is an account (an address or an object with properties address and privateKey).
receiver is the address of a contract already deployed.
fn is an string with the full function signature to invoke, ie transfer(address,uint256).
args is an array with the function arguments.
options is an object with properties like gas, gasPrice, value and nonce.
If no nonce is provided, the next nonce available for the sender will be use.
If no gas price is provided, the one informed by the host will be used.
const txhash = await client.call(sender, receiver, fn, args, options);sender is an account (an address or an object with properties address and privateKey).
receiver is the address of a contract already deployed.
fn is an string with the full function signature to invoke, ie transfer(address,uint256).
args is an array with the function arguments.
options is an object with properties like value.
Being a call query and not a transaction, no gasPrice, gas or nonce is
needed.
Some simple samples at https://github.com/ajlopez/RskApi/tree/master/samples/simple.
Some simple commands using a configuration file at https://github.com/ajlopez/RskApi/tree/master/samples/commands.
client.block, get balance using block, get nonce using block, encode big integersFeel free to file issues and submit pull requests � contributions are welcome.
If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that npm test continues to pass.
Estimated unpacked size across 22 packages.
7.0 MB
Includes dependencies.
4 direct · 2 outdated
0.0.9
0.0.9
^1.3.7
2.1.2
0.0.7
0.0.7
6.1.0
7.1.5