JSON-RPC Web3

The JSON-RPC API was designed to be highly compatible with existing Ethereum client interfaces and allows for easy migration of existing DApps built on Ethereum to Aion.

Setup

The use of the JSON-RPC API is enabled from the kernel configuration file config.xml.
The active attribute must be set to "true" before starting the kernel to allow the API to interact with the Aion network through the local kernel.

<api>
  <rpc active="true" ip="127.0.0.1" port="8545">
    <!--boolean, enable/disable cross origin requests (browser enforced)-->
    <cors-enabled>false</cors-enabled>
    <!--comma-separated list, APIs available: web3,net,debug,personal,eth,stratum-->
    <apis-enabled>web3,eth,personal,stratum,net</apis-enabled>
    <!--size of thread pool allocated for rpc requests-->
    <threads>1</threads>
  </rpc>
  <!-- other API settings -->
</api>

Console

To interact with the kernel using a console first ensure that you have all the requirements installed.

Next use the web3 folder provided with your kernel release and execute the required installation steps from setup.
Finally, run the following in a terminal:

cd /path/to/aion/web3
node console.js

To exit the console run:

process.exit()

Use

For JavaScript applications, add the following lines to your code to interract with the API:

const Web3 = require('/path/to/aion/web3');
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

Note that if the kernel is running on a different machine or using a different port the string http://localhost:8545 must be replaced with the correct configuration.