Java Smart Contracts Hit The Testnet

Nick Nadeau
Aion
Published in
3 min readJan 9, 2019

Our Aion Virtual Machine (AVM) testnet is officially up and running. This is the network we’re using to further test a version of our Aion Java Kernel that has support for Java smart contracts.

Solidity and Java … together at last?

While the AVM Testnet does support both Solidity and Java smart contracts, the simple RPC script we’ve provided you with only allows for the deployment and calling of Java smart contracts. If you want to deploy a Solidity smart contract, you’ll have to use the regular web3.js means of doing so.

Also, note that Solidity contracts are not able to call into Java contracts and vice versa. Java smart contracts are also not able to call into precompiled contracts either (these will be added as high-level APIs, later).

Connecting to the network

To connect to the network, download the AVM Testnet release in the release tab of the AVM repository here. Once you have the release and have extracted its contents, you can connect to the network by running:

./aion.sh -n avmtestnet

Creating an account and getting funds

To create a new account run

./aion.sh -n avmtestnet -a create

If you need some Aion to fund your transactions, you can use the AVM Testnet faucet. Go to the Gitter link here and copy and paste your account address into the Gitter chat. In less than a minute you should have received the funds.

Deploying a Java smart contract

The AVM Testnet release binary comes pre-packaged with a basic Hello World contract, in the file named dapp.jar. This is the same contract we walked you through in a previous Medium article. Assuming you’ve followed the above steps, created an account (we will pretend our account is 0xa09b202a1b27c10a) and used the faucet to get some coins, you can deploy the contract by running:

./rpc.sh --deploy 0xa09b202a1b27c10a ./dapp.jar

Make sure you have a running instance of the kernel to deploy the contract.

Note that the above address is not valid, but it’s the one we’re going to use for our example.

You’ll receive a receipt hash once you send this transaction off (let’s say the receipt hash is: 0x0010276f1af924f1e45). You can use the hash to query the transaction results by running:

./rpc.sh --get-receipt 0x0010276f1af924f1e45

Calling a deployed Java smart contract

Let’s continue with our Hello World example above. Assuming you’ve successfully deployed the contract to the Testnet and you’ve got the address of the contract by querying the receipt hash, let’s proceed to invoke the “sayHello” method.

We’ll assume the address of the contract is: 0x0ff991a33c888f6b72.

To call the “sayHello” method simply run:

./rpc.sh --call 0xa09b202a1b27c10a 0x0ff991a33c888f6b72 sayHello

Again, just like with deploying a contract, you’ll receive a receipt hash that you can query in the same manner as outlined above.

Testnet caveats

The network is open to the public but its primary purpose is to provide ourselves with a means of testing our latest software and infrastructure. This network is not as polished as it will be in the future. There is also currently no dashboard support for the testnet, and the network will be restarted weekly as we are still in the process of making a number of consensus-breaking changes.

Final remarks

The Testnet will be substantially improved over the coming weeks. With this improvement to the software, we will also be improving the tools we provide you with to interact with the network.

For those of you interested in deploying more exotic contracts, with methods that take input arguments, you can see this user guide, which briefly walks you over the means of formatting your argument input. This same formatting is used by the rpc.sh script.

Have fun, and feel free to let us know how you fare. 👊

--

--