Aion University

So you want to be a DApp developer?

Well you've come to the right place. You'll find comprehensive guides and documentation to help you start developing with Aion as quickly as possible, as well as support if you get stuck. Let's jump right in!

Let's DApp

πŸŽ“ Interact with Aion Web3 [Solidity Contract]

This guide is only compatible with Solidity smart contracts.

Guide Level: Beginner

You are a developer who

  • Is interested in learning blockchain
  • Is experienced and looking to build on Aion
  • A cool and curious cat who wants to deploy their first contract via Web3


Want to learn how to use Aion Web3 for all your blockchain and smart contract needs? You've come to the right place :raised-hands+: In this guide - we'll be going on a step by step journey on how to set up your environment, understand what it takes to deploy a smart contract, and how to interact with it.

You'll walk away knowing how to connect to Aion's Mastery Testnet, building and sending transactions, and the confidence to start building great things on the Aion Network.

1. Setup

Alright rockstars, we'll need a few things to set the stage before we can deploy that smart contract!


  • Node.js (recommended version: 10.x)
  • NPM (recommended version: 6.x)
  • A computer with an internet connection (Dial up works too)

1.1 Connect to the Aion Network

First we'll need to have access to an Aion Node. In this guide, we'll be using Nodesmith to connect to the Aion Network.

Nodesmith hosts Aion nodes so that you don't have to:

  • Host and manage the infrastructure of a full Aion node yourself

  • Wait over a day for the node to sync before you can begin interacting with the network

Let's get started:

  1. Sign Up and verify your e-mail
  2. Login to the developer portal with your account
  3. Once on Dashboard, create & nickname your new project. Bam! You've got your API Key. We'll be using this key to send requests to our Nodesmith endpoint.
  4. On "Select Network", and switch to the 'Testnet (Mastery)' option
Nodesmith Dashboard

Nodesmith Dashboard

Other ways to connect to the Aion Network

1.2 Aion Web3 Setup

Aion Web3 is an application programming interface that sits on top of the Aion Network. It allows you to interact with a local or remote Aion Node using an HTTP or IPC connection

We'll be using Web3 to

  • Create an Aion Account
  • Compile, Deploy, and Interact with our smart contract

Let's start by creating a directory, moving inside it, then installing Aion Web3 in there.

Run these commands in your terminal or command prompt:

# Create and move into our project folder
mkdir aion_smart_contract_demo
cd aion_smart_contract_demo

# Download & Install Aion Web3
npm install

Easy peazy! Now that web3 is installed, let's go ahead and open the web3 console and connect to the Aion network by typing the command below.

:loudspeaker+: You'll need your Nodesmith endpoint for this step

node console.js <https://nodesmith-endpoint-url-here>

You should see something like this.

Successfully opened the console and connected to our Nodesmith endpoint

Successfully opened the console and connected to our Nodesmith endpoint

1.3 Create/Import an Account

Great! Now we'll be using Web3 to generate our very own Aion address.

Keep your private key safe!

  • It acts as your digital signature
  • Helps confirm that you, the holder of the account, approve transactions on the network
  • The network is designed to approve any transactions were public & private keys match

Need a wallet interface?

Check out the easy to use in-browser wallet, AIWA. Once an account has been created, you can export the private key to deploy a contract using web3!

We need an Aion address so we can receive AION Coins - AION Coins - The native asset of the Aion blockchain. :money-with-wings+: in it. An account will allow you to sign transactions, deploy contracts and interact with DApps!

Now back to the Web3 console, run these commands to create an account.

// Create an account locally
let account = web3.eth.accounts.create(); 

// OR you can Import an account
let account = web3.eth.accounts.privateKeyToAccount('PasteYourPrivateKeyHere')

// Output details of our newly-created account


  • web3.eth.accounts.create() generates an account and the private key

  • account: will display the details of the newly-created account. The output will resemble the structure shown below. Take note of the "address" field (lines 7-8) – this is your public Aion address. The "privateKey" field contains your private key.

{ _privateKey:
   <Buffer 61 1c 22 c0 c4 af 62 f7 2d a9 fe 1c 89 ba 81 19 1e 17 ff 00 8a d7 7c 0b b2 6e 52 f0 0b 96 2f d6 f7 ab 59 b5 bc aa 7c a6 d2 af 5a 72 cc 6a 88 6b e7 47 ... >,
   <Buffer f7 ab 59 b5 bc aa 7c a6 d2 af 5a 72 cc 6a 88 6b e7 47 4a 42 6b fc 69 18 a1 33 fd 21 c4 1c db 1f>,
  signTransaction: [Function: signTransaction],
  sign: [Function: sign],
  encrypt: [Function: encrypt] }

1.4 Get AION in your Account

Alright let's get some AION in that account! :money-with-wings+:

We need AION to:

  • Deploy a contract
  • Interact with the contract
  • Send transactions
  1. Head over to the Faucet here
  2. Blockchain Network: Select Mastery
  3. Wallet: Paste your Aion Address
  4. Agree to Terms of Service and Privacy Policy
  5. Verify you're not a robot (so human beings, dogs, cats are cool)
  6. Press to pour! (Pretty self-explanatory)
  7. :fireworks+: 10 tokens wired to your given address, along with a transaction receipt that you can track search up on the Testnet Dashboard

Your account should now have 1 AION.

You can check the balance of your account by:

  • Aion Dashboard (Paste your account address into the search bar)
  • Through web3 with the following command


  • Alternatively, you can use web3.utils.fromNAmp to to convert NAmp to AION

2. Smart Contract

Let's get the show on the road!

Smart Contracts 101

We write smart contracts in a programming language called Solidity - Solidity - Solidity is a contract-oriented programming language for writing smart contracts. It is used for implementing smart contracts on various blockchain platforms . If you haven't heard of it before, that's okay! You can read up all about it here.

Below you'll find a simple smart contract which we've named as Counter.sol. It acts as a counter that can be either increased or decreased. Comments are written in-line so you can get a better understanding of what's going on.

Create the Smart Contract File

  • Navigate in the project folder we made earlier (the aion_smart_contract_demo directory)
  • Create a new file and name it 'Counter.sol'
  • Paste the following code in and save :floppy-disk+:
  sol Counter
  Simple Counter Contract - Increase / Decrease by 1

pragma solidity ^0.4.10;

contract Counter {

  /* State Variables */
  // State variables are values which are permanently stored in contract storage.
  int private count; // = 0
  address owner;

  /* Events */
  event CounterIncreased(bool counter);
  event CounterDecreased(bool counter);

  /* Functions */
  // Functions are the executable units of code within a contract.
  function Counter() public {
    owner = msg.sender;

  // Increase counter by 1
  function incrementCounter() public {
    count += 1;
  // Decrease counter by 1
  function decrementCounter() public {
    count -= 1;
  // Getter function that returns the current counter status
  function getCount() public constant returns (int) {
    return count;

2.1 Compile

Before we deploy the smart contract, we’re going to need to compile our solidity code into an interface (ABI) and bytecode (bin).

Compile Smart Contracts for

  • Application Binary Interface (ABI): JavaScript Object that defines how the machine is to interact with the contract

  • Bytecode: Compiled β€˜code’

Let's load the Solidity program into Web3 and compile our contract now :thumbsup+:
Enter each line into your Web3 console:

// Read the solidity program from file
let counterSol = fs.readFileSync("../Counter.sol", "utf8"); 

// Compile the contract
web3.eth.compileSolidity(counterSol).then((res) => compiled = res); 

// Display the compilation result


  • fs.readFileSync("./Counter.sol", "utf8"): Takes our Counter.sol contract, reads it then stores it in a variable we named counterSol

  • web3.eth.compileSolidity(counterSol): Lets web3 know that we want to compile this contract

  • compiled: Displays the output of the Solidity compiler (shown below). It contains the ABI Definition and VM bytecode, which we need to deploy to the network and interact with.

{ Counter:
   { code:
      { abiDefinition: [Array],
        languageVersion: '0',
        language: 'Solidity',
        compilerVersion: '0.4.15+commit.ecf81ee5.Linux.g++',
         '/*\n  sol Counter\n  Simple Counter Contract - Increase / Decrease by 1\n*/\n\npragma solidity ^0.4.10;\n\ncontract Counter {\n\n  /* State Variables */\n  // State variables are values which are permanently stored in contract storage.\n  int private count; // = 0\n  address owner;\n\n  /* Events */\n  event CounterIncreased(bool counter);\n  event CounterDecreased(bool counter);\n\n  /* Functions */\n  // Functions are the executable units of code within a contract.\n  function Counter() public {\n    owner = msg.sender;\n  }\n\n  // Increase counter by 1\n  function incrementCounter() public {\n    count += 1;\n    CounterIncreased(true);\n  }\n  \n  // Decrease counter by 1\n  function decrementCounter() public {\n    count -= 1;\n    CounterDecreased(true);\n  }\n  \n  // Getter function that returns the current counter status\n  function getCount() public constant returns (int) {\n    return count;\n  }\n}\n' 

2.2 Deploy

Awesome! Now that we've compiled our contract, it's time for deployment. By deploying a smart contract, we're sending a transaction to the network.

Your smart contract being deployed to Aion Network.

Your smart contract being deployed to Aion Network.

We'll be using Web3 to:

  • Build this transaction
  • Sign it on the client-side
  • Deploy the contract (by sending the signed transaction)

Building the Transaction

Before we even deploy the contract, we have to define the deployment transaction, and then sign it using our private key.

let contractInst = new eth.Contract(;

let deploy = contractInst.deploy( {data:compiled.Counter.code, arguments: []} ).encodeABI();

let deployTx = { gas: 4000000, gasPrice: 10000000000, data: deploy, from: account.address };

eth.accounts.signTransaction( deployTx, account.privateKey ).then( (res) => signedTx = res );



  • new eth.Contract(): Instantiates a new contract using the ABI definition we received from the compiler

  • contractInst.deploy().encodeABI(): Encodes the ABI of the contract's constructor; in this case, the constructor takes zero arguments, hence the arguments is a blank list

  • deployTx: Creates a transaction object with the encoded ABI

  • eth.accounts.signTransaction(): Signs the transaction using your account's private key

  • signedTx: Displays the signed transaction – the output's structure is shown in the snippet below.



Deploying the Contract

Up until now, we have not used any AION from our account since we haven't actually sent a transaction to the network. We only built the transaction in the last step.

Now let's send the transaction to the network.
Run this command into the Web3 console

web3.eth.sendSignedTransaction( signedTx.rawTransaction 
  ).on('receipt', receipt => { 
     console.log("Receipt received!\ntxHash =", receipt.transactionHash, 
                 "\ncontractAddress =", receipt.contractAddress);
  	 ctAddress = receipt.contractAddress;

Success! :tada+:
If everything goes as planned and contract deployment is a success , you should see the output below.

Receipt received! 
txHash = 0x83d4e490605437be85fed385a27889882f8f7bbd443a7b33b05a01d954e009cb 
contractAddress = 0xa0e5C73F2Aa1dbfD3bDc3cEb2D3BBEBCE467aeDf53D556e56A0eDe250f2B3d89

You can also see more details Aion Dashboard by pasting the transaction hash you received.

Confirmed Transaction Hash

Confirmed Transaction Hash

2.3 Interact

Now that we have our contract deployed on the network, we can interact with it. Like contract deployment, contract calls are transactions. The transaction object uses the same structure as before, but now we can populate the 'to:' field to point to the contract address (where our smart contract lives now).

Getter Function

In our Counter.sol contract, the getCount() function simply returns a constant. This means that it does not change or modify any values in the contract, but just outputs the value of a specific variable.

As long as you are only reading data from the blockchain and not changing the blockchain, you don't need to carry out a transaction. The function you call is carried out by the node and since nothing is mined, you do not need to pay any NRG.

So, since we're simply reading information from our contract, we can use without sending NRG - NRG - The internal pricing for running a transaction or contract on the Aion Network. Similary to how Gas is to Ethereum. or signing the transaction.

let txCall = {
	from: account.address, 
	to: ctAddress, 
	gas: 54321, 
        data: contractInst.methods.getCount().encodeABI()
}; => console.log(web3.utils.hexToNumber(res)));


  • txCall: Transaction object with getCount() method
  • web3.utils.hexToNumber(res): We take the return and convert it from hexadecimal to decimal format

As expected, it is zero - which is the initial value of the contract's count variable.


Function Calls

Let's try to use the incrementCounter() method, which modifies the state of the contract by increasing the counter by 1.

Since you are modifying the blockchain by sending instructions to the contract, this is a transaction. As with all transactions, it is necessary for the transaction to be signed and NRG to be required for execution.

Again, let's construct the transaction object and sign it - just like before.

// Create the transaction object
let txCallIncrement = {
    from: account.address, 
    to: ctAddress, 
    data: contractInst.methods.incrementCounter().encodeABI()

// Sign it
    txCallIncrement, account.privateKey
  ).then((res) => signedIncrementCall = res); 

// Output the signed transaction 


  • txCallIncrement: Transaction object with the incrementCounter() method
  • eth.accounts.signTransaction(): Signs the transaction using your account's private key
  • signedIncrementCall: Similarly to the code snippet for the contract deployment, the signed transaction has a rawTransaction

Waiting for Confirmation

Now, we're going to send the transaction and set up a handler as before, looking for the 'transactionHash' and 'receipt' event.

    ).on('transactionHash', txHash => { 
      console.log("txHash", txHash) }
      receipt => { console.log("receipt", receipt) }

This means that the transaction hash and the receipt will be displayed when they are available from our Aion node.

You will notice that the transaction hash appears before the receipt does. Why is that?

Things to know

Transaction hashes are created as soon as the node receives the transaction

The receipt is available only after the node has processed the transaction - which may take up to 10 - 20 seconds on the Mastery TestNet.

The output on your console should look something like this.

txHash 0x911c71347ee575c9b0b0f6e29bd8545b355a31fc4621ebf05cc0d114327da4bd

receipt { blockHash:
  nrgPrice: '0x02540be400',
  nrgUsed: '0x00aa7e',
  contractAddress: null,
  transactionIndex: 0,
  gasLimit: '0x00d431',
  cumulativeNrgUsed: '0xaa7e',
  gasUsed: 43646,
  blockNumber: 971622,
  cumulativeGasUsed: 43646,
   [ { address:
       logIndex: 0,
       data: '0x00000000000000000000000000000001',
       topics: [Array],
       blockNumber: 971622,
       transactionIndex: 0,
       id: null } ],
  gasPrice: '0x02540be400',
  status: true }

Alright, so everything looks good. :thumbsup+: We have our transaction hash and the receipt - so let's see if it actually updated!

Use to execute the getCount()method one more time.
We will use the same transaction object we created for it earlier (txCall). => console.log(web3.utils.hexToNumber(res)));


  • txCall: Transaction object with getCount()method
  • web3.utils.hexToNumber(res): We take the return and convert it from hexadecimal to decimal format

Since we called the incrementCounter() method once, it is expected that the counter increased by 1.


Well there you have it! You can continue to increment/decrement this counter to your hearts content and get a good feel of things. After that, you're ready to start deploying more complex contracts and create awesome DApps on the Aion Network - and we cannot wait to see it!

Need Help?

If you get stuck, try searching these docs πŸ‘† or head over to our Gitter channels or StackOverflow for answers to some common questions.

Written by KimCodeashian :fire+:

πŸŽ“ Interact with Aion Web3 [Solidity Contract]

This guide is only compatible with Solidity smart contracts.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.