ICON 2.0 new blockchain engine will be able to support SCORE coded in Java. The main advantage of coding SCORE in Java is that the deployed contract doesnāt need to go through the Audit process before being deployed : theyāre instantly active and running right away.
Hereās a small write up from a discussion which took place in the ICONDevs Telegram channel few hours ago. We tried to deploy our first contract on the Gangnam Network, the current testnet that supports the current ICON 2.0 implementation.
š§ Letās begin : SCORE Deployment on Gangnam
Iāll do these step on a Linux environment ā more exactly on my WSL installation on Windows 10. These steps are also compatible with Mac. So whatever OS you are using, you should be able to follow these instructions.
The first things we need to learn are :
- How to deploy a contract on Gangnam Network
- How to call that contract using the goloop CLI tool
First, we need to install the JDK 11, as the build and deployment tools are coded in Java.
$ sudo apt install openjdk-11-jdk
For this tutorial, weāre going to use SCORE examples provided by ICON, we will learn to code our own contract in Java at a later stage :
$ git clone https://github.com/icon-project/java-score-examples.git
$ cd java-score-examples
Weāre going to build all these contracts in this directory, but we will only use one : the simple āhello-worldā contract.
In order to build these contracts, weāre going to run this command:
$ ./gradlew build
Once the contracts are built, we need to optimize them before deploy them. Once again, we only need to call a single command:
$ ./gradlew optimizedJar
Now we have an optimized contract ready to be deployedā¦ but we need ICX in order to cover the deployment fee costs. Fortunately, iBriz, Stakin and ReliantNode provide faucets for sending ICX on Gangnam network to any wallet automatically:
- https://gicon.ibriz.ai/
- https://faucet.sharpn.tech/ (select Gangnam)
- https://faucet.reliantnode.com/gangnam
Iād recommand to create a new wallet for that purpose ā you can create one online quickly on myiconwallet.com if you donāt have ICONex installed. I saved my wallet in a file called āgangnam.jsonā
Once you sent Gangnam ICX to your wallet, check your balance on the Gangnam tracker. My address is hx8262ca13a43b61919d7c3725df98d0e808be74d3, so I can check its balance here : https://gicon.tracker.solidwallet.io/address/hx8262ca13a43b61919d7c3725df98d0e808be74d3
So I have 2300 ICX, plenty enough to deploy my contract.
Now letās try to deploy the āhello-worldā contract from the java-score-examples repo using my wallet:
$ ./gradlew hello-world:deployToGangnam -PkeystoreName=../gangnam.json -PkeystorePass=<wallet password>
Please notice the deployToGangnam task that indicates that weāre going to send our contract to the Gangnam network.
The contract is deployed and active āgreat!
š Reading the contract with the goloop CLI
Now that weāve deployed our contract, we would like to call the getGreeting method from the hello-world contract.
For that, weāll need to install goloop, the new blockchain engine powering ICON 2.0.
When writing this article (Feb 2021), the goloop engine is still alpha software, so a lot of changes may have happened if you read this article later. Iāll provide some instructions in order to build goloop 0.9.5, please donāt follow these instructions on a more recent version of this software if youāre reading this article months later, refer to the official instructions instead.
First, download goloop 0.9.5 from Github and cd to that folder :
$ wget https://github.com/icon-project/goloop/archive/v0.9.5.zip$ unzip v0.9.5.zip && cd goloop-0.9.5
Simply run the make and make pyexec commands:
$ make && make pyexec
And thatās it! You now should have a goloop binary in the ābinā folder of your goloop folder.
Once we have built this binary, we are now able to call any method from our contract with a single command.
Hereās how to call the āgetGreetingā method from our SCORE using its contract address (cxb8f73563ea4122a619c3d4e3e5344c35c5b981f0) :
$ ./bin/goloop rpc call --to cxb8f73563ea4122a619c3d4e3e5344c35c5b981f0 --method getGreeting --uri https://gicon.net.solidwallet.io/api/v3
If everything went right, it should output āHello Aliceā, as expected from the hello-world contract. š
If you want to do more complex method calls, refer to the goloop rpc call documentation.
Thatās all for this writeup, next step is coding your own Java SCORE in another article!
If you want to run your own goloop node on localhost for debugging purposes, you can follow this guide: https://iconation.medium.com/running-goloop-0-9-5-javaee-natively-without-docker-5b96fe051ba3