ICON 2.0 Gangnam Network: Developer beginner guide šŸ› ļø

ICONation
4 min readFeb 2, 2021

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
It took about 44 seconds to finishā€¦ go grab a coffee ā˜•

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:

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!

My first contract on Gangnam, woohoo! šŸŽ‰

šŸ“ 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.

Try running ./bin/goloop and make sure it displays the same output

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

--

--