AION blockchain node is currently supported only on Ubuntu 16.04 or later.

So if you are a smart contract developer and using other OS like Mac OS , Windows or other Linux flavor, you have to either use web3 or Java RPC call for smart contract compilation.

Another option is, Titan Suite IDE (https://titan-suite.com/), which provides a browser based editor. This is a nodeJS application and you need to provide a web3 rpc endpoint pointing to a AION kernel.

But if you prefer to compile your smart contract from command line on a non supported platform and without connecting to AION kernel, there is a way to do that.

You can do that using docker image. I have created a lite weight docker image with Ubuntu 16.04 and aion fastvm (0.3.1) + solidity pre-installed on that.

Let me explain how to do that.

Pre-requisites :

> Install Docker engine

> Start the Docker daemon.

Steps: (One time process)

> Fetch required docker image for AION fastvm and solidity compiler from Docker Hub.

$> docker pull satran004/aion-fastvm:0.3.1

> Create an alias for the docker command which will be used to compile solidity source. So you don’t need to type a long command in future.

$> alias solc='docker run --rm -v "$(pwd):/src" satran004/aion-fastvm:0.3.1 solc'

Note: I have tested this on Mac and Linux. But windows testing is still pending, as I don’t have a Windows machine right now. But for windows, you may need to do a small change for “ ${pwd}” in the above command for windows environment. Replace that with windows equivalent or an absolute path of your working folder.

Now the fun part :)

> Go to the contract source folder and try to compile a contract source file as you do with the standard solc command.

$> solc --abi --bin -o <output_path> <solidity_file>

Example:

$> solc --abi --bin -o . Math.sol

Note: The source file can be present in a nested folder from your working directory. In that case, you need to pass the relative path of the source file. Also, the output directory should be a nested directory from your working directory.

Here is the source code for a sample solidity contract which can be used for testing. (Math.sol)

pragma solidity ^0.4.10;



contract Math {



function sum(uint n) returns (uint) {

uint s = 0;

for (uint i = 1; i <= n; i++) {

s += i;

}

return s;

}

}

If you try to compile the file without “-o” option, the compilation output will be directly printed in the console.

$> solc --abi --bin Math.sol Output : $> ======= Math.sol:Math =======

Binary:

605060405234156100105760006000fd5b610015565b60cb806100236000396000f30060506040526000356c01000000000000000000000000900463ffffffff16806357a7744b14603157602b565b60006000fd5b3415603c5760006000fd5b605060048080359060100190919050506066565b6040518082815260100191505060405180910390f35b60006000600060009150600190505b8381111515609157808201915081505b80806001019150506075565b8192506098565b50509190505600a165627a7a72305820c77f0903a9175d19c703e8dcc1c546a9db9bea00b647bb07ea4b867d298018f00029

Contract JSON ABI

[{"constant":false,"inputs":[{"name":"n","type":"uint128"}],"name":"sum","outputs":[{"name":"","type":"uint128"}],"payable":false,"type":"function"}]

So What’s next ?

The Java developers are mostly relying on IDE (Intellij, Eclipse etc.) and build tools like Maven, Gradle for development. These tools provide great developer experience and value for java development eco-system.

So why not use these proven tools and try to bridge the gap between java development and solidity contract development. So if you are developer from enterprise java background like me, you will feel at home with the familiar tools.

I have just started working on a Gradle plugin which can automate all of the above steps. Only per-requisite is docker installation.

So the idea here is to support a project structure similar to maven convention. And use Gradle as build tool for smart contract based project.

- project_folder

- src

- main

- solidity

- Math.sol

- Mycontract.sol

- test build.gradle

...

The gradle plugin will support tasks like compileSolidity similar to compileJava. Additional tasks like creating a distribution and pushing it to repository like nexus can also be achieved by using some existing plugins. This can be later extended to build through CI / CD tools like Jenkins.

We also need to explore if we can provide a test / sandbox environment (trimmed down version of blockchain or only a fastvm environment) which can be used to test the smart contract on a developer workstation in a predictable and fastest possible way. I am sure that’s also possible. So I will continue to find a way to support that in the plugin. Something like Ganache in Tuffle which is used by Ethereum ecosystems.

So keep watching this space for more update. The initial version of the Gradle plugin for smart contract compilation should be out very soon.

Resources:

AION-FastVM-Docker GITHUB : https://github.com/satran004/aion-fastvm-docker