How to create and deploy a smart contract using Aion?
Smart Contract Demo-DApp
This will take you through configuring your Aion blockchain, as well as deploying and interacting with a smart contract on Aion. It is meant for those who have some programming knowledge, but not necessarily blockchain.
Before we begin, make sure you have the following:
You will also need:
node.js version 8.9.1 download and install
npm version 5.5.1 (typically included with node.js installation.)
gulp version 3.9.1 download and install
Currently the compiler binary is built for 64-bit Ubuntu 16.04, other versions of Ubuntu may not be fully compatible
We’ll be walking you through a simple counter dApp built on Aion that you can interact with through the terminal. There are four main steps in this tutorial, being:
Setting up a Local Development Environment
Compiling the Smart Contract
Deploying the Smart Contract
Interacting with the Smart Contract
Reach out to us!
If you have any questions or encounter difficulties, feel free to connect with Aion on Gitter!
1. Setting up a Local Development Environment
For testing and DApp development purposes, you should configure the Aion kernel to be running the testnet.json file as the genesis file, and modify the config.xml to run internal mining for a local blockchain. For the steps on how to do this, refer to the Local Blockchain Network node set-up.
2. Compiling the Smart Contract
Before deploying the smart contract, we’re going to need to compile our solidity code into an interface (ABI) and bytecode (bin) to allow us to deploy the contract on the blockchain.
Bytecode: Compiled ‘code’
Configure your smart contract for compiling
Download or clone the aion_qa repository
Navigate into the DemoDApp directory and
npm install(This command installs all the packages we’ll need – you can find the dependencies in the package.json file)
Navigate to the DemoDApp/src directory and check that you have a contracts folder containing the Counter.sol file
Open deploy_counter.js file in the src folder and make the following changes:
line 10: edit directory path to where your aion/web3 is located (from home, or check the directory using the
line 28: edit a0 to the index number your address is in (listed under alloc when you open the new config/genesis.json file) Note: Lists are indexed starting at 0
line 29: edit pw0 = “password associated with account address”
5. Save the changes
3. Deploying the Smart Contract
To deploy the smart contract, you will need the contract ABI and bytecode as mentioned above, and an unlocked account with balance.
Running a script to deploy the smart contract
Navigate to the DemoDApp/src directory in terminal