Search…
Java SDK
The source code is found on GitHub at https://github.com/icon-project/icon-sdk-java
This document describes how to interact with ICON Network using Java SDK. This document contains SDK installation, API usage guide, and code examples.
Get different types of examples as follows.
Code Example
Description
Wallet
An example of creating and loading a keywallet.
An example of transferring ICX and confirming the result.
An example of deploying an IRC token, transferring the token and confirming the result.
An example of checking block confirmation and printing the ICX and token transfer information.
This document is focused on how to use the SDK properly. For the detailed API specification, see the API reference documentation.

Prerequisite

This Java SDK works on the following platforms:
    Java 8+ (for Java 7, you can explore source code here)
    Android 3.0+ (API 11+)

Installation

Download the latest JAR or grab via Maven:
1
<dependency>
2
<groupId>foundation.icon</groupId>
3
<artifactId>icon-sdk</artifactId>
4
<version>[x.y.z]</version>
5
</dependency>
Copied!
or Gradle:
1
dependencies {
2
implementation 'foundation.icon:icon-sdk:[x.y.z]'
3
}
Copied!

Using the SDK

IconService

APIs are called through IconService. IconService can be initialized as follows.
1
// Creates an instance of IconService using the HTTP provider.
2
IconService iconService = new IconService(new HttpProvider("http://localhost:9000", 3));
Copied!
The code below shows initializing IconService with a custom HTTP client.
1
OkHttpClient okHttpClient = new OkHttpClient.Builder()
2
.readTimeout(200, TimeUnit.MILLISECONDS)
3
.writeTimeout(600, TimeUnit.MILLISECONDS)
4
.build();
5
6
IconService iconService = new IconService(new HttpProvider(okHttpClient, "http://localhost:9000", 3));
Copied!

Queries

All queries are requested by a Request object. Query requests can be executed as Synchronized or Asynchronized. Once the request has been executed, the same request object cannot be executed again.
1
Request<Block> request = iconService.getBlock(height);
2
3
// Synchronized request execution
4
try {
5
Block block = request.execute();
6
...
7
} catch (Exception e) {
8
...
9
}
10
11
// Asynchronized request execution
12
request.execute(new Callback<Block>(){
13
@Override
14
public void onSuccess(Block block) {
15
...
16
}
17
18
@Override
19
public void onFailure(Exception exception) {
20
...
21
}
22
});
Copied!
The querying APIs are as follows.
1
// Gets the block
2
Request<Block> request = iconService.getBlock(new BigInteger("1000")); // by height
3
Request<Block> request = iconService.getBlock(new Bytes("0x000...000"); // by hash
4
Request<Block> request = iconService.getLastBlock(); // the last block
5
6
// Gets the balance of an given account
7
Request<BigInteger> request = iconService.getBalance(new Address("hx000...1");
8
9
// Gets a list of the SCORE API
10
Request<List<ScoreApi>> request = iconService.getScoreApi(new Address("cx000...1"));
11
12
// Gets the total supply of icx
13
Request<BigInteger> request = iconService.getTotalSupply();
14
15
// Gets a transaction matching the given transaction hash
16
Request<Transaction> request = iconService.getTransaction(new Bytes("0x000...000"));
17
18
// Gets the result of the transaction matching the given transaction hash
19
Request<TransactionResult> request = iconService.getTransactionResult(new Bytes("0x000...000"));
20
21
// Calls a SCORE read-only API
22
Call<BigInteger> call = new Call.Builder()
23
.from(wallet.getAddress())
24
.to(scoreAddress)
25
.method("balanceOf")
26
.params(params)
27
.buildWith(BigInteger.class);
28
Request<BigInteger> request = iconService.call(call);
29
30
// Calls without response type
31
Call<RpcItem> call = new Call.Builder()
32
.from(wallet.getAddress())
33
.to(scoreAddress)
34
.method("balanceOf")
35
.params(params)
36
.build();
37
Request<RpcItem> request = iconService.call(call);
38
try {
39
RpcItem rpcItem = request.execute();
40
BigInteger balance = rpcItem.asInteger();
41
...
42
} catch (Exception e) {
43
...
44
}
Copied!

Transactions

Calling SCORE APIs to change states is requested as sending a transaction.
Before sending a transaction, the transaction should be signed. It can be done using a Wallet object.
Loading wallets and storing the Keystore
1
// Generates a wallet.
2
Wallet wallet = KeyWallet.create();
3
4
// Loads a wallet from the private key.
5
Wallet wallet = KeyWallet.load(new Bytes("0x0000"));
6
7
// Loads a wallet from the key store file.
8
File file = new File("./key.keystore");
9
Wallet wallet = KeyWallet.load("password", file);
10
11
// Stores the keystore on the file path.
12
File dir = new File("./");
13
KeyWallet.store(wallet, "password", dir); // throw exception if an error exists.
Copied!
Creating transactions
1
// send ICX
2
Transaction transaction = TransactionBuilder.newBuilder()
3
.nid(networkId)
4
.from(wallet.getAddress())
5
.to(scoreAddress)
6
.value(new BigInteger("150000000"))
7
.stepLimit(new BigInteger("1000000"))
8
.nonce(new BigInteger("1000000"))
9
.build();
10
11
// deploy a SCORE
12
Transaction transaction = TransactionBuilder.newBuilder()
13
.nid(networkId)
14
.from(wallet.getAddress())
15
.to(scoreAddress)
16
.stepLimit(new BigInteger("5000000"))
17
.nonce(new BigInteger("1000000"))
18
.deploy("application/zip", content)
19
.params(params)
20
.build();
21
22
// call a method in SCORE
23
Transaction transaction = TransactionBuilder.newBuilder()
24
.nid(networkId)
25
.from(wallet.getAddress())
26
.to(scoreAddress)
27
.value(new BigInteger("150000000"))
28
.stepLimit(new BigInteger("1000000"))
29
.nonce(new BigInteger("1000000"))
30
.call("transfer")
31
.params(params)
32
.build();
33
34
// send a message
35
Transaction transaction = TransactionBuilder.newBuilder()
36
.nid(networkId)
37
.from(wallet.getAddress())
38
.to(scoreAddress)
39
.value(new BigInteger("150000000"))
40
.stepLimit(new BigInteger("1000000"))
41
.nonce(new BigInteger("1000000"))
42
.message(message)
43
.build();
Copied!
SignedTransaction object signs a transaction using the wallet. And the request can be executed as Synchronized or Asynchronized like a query request. Once the request has been executed, the same request object cannot be executed again.
1
SignedTransaction signedTransaction = new SignedTransaction(transaction, wallet);
2
3
Request<Bytes> request = iconService.sendTransaction(signedTransaction);
4
5
// Synchronized request execution
6
try {
7
Bytes txHash = request.execute();
8
...
9
} catch (Exception e) {
10
...
11
}
12
13
// Asynchronized request execution
14
request.execute(new Callback<Bytes>() {
15
@Override
16
public void onSuccess(Bytes result) {
17
...
18
}
19
20
@Override
21
public void onFailure(Exception exception) {
22
...
23
}
24
});
Copied!

Step Estimation

@ Available since: 0.9.12
It is important to set a proper stepLimit value in your transaction to make the submitted transaction executed successfully.
estimateStep API provides a way to estimate the Step usage of a given transaction. Using the method, you can get an estimated Step usage before sending your transaction then make a SignedTransaction with the stepLimit based on the estimation.
1
// make a raw transaction without the stepLimit
2
Transaction transaction = TransactionBuilder.newBuilder()
3
.nid(networkId)
4
.from(fromAddress)
5
.to(toAddress)
6
.nonce(BigInteger.valueOf(1))
7
.call("transfer")
8
.params(params)
9
.build();
10
11
// get an estimated step value
12
BigInteger estimatedStep = iconService.estimateStep(transaction).execute();
13
14
// set some margin
15
BigInteger margin = BigInteger.valueOf(10000);
16
17
// make a signed transaction with the same raw transaction and the estimated step
18
SignedTransaction signedTransaction = new SignedTransaction(transaction, wallet, estimatedStep.add(margin));
19
Bytes txHash = iconService.sendTransaction(signedTransaction).execute();
20
...
Copied!
Note that the estimation can be smaller or larger than the actual amount of step to be used by the transaction, so it is recommended to add some margin to the estimation when you set the stepLimit of the SignedTransaction.

Converter

All the requests and responses values are parcelled as RpcItem (RpcObject, RpcArray, RcpValue). You can convert your own class using RpcConverter.
1
iconService.addConverterFactory(new RpcConverter.RpcConverterFactory() {
2
@Override
3
public RpcConverter create(Class type) {
4
if (type.isAssignableFrom(Person.class)) {
5
return new RpcConverter<Person>() {
6
@Override
7
public Person convertTo(RpcItem object) {
8
// Unpacking from RpcItem to the user defined class
9
String name = object.asObject().getItem("name").asString();
10
BigInteger age = object.asObject().getItem("age").asInteger();
11
return new Person(name, age);
12
}
13
14
@Override
15
public RpcItem convertFrom(Person person) {
16
// Packing from the user defined class to RpcItem
17
return new RpcObject.Builder()
18
.put("name", person.name)
19
.put("age", person.age)
20
.build();
21
}
22
};
23
}
24
return null;
25
}
26
});
27
28
...
29
30
class Person {
31
public Person(String name, BigInteger age) {}
32
}
33
34
...
35
36
Call<Person> call = new Call.Builder()
37
.from(fromAddress)
38
.to(scoreAddress)
39
.method("searchMember")
40
.params(person) // the input parameter is an instance of Person type
41
.buildWith(Person.class); // build with the response type 'Person'
42
43
Person memberPerson = iconService.call(call).execute();
Copied!

Code Examples

Wallet

This example shows how to create a new KeyWallet or load wallet with a private key or Keystore file.
Create a wallet
Create new EOA by calling create function. After creation, the address and private key can be looked up.
1
KeyWallet wallet = KeyWallet.create(); // Wallet Creation
2
System.out.println("address:" + wallet.getAddress()); // Address Check
3
System.out.println("privateKey:" + wallet.getPrivateKey()); // PrivateKey Check
4
5
// Output
6
address:hx4d37a7013c14bedeedbe131c72e97ab337aea159
7
privateKey:00e1d6541bfd8be7d88be0d24516556a34ab477788022fa07b4a6c1d862c4de516
Copied!
Load a wallet
You can call existing EOA by calling load function.
After creation, address and private key can be looked up.
1
String privateKey;
2
KeyWallet wallet = KeyWallet.load(new Bytes(privateKey)); // Load keyWallet with privateKey
3
System.out.println("address:" + wallet.getAddress()); // Address lookup
4
System.out.println("privateKey:" + wallet.getPrivateKey()); // PrivateKey lookup
Copied!
Store the wallet
After KeyWallet object creation, the Keystore file can be stored by calling store function.
After calling store, the Keystore file’s name can be looked up with the returned value.
1
String password;
2
KeyWallet wallet; /* create or load keywallet */
3
File destinationDirectory = new File(/* directory Path */);
4
String fileName = KeyWallet.store(wallet, password, destinationDirectory);
5
System.out.println("fileName:" + fileName); // Keystore file name output
6
7
// Output
8
fileName:UTC--2018-08-30T03-27-41.768000000Z--hx4d37a7013c14bedeedbe131c72e97ab337aea159.json
Copied!

ICX Transfer

This example shows how to transfer ICX and check the result.
For the KeyWallet and IconService creation, please refer to the information above.
ICX transfer transaction
In this example, you can create a KeyWallet with CommonData.PRIVATE_KEY_STRING and transfer 1 ICX to CommonData.ADDRESS_1.
1
Wallet wallet = KeyWallet.load(new Bytes(CommonData.PRIVATE_KEY_STRING));
2
Address toAddress = new Address(CommonData.ADDRESS_1);
3
// 1 ICX -> 1000000000000000000 loop conversion
4
BigInteger value = IconAmount.of("1", IconAmount.Unit.ICX).toLoop();
Copied!
Generate a transaction using the values above.
1
// Network ID ("1" for Mainnet, "2" for Testnet, etc)
2
BigInteger networkId = new BigInteger("3");
3
// Only `default` step cost is required to transfer ICX: it is `100000` as of now.
4
BigInteger stepLimit = new BigInteger("100000");
5
6
// Timestamp is used to prevent the identical transactions. Only current time is required (Standard unit: us)
7
// If the timestamp is considerably different from the current time, the transaction will be rejected.
8
long timestamp = System.currentTimeMillis() * 1000L;
9
10
//Enter transaction information
11
Transaction transaction = TransactionBuilder.newBuilder()
12
.nid(networkId)
13
.from(fromAddress)
14
.to(toAddress)
15
.value(value)
16
.stepLimit(stepLimit)
17
.timestamp(new BigInteger(Long.toString(timestamp)))
18
.build();
Copied!
Generate a SignedTransaction to add the signature of the transaction.
1
// Create signature of the transaction
2
SignedTransaction signedTransaction = new SignedTransaction(transaction, wallet);
3
// Read params to transfer to nodes
4
System.out.println(signedTransaction.getProperties());
5
// Send the transaction
6
Bytes txHash = iconService.sendTransaction(signedTransaction).execute();
Copied!
Check the transaction result
After a transaction is sent, the result can be looked up with the returned hash value.
In this example, you can check your transaction result in every 2 seconds because of the block confirmation time. Checking the result is as follows:
1
// Check the result with the transaction hash
2
TransactionResult result = iconService.getTransactionResult(hash).execute();
3
System.out.println("transaction status(1:success, 0:failure):"+result.getStatus());
4
5
// Output
6
transaction status(1:success, 0:failure):1
Copied!
You can check the following information using the TransactionResult.
    status : 1 (success), 0 (failure)
    to : transaction’s receiving address
    failure : Only exists if the status is 0(failure). code(str), message(str) property included
    txHash : transaction hash
    txIndex : transaction index in a block
    blockHeight : Block height of the transaction
    blockHash : Block hash of the transaction
    cumulativeStepUsed : Accumulated amount of consumed step until the transaction is executed in block
    stepUsed : Consumed step amount to send the transaction
    stepPrice : Consumed step price to send the transaction
    scoreAddress : SCORE address if the transaction generated SCORE (optional)
    eventLogs : List of EventLogs written during the execution of the transaction.
    logsBloom : Bloom Filter of the indexed data of the Eventlogs.
Check the ICX balance
In this example, you can check the ICX balance by looking up the transaction before and after the transaction.
ICX balance can be confirmed by calling getBalance function from IconService
1
KeyWallet wallet; /* create or load */
2
// Check the wallet balance
3
BigInteger balance = iconService.getBalance(wallet.getAddress()).execute();
4
System.out.println("balance:" + balance));
5
6
// Output
7
balance:5000000000000000000
Copied!

Token Deploy and Transfer

This example shows how to deploy a token and check the result. After that, shows how to send tokens and check the balance.
For KeyWallet and IconService generation, please refer to the information above.
Token deploy transaction
You need a SCORE project to deploy token.
In this example, you will use ‘sampleToken.zip’ from the ‘resources’ folder.
    sampleToken.zip: SampleToken SCORE project zip file.
Generate a KeyWallet using CommonData.PRIVATE_KEY_STRING, then read the binary data from ‘sampleToken.zip’
1
Wallet wallet = KeyWallet.load(new Bytes(CommonData.PRIVATE_KEY_STRING));
2
// Read sampleToken.zip from ‘resources’ folder.
3
byte[] content = /* score binary */
Copied!
Prepare basic information of the token you want to deploy and make a parameter object.
1
BigInteger initialSupply = new BigInteger("100000000000");
2
BigInteger decimals = new BigInteger("18");
3
4
RpcObject params = new RpcObject.Builder()
5
.put("_initialSupply", new RpcValue(initialSupply))
6
.put("_decimals", new RpcValue(decimals))
7
.build();
Copied!
Generate a raw transaction to deploy a token SCORE without the stepLimit value.
1
Transaction transaction = TransactionBuilder.newBuilder()
2
.nid(networkId)
3
.from(wallet.getAddress())
4
.to(CommonData.SCORE_INSTALL_ADDRESS)
5
.timestamp(new BigInteger(Long.toString(timestamp)))
6
.deploy(contentType, content)
7
.params(params)
8
.build();
Copied!
Get an estimated Step value using estimateStep API of IconService.
1
BigInteger estimatedStep = iconService.estimateStep(transaction).execute();
Copied!
Generate a SignedTransaction with the same raw transaction and the estimated Step. Note that the estimation can be smaller or larger than the actual amount of step to be used by the transaction. So we need to add some margin to the estimation when you set the stepLimit of the SignedTransaction.
1
// Set some margin for the operation of `on_install`
2
BigInteger margin = BigInteger.valueOf(10000);
3
4
SignedTransaction signedTransaction = new SignedTransaction(transaction, wallet, estimatedStep.add(margin));
Copied!
Calling sendTransaction API of IconService will return the transaction hash.
1
Bytes txHash = iconService.sendTransaction(signedTransaction).execute();
2
3
// Print Transaction Hash
4
System.out.println("txHash:"+txHash);
5
6
// Output
7
txHash:0x6b17886de346655d96373f2e0de494cb8d7f36ce9086cb15a57d3dcf24523c8f
Copied!
Check the Result
After sending the transaction, you can check the result with the returned hash value.
In this example, you can check your transaction result in every 2 seconds because of the block confirmation time.
If the transaction succeeds, you can check the scoreAddress from the result.
You can use the SCORE after the SCORE passes the audit and is finally accepted to deploy.
1
// Checking the results with transaction hash
2
TransactionResult result = iconService.getTransactionResult(hash).execute();
3
System.out.println("transaction status(1:success, 0:failure):"+result.getStatus());
4
System.out.println("created score address:"+result.getScoreAddress());
5
System.out.println("waiting accept score...");
6
7
// Output
8
transaction status(1:success, 0:failure):1
9
created score address:cxd7fce67cc95b731dfbfdd8c8b34e8a5d0664a9ed
10
waiting accept score...
Copied!
For the 'TransactionResult', please refer to the IcxTransactionExample.
Token transfer transaction
You can get the token SCORE address by checking the scoreAddress from the deploy transaction result above, and use this to send the token.
You can generate a KeyWallet using CommonData.PRIVATE_KEY_STRING just like in the case of IcxTransactionExample, then send 1 Token to CommonData.ADDRESS_1.
1
Wallet wallet = KeyWallet.load(new Bytes(CommonData.PRIVATE_KEY_STRING));
2
Address toAddress = new Address(CommonData.ADDRESS_1);
3
4
// Deploy a token SCORE and get the SCORE address
5
Address tokenAddress = new DeployTokenExample().deploy(wallet);
6
7
int tokenDecimals = 18; // token decimal
8
// 1 ICX -> 1000000000000000000 conversion
9
BigInteger value = IconAmount.of("1", tokenDecimals).toLoop();
Copied!
Generate a transaction with the given parameters above. You have to add receiving address and value to RpcObject to send token.
1
// Network ID ("1" for Mainnet, "2" for Testnet, etc)
2
BigInteger networkId = new BigInteger("3");
3
// Transaction creation time (timestamp is in the microsecond)
4
long timestamp = System.currentTimeMillis() * 1000L;
5
// 'transfer' as a methodName means to transfer token
6
// https://github.com/icon-project/IIPs/blob/master/IIPS/iip-2.md
7
String methodName = "transfer";
8
9
// Enter receiving address and the token value.
10
// You must enter the given key name ("_to", "_value"). Otherwise, the transaction will be rejected.
11
RpcObject params = new RpcObject.Builder()
12
.put("_to", new RpcValue(toAddress))
13
.put("_value", new RpcValue(value))
14
.build();
15
16
// Create a raw transaction to transfer token (without stepLimit)
17
Transaction transaction = TransactionBuilder.newBuilder()
18
.nid(networkId)
19
.from(wallet.getAddress())
20
.to(tokenAddress)
21
.timestamp(new BigInteger(Long.toString(timestamp)))
22
.call(methodName)
23
.params(params)
24
.build();
25
26
// Get an estimated step value
27
BigInteger estimatedStep = iconService.estimateStep(transaction).execute();
28
29
// Create a signedTransaction with the sender's wallet and the estimatedStep
30
SignedTransaction signedTransaction = new SignedTransaction(transaction, wallet, estimatedStep);
Copied!
Call sendTransaction from IconService to check the transaction hash.
1
// Send transaction
2
Bytes txHash = iconService.sendTransaction(signedTransaction).execute();
3
4
// Print transaction hash
5
System.out.println("txHash:"+txHash);
6
7
// Output
8
txHash:0x6b17886de346655d96373f2e0de494cb8d7f36ce9086cb15a57d3dcf24523c8f
Copied!
Check the Result
You can check the result with the returned hash value of your transaction.
In this example, you check your transaction result in every 2 seconds because the block confirmation time is around 2 seconds. Checking the result is as follows:
1
// Check the result with the transaction hash
2
TransactionResult result = iconService.getTransactionResult(hash).execute();
3
System.out.println("transaction status(1:success, 0:failure):"+result.getStatus());
4
5
// Output
6
transaction status(1:success, 0:failure):1
Copied!
For the TransactionResult, please refer to the ICX Transfer example.
Check the token balance
In this example, you can check the token balance before and after the transaction.
You can check the token balance by calling balanceOf from the token SCORE.
1
KeyWallet wallet; /* create or load */
2
Address tokenAddress; /* returned from `new DeployTokenExample().deploy(wallet)` */
3
String methodName = "balanceOf"; /* Method name to check the balance */
4
5
// Enter the address to check balance.
6
// You must enter the given key name ("_owner"). Otherwise, your transaction will be rejected.
7
RpcObject params = new RpcObject.Builder()
8
.put("_owner", new RpcValue(wallet.getAddress()))
9
.build();
10
11
Call<RpcItem> call = new Call.Builder()
12
.to(tokenAddress)
13
.method(methodName)
14
.params(params)
15
.build();
16
17
RpcItem result = iconService.call(call).execute();
18
BigInteger balance = result.asInteger();
19
System.out.println("balance:"+balance));
20
21
// Output
22
balance:6000000000000000000
Copied!

Sync Block

This example shows how to read block information and print the transaction result for every block creation.
Please refer to above for KeyWallet and IconService creation.
Read block information
In this example, getLastBlock is called periodically in order to check the new blocks,
by updating the transaction information for every block creation.
1
// Check the recent blocks
2
Block block = iconService.getLastBlock().execute();
3
System.out.println("block height:"+block.getHeight());
4
5
// Output
6
block height:237845
Copied!
If a new block has been created, get the transaction list.
1
List<ConfirmedTransaction> txList = block.getTransactions();
2
System.out.println("transaction hash:" + transaction.getTxHash());
3
System.out.println("transaction:" + transaction);
4
5
// Output
6
transaction hash:0x0d2b71ec3045bfd39f90da844cb03c58490fe364c7715cc299db346c1153fe0f
7
transaction:ConfirmedTransaction...stepLimit=0xfa0...value=0x21e19e...version=0x3...
Copied!
You can check the following information using the ConfirmedTransaction:
    version : json rpc server version
    to : Receiving address of the transaction
    value: The amount of ICX coins to transfer to the address. If omitted, the value is assumed to be 0
    timestamp: timestamp of the transmitting transaction (unit: microseconds)
    nid : network ID
    signature: digital signature data of the transaction
    txHash : transaction hash
    dataType: A value indicating the type of the data item (call, deploy, message)
    data: Various types of data are included according to dataType.
Transaction output
After reading the TransactionResult, merge with ConfirmedTransaction to send ICX or tokens. Transaction output is as follows:
1
TransactionResult txResult = iconService.getTransactionResult(transaction.getTxHash()).execute();
2
3
// Send ICX
4
if ((transaction.getValue() != null) &&
5
(transaction.getValue().compareTo(BigInteger.ZERO) > 0)) {
6
7
System.out.println("[Icx] status:" + txResult.getStatus() +
8
",from:" + transaction.getFrom() +
9
",to:" + transaction.getTo() +
10
",amount:" + transaction.getValue());
11
}
12
13
// Send token
14
if (transaction.getDataType() != null &&
15
transaction.getDataType().equals("call")) {
16
17
RpcObject data = transaction.getData().asObject();
18
String methodName = data.getItem("method").asString();
19
20
if (methodName != null && methodName.equals("transfer")) {
21
RpcObject params = data.getItem("params").asObject(); // SCORE params
22
BigInteger value = params.getItem("_value").asInteger(); // value
23
Address toAddr = params.getItem("_to").asAddress(); // to address value
24
25
String tokenName = getTokenName(transaction.getTo());
26
String symbol = getTokenSymbol(transaction.getTo());
27
String token = String.format("[%s Token(%s)]", tokenName, symbol);
28
System.out.println(token+",tokenAddress:" + transaction.getTo() +
29
",status:" + txResult.getStatus() +
30
",from:" + transaction.getFrom() +
31
",to:" + toAddr +
32
",amount:" + value);
33
}
34
}
Copied!
Check the token name & symbol
You can check the token SCORE by calling the name and symbol functions.
1
Address tokenAddress; /* returned from `new DeployTokenExample().deploy(wallet)` */
2
3
Call<RpcItem> call = new Call.Builder()
4
.to(tokenAddress)
5
.method("name")
6
.build();
7
8
RpcItem result = iconService.call(call).execute();
9
String tokenName = result.asString();
10
11
Call<RpcItem> call = new Call.Builder()
12
.to(tokenAddress)
13
.method("symbol")
14
.build();
15
16
result = iconService.call(call).execute();
17
String tokenSymbol = result.asString();
18
19
System.out.println("tokenName:"+tokenName);
20
System.out.println("tokenSymbol:"+tokenSymbol);
21
22
// Output
23
tokenName:StandardToken
24
tokenSymbol:ST
Copied!

Chagelog

References

Licenses

This project follows the Apache 2.0 License. Please refer to LICENSE for details.
Last modified 1mo ago