Search…
Deploying smart contracts

How to deploy a smart contract

Using goloop CLI command
Now you can deploy the optimized jar to ICON networks that support the Java smart contract execution environment. Assuming you are running a local network that is listening on port 9082 for incoming requests, you can create a deploy transaction with the optimized jar and deploy it to the local network as follows.
1
$ goloop rpc sendtx deploy ./hello-world/build/libs/hello-world-0.1.0-optimized.jar \
2
--uri http://localhost:9082/api/v3 \
3
--key_store <your_wallet_json> --key_password <password> \
4
--nid 3 --step_limit=1000000 \
5
--content_type application/java \
6
--param name=Alice
Copied!
[Note] The content type should be application/java instead of application/zip to differentiate it with the Python smart contract deployment.
Using deployJar extension
Starting with version 0.7.2 of gradle-javaee-plugin, you can also use the deployJar extension to specify all the information required for deployment.
1
deployJar {
2
endpoints {
3
local {
4
uri = 'http://localhost:9082/api/v3'
5
nid = 3
6
}
7
}
8
keystore = rootProject.hasProperty('keystoreName') ? "$keystoreName" : ''
9
password = rootProject.hasProperty('keystorePass') ? "$keystorePass" : ''
10
parameters {
11
arg('name', 'Alice')
12
}
13
}
Copied!
Now you can run deployToLocal task as follows.
1
$ ./gradlew hello-world:deployToLocal -PkeystoreName=<your_wallet_json> -PkeystorePass=<password>
2
3
> Task :hello-world:deployToLocal
4
>>> deploy to http://localhost:9082/api/v3
5
>>> optimizedJar = ./hello-world/build/libs/hello-world-0.1.0-optimized.jar
6
>>> keystore = <your_wallet_json>
7
Succeeded to deploy: 0x699534c9f5277539e1b572420819141c7cf3e52a6904a34b2a2cdb05b95ab0a3
8
SCORE address: cxd6d044b01db068cded47bde12ed4f15a6da9f1d8
Copied!
[Note] If you want to deploy to Lisbon testnet, use the following configuration for the endpoint and run deployToLisbon task.
1
deployJar {
2
endpoints {
3
lisbon {
4
uri = 'https://lisbon.net.solidwallet.io/api/v3'
5
nid = 0x2
6
}
7
...
8
}
9
}
Copied!

4. Verify the execution

Check the deployed smart contract address first using the txresult command.
1
$ goloop rpc txresult <tx_hash> --uri http://localhost:9082/api/v3
2
{
3
...
4
"scoreAddress": "cxaa736426a9caed44c59520e94da2d64888d9241b",
5
...
6
}
Copied!
Then you can invoke getGreeting method via the following call command.
1
$ goloop rpc call --to <score_address> --method getGreeting --uri http://localhost:9082/api/v3
2
"Hello Alice!"
Copied!