Xavier Arias
Sep 4 · 4 min read

After intense collaboration with the Aion network team, Web3 Labs is proud to announce the availability of the web3j Aion integration to support the Aion Virtual Machine (AVM). The AVM is a JVM-compliant blockchain execution environment that unlocks the entire Java ecosystem and enables you to write smart contracts in Java.

Developed under the Aion Bounties & Grants program, the web3j Aion project is now part of the web3j ecosystem of interoperable tools integrated with the blockchain infrastructure and is publicly available in Maven Central and jCenter repositories.

The web3j Aion project

It has been great working with a group of like-minded engineers. Like the Aion team, we are passionate technologists who strive to keep blockchain technology simple and share the common belief about the future of Java and the JVM for the blockchain.

When we started the web3j-aion project our intentions were clear. We wanted to make it easier for Java/JVM developers who work with Ethereum to use the Aion blockchain network in a way that complemented the Aion stack. Also, we wanted to help unblock developers building dApps, whilst promoting open-source.

The web3j-aion project adds to the existing Aion Java development stack: a Maven plugin and IntelliJ Idea plugin. By integrating with the familiar web3j API, the Aion network becomes accessible for developers who already use web3j to work with Ethereum. This brings similar capabilities of the JavaScript web3-aion and Ethers.js libraries to the Java ecosystem.

It also grows the number of web3j integrations available for a diverse array of blockchain clients and platforms, which already includes Parity, Geth and Pantheon, and Quorum.

Getting started

To get up and running quickly, we created the web3j Aion samples repository. It allows you to understand the entire lifecycle of your blockchain code and Aion smart contracts, from development to deployment. Running the following commands will enable you to get a Java Aion smart contract up and running in a few steps:

Clone the samples repository

git clone git@github.com:web3j/web3j-aion-samples.git
cd web3j-aion-samples

Compile the HelloWorld contract

To simplify the starting process, in the samples project we have included a test module. This contains a simple Java contract that you can modify and run so that you can get familiar with the web3j for Aion development environment:

public class HelloAvm {
private static String myStr = “Hello AVM”;
@Callable
public static void sayHello() {
Blockchain.println(“Hello Avm”);
}
@Callable
public static String greet(String name) {
return “Hello “ + name;
}
...
}

This contract, generated with the aion4j Maven archetype, demonstrates a very basic interaction with a contract by printing some logs, greeting with a given name and getting/setting a text stored as the contract state. To compile it, from the samples project run the commands:

cd hello-world-avm
./mvnw initialize
./mvnw install
cd ..

Generate the HelloWorld contract wrapper

Once the contract compilation is complete, the created artefacts will be in the target folder of the Maven project. Use them as the input for the contract wrapper generation task, which you can run with the command:

./gradlew generateContractWrappers

This task runs the web3j Aion command-line tools to generate the web3j contract wrapper. You can use this to deploy and interact with the smart contract:

// Create an Aion instance with a node URL
Aion aion = Aion.build(new HttpService("..."));
// Create a manager for local transaction signing with a private key
TransactionManager manager = new AionTransactionManager(
aion, new Ed25519KeyPair("..."), VirtualMachine.AVM
);
// Deploy the HelloAvm contract
HelloAvm contract = HelloAvm.deploy(
aion, manager, AionGasProvider.INSTANCE
).send();
// Call greet and receive "Hello John"
String result = contract.call_greet("John").send();

For more details on running an end-to-end test using this contract wrapper on an Aion network, check the project documentation and the web3j Aion tutorial. Check also the official Aion blog post on the project announcement.

What’s next?

We’re really excited with this support for Aion in web3j, and keen to hear from you, the community on how you’re finding it.

If you have any suggestions for the project, please create a new issue, or even better submit a pull request!. We will be happy to integrate improvements and new features to the library.

web3labs

The connector for enterprise technology and the blockchain

    Xavier Arias

    Written by

    web3labs

    web3labs

    The connector for enterprise technology and the blockchain

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade