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://faucet.sharpn.tech/ (select 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