Accumulate
Search…
Java SDK
Accumulate Java SDK Guide
The Accumulate SDK is a Java library for implementing sending and receiving tokens in Java apps with Accumulate. It provides easy-to-use Java methods, and Integrating our SDK into your Desktop application is easy and beginner-friendly.
Accumulate Java SDK helps the developers to integrate their applications with Accumulate network. It has ready-made methods to execute. So, the developers can reuse the codebase and develop their applications efficiently.
To view the Java generated documentation, visit this link
Requirements:
In this guide, we focused on two main parts, the Installation and code examples of the Java SDK.
This tutorial uses IntelliJ

Installation

Add pom.xml file
  1. 1.
    Open an existing Java project
  2. 2.
    In the Project tool window, right-click your project and select Add Framework Support.
3. In the dialog that opens, select Maven from the options on the left and click OK.
IntelliJ IDEA will automatically add a pom.xml file to the project and generates the standard Maven layout in the Project tool window.
Open the generated pom.xml file and add the below information. The artifactId and version are specified automatically.
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<project xmlns="http://maven.apache.org/POM/4.0.0"
4
5
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
7
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
8
9
<modelVersion>4.0.0</modelVersion>
10
11
12
13
<groupId>org.example</groupId>
14
15
<artifactId>test-project</artifactId>
16
17
<version>1.0-SNAPSHOT</version>
18
19
<repositories>
20
21
<repository>
22
23
<id>com.sdk.accumulate</id>
24
25
<url>http://18.232.151.167:8082/artifactory/libs-release-local/</url>
26
27
</repository>
28
29
</repositories>
30
31
<properties>
32
33
<maven.compiler.source>11</maven.compiler.source>
34
35
<maven.compiler.target>11</maven.compiler.target>
36
37
</properties>
38
39
<dependencies>
40
41
<dependency>
42
43
<groupId>com.sdk.accumulate</groupId>
44
45
<artifactId>AccumulateJavaSDK</artifactId>
46
47
<version>1.1</version>
48
49
</dependency>
50
51
<dependency>
52
53
<groupId>org.purejava</groupId>
54
55
<artifactId>tweetnacl-java</artifactId>
56
57
<version>1.1.2</version>
58
59
</dependency>
60
61
<dependency>
62
63
<groupId>org.apache.commons</groupId>
64
65
<artifactId>commons-lang3</artifactId>
66
67
<version>3.12.0</version>
68
69
</dependency>
70
71
<dependency>
72
73
<groupId>com.fasterxml.jackson.core</groupId>
74
75
<artifactId>jackson-databind</artifactId>
76
77
<version>2.13.2.1</version>
78
79
</dependency>
80
81
<dependency>
82
83
<groupId>org.apache.httpcomponents</groupId>
84
85
<artifactId>httpclient</artifactId>
86
87
<version>4.5.13</version>
88
89
</dependency>
90
91
</dependencies>
92
93
</project>
Copied!

Configure the Java SDK repo (settings.xml configuration)

  • Currently, the Java SDK is hosted in a private repository. To access the repository we have to specify the username and password of the repository.
  • To set the credentials, we have to create a settings file inside the .m2 directory.
  • Since we are using the maven, the system itself can create the .m2 directory while maven installation.
  • Else follow the below steps.
  • $ cd - It will goto the home directory. (for example /home/user/)
  • $ mkdir .m2 - It will create a .m2 directory (/home/user/.m2/)
  • Now create a settings.xml file inside the .m2 directory (/home/user/.m2/settings.xml)
  • Then paste the below xml content in the settings.xml file.
1
<?xml version="1.0" encoding="UTF-8"?>
2
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.2.0"
3
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4
<servers>
5
<server>
6
<username>admin</username>
7
<password>[email protected]</password>
8
<id>com.sdk.accumulate</id>
9
</server>
10
</servers>
11
<mirrors>
12
<mirror>
13
<id>insecure-repo</id>
14
<mirrorOf>external:http:*</mirrorOf>
15
<url>http://18.232.151.167:8082/artifactory/libs-release-local/</url>
16
<blocked>false</blocked>
17
</mirror>
18
</mirrors>
19
</settings>
20
Copied!
  • And save the file
  • Now the system can access the Java SDK private repository.
Now you have your project fully configured to use the Accumulate Java SDK. We have some code examples below to help you get started using the SDK to make it easier for you.

Code Examples

The Accumulate java SDK methods with examples of how to use them in your project.
LiteAccount
1
public class LiteAccount{
2
public static void main(String[] args) throws Exception {
3
4
TestNetClient client = new TestNetClient();
5
LiteAccount liteAccount = LiteAccount.generate();
6
System.out.println("response" + " " + liteAccount);
7
8
}
9
}
Copied!
Faucet
1
public class Faucet{
2
public static void main(String[] args) throws Exception {
3
4
TestNetClient client = new TestNetClient();
5
LiteAccount liteAccount = LiteAccount.generate();
6
7
String faucet = client.getFaucet(liteAccount.url().string());
8
9
System.out.println("response" + " " + faucet);
10
11
12
}
13
}
Copied!
Add Credit
1
public class AddCredit {
2
public static void main(String[] args) throws Exception {
3
4
TestNetClient client = new TestNetClient();
5
LiteAccount liteAccount = LiteAccount.generate();
6
String response = client.getFaucet(liteAccount.url().string());
7
System.out.println("Lite Account Response: "+response);
8
9
AddCreditsArg addCreditsArg = new AddCreditsArg();
10
addCreditsArg.setAmount(1000);
11
addCreditsArg.setRecipient(liteAccount.url().string());
12
String addCreditsResponse = client.addCredits(addCreditsArg,liteAccount);
13
System.out.println("Add Credits Response: "+addCreditsResponse);
14
15
}
16
}
Copied!
BurnTokens
1
public class BurnTokens {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
LiteAccount liteAccount = LiteAccount.generate();
5
String response = client.getFaucet(liteAccount.url().string());
6
System.out.println("Lite Account Response: "+response);
7
8
BurnTokensArg burnTokensArg = new BurnTokensArg();
9
burnTokensArg.setAmount(BigInteger.valueOf(56879));
10
String burnTokensResponse = client.burnTokens(burnTokensArg,liteAccount);
11
System.out.println("Burn token Response: "+burnTokensResponse);
12
}
13
}
Copied!
CreateADI
1
public class CreateADI {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
LiteAccount liteAccount = LiteAccount.generate();
5
String response = client.getFaucet(liteAccount.url().string());
6
System.out.println("Lite Account Response: "+response);
7
8
CreateIdentityArg createIdentityArg = new CreateIdentityArg();
9
createIdentityArg.setUrl("acc://my-own-identity");
10
TweetNaclFast.Signature.KeyPair kp = TweetNaclFast.Signature.keyPair();
11
createIdentityArg.setPublicKey(kp.getPublicKey());
12
createIdentityArg.setKeyBookName("test-key-book");
13
createIdentityArg.setKeyPageName("test-key-page");
14
String createAdiResponse = client.createIdentity(createIdentityArg,liteAccount);
15
System.out.println("Create ADI Response: "+createAdiResponse);
16
}
17
}
Copied!
CreateDataAccount
1
public class CreateDataAccount {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
LiteAccount liteAccount = LiteAccount.generate();
5
String response = client.getFaucet(liteAccount.url().string());
6
System.out.println("Lite Account Response: "+response);
7
8
9
String identityUrl = "acc://my-own-identity-1";
10
CreateIdentityArg createIdentityArg = new CreateIdentityArg();
11
createIdentityArg.setUrl(identityUrl);
12
TweetNaclFast.Signature.KeyPair kp = TweetNaclFast.Signature.keyPair();
13
createIdentityArg.setPublicKey(kp.getPublicKey());
14
createIdentityArg.setKeyBookName("test-key-book");
15
createIdentityArg.setKeyPageName("test-key-page");
16
String createAdiResponse = client.createIdentity(createIdentityArg,liteAccount);
17
System.out.println("Create ADI Response: "+createAdiResponse);
18
19
ADI adi = new ADI(AccURL.toAccURL(identityUrl),kp);
20
21
CreateDataAccountArg createDataAccountArg = new CreateDataAccountArg();
22
createDataAccountArg.setUrl(identityUrl+"/data");
23
createDataAccountArg.setKeyBookUrl(identityUrl+"/test-key-book");
24
createDataAccountArg.setManagerKeyBookUrl(identityUrl+"/test-key-book");
25
createDataAccountArg.setScratch(true);
26
String createDataAccountResponse = client.createDataAccount(createDataAccountArg,adi);
27
System.out.println("Create data account Response: "+createDataAccountResponse);
28
}
29
}
Copied!
CreateKeyBook
1
public class CreateKeyBook {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
LiteAccount liteAccount = LiteAccount.generate();
5
String response = client.getFaucet(liteAccount.url().string());
6
System.out.println("Lite Account Response: "+response);
7
8
String identityUrl = "acc://my-own-identity-1";
9
CreateIdentityArg createIdentityArg = new CreateIdentityArg();
10
createIdentityArg.setUrl(identityUrl);
11
TweetNaclFast.Signature.KeyPair kp = TweetNaclFast.Signature.keyPair();
12
createIdentityArg.setPublicKey(kp.getPublicKey());
13
createIdentityArg.setKeyBookName("test-key-book");
14
createIdentityArg.setKeyPageName("test-key-page");
15
String createAdiResponse = client.createIdentity(createIdentityArg,liteAccount);
16
System.out.println("Create ADI Response: "+createAdiResponse);
17
ADI adi = new ADI(AccURL.toAccURL(identityUrl),kp);
18
19
CreateKeyBookArg createKeyBookArg = new CreateKeyBookArg();
20
createKeyBookArg.setUrl(identityUrl+"/book1");
21
List<String> pages = new ArrayList<>();
22
pages.add(identityUrl+"/test-key-page");
23
createKeyBookArg.setPages(pages);
24
String createKeyBook = client.createKeyBook(createKeyBookArg,adi);
25
System.out.println("Create Key book Response: "+createKeyBook);
26
}
27
}
Copied!
CreateKeyPage
1
public class CreateKeyPage {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
LiteAccount liteAccount = LiteAccount.generate();
5
String response = client.getFaucet(liteAccount.url().string());
6
System.out.println("Lite Account Response: "+response);
7
8
String identityUrl = "acc://my-own-identity-1";
9
CreateIdentityArg createIdentityArg = new CreateIdentityArg();
10
createIdentityArg.setUrl(identityUrl);
11
TweetNaclFast.Signature.KeyPair kp = TweetNaclFast.Signature.keyPair();
12
createIdentityArg.setPublicKey(kp.getPublicKey());
13
createIdentityArg.setKeyBookName("test-key-book");
14
createIdentityArg.setKeyPageName("test-key-page");
15
String createAdiResponse = client.createIdentity(createIdentityArg,liteAccount);
16
System.out.println("Create ADI Response: "+createAdiResponse);
17
ADI adi = new ADI(AccURL.toAccURL(identityUrl),kp);
18
19
CreateKeyPageArg createKeyPageArg = new CreateKeyPageArg();
20
List<byte[]> keys = new ArrayList<>();
21
keys.add(liteAccount.getPublicKey());
22
createKeyPageArg.setKeys(keys);
23
createKeyPageArg.setUrl(identityUrl+"/test-key-page");
24
String createKeyPageResponse = client.createKeyPage(createKeyPageArg,adi);
25
System.out.println("Create Key page Response: "+createKeyPageResponse);
26
}
27
}
28
Copied!
CreatToken
1
public class CreateToken {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
LiteAccount liteAccount = LiteAccount.generate();
5
String response = client.getFaucet(liteAccount.url().string());
6
System.out.println("Lite Account Response: "+response);
7
8
AddCreditsArg addCreditsArg = new AddCreditsArg();
9
addCreditsArg.setAmount(500000);
10
addCreditsArg.setRecipient(liteAccount.url().string());
11
String addCreditsResponse = client.addCredits(addCreditsArg,liteAccount);
12
System.out.println("Add Credits Response: "+addCreditsResponse);
13
14
String identityUrl = "acc://my-own-identity-3";
15
CreateIdentityArg createIdentityArg = new CreateIdentityArg();
16
createIdentityArg.setUrl(identityUrl);
17
TweetNaclFast.Signature.KeyPair kp = TweetNaclFast.Signature.keyPair();
18
createIdentityArg.setPublicKey(kp.getPublicKey());
19
createIdentityArg.setKeyBookName("test-key-book");
20
createIdentityArg.setKeyPageName("test-key-page");
21
String createAdiResponse = client.createIdentity(createIdentityArg,liteAccount);
22
System.out.println("Create ADI Response: "+createAdiResponse);
23
Thread.sleep(5000);
24
ADI adi = new ADI(AccURL.toAccURL(identityUrl),kp);
25
26
CreateTokenArg createTokenArg = new CreateTokenArg();
27
createTokenArg.setUrl(identityUrl+"/tok");
28
createTokenArg.setKeyBookUrl(identityUrl+"/test-key-page");
29
createTokenArg.setSymbol("INR");
30
createTokenArg.setPrecision(10);
31
createTokenArg.setProperties("acc://my-own-identity-3/INR");
32
createTokenArg.setInitialSupply(BigInteger.valueOf(1000000000));
33
createTokenArg.setHasSupplyLimit(true);
34
createTokenArg.setManager("acc://my-own-identity-3/test-key-page");
35
String createTokenResponse = client.createToken(createTokenArg,adi);
36
System.out.println("Create Token Response: "+createTokenResponse);
37
}
38
}
Copied!
CreatTokenAccount
1
public class CreateTokenAccount {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
LiteAccount liteAccount = LiteAccount.generate();
5
String response = client.getFaucet(liteAccount.url().string());
6
System.out.println("Lite Account Response: " + response);
7
8
String identityUrl = "acc://my-own-identity-2";
9
CreateIdentityArg createIdentityArg = new CreateIdentityArg();
10
createIdentityArg.setUrl(identityUrl);
11
TweetNaclFast.Signature.KeyPair kp = TweetNaclFast.Signature.keyPair();
12
createIdentityArg.setPublicKey(kp.getPublicKey());
13
createIdentityArg.setKeyBookName("test-key-book");
14
createIdentityArg.setKeyPageName("test-key-page");
15
String createAdiResponse = client.createIdentity(createIdentityArg, liteAccount);
16
System.out.println("Create ADI Response: " + createAdiResponse);
17
ADI adi = new ADI(AccURL.toAccURL(identityUrl), kp);
18
19
CreateTokenAccountArg createTokenAccountArg = new CreateTokenAccountArg();
20
createTokenAccountArg.setUrl(identityUrl);
21
createTokenAccountArg.setTokenUrl(identityUrl + "/tok");
22
createTokenAccountArg.setKeyBookUrl(identityUrl + "/test-key-book");
23
createTokenAccountArg.setScratch(true);
24
String createTokenAccountResponse = client.createTokenAccount(createTokenAccountArg, adi);
25
System.out.println("Create Token Account Response: " + createTokenAccountResponse);
26
}
27
}
Copied!
IssueToken
1
public class IssueToken {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
5
LiteAccount liteAccount = LiteAccount.generate();
6
String response = client.getFaucet(liteAccount.url().string());
7
System.out.println("Lite Account Response: "+response);
8
9
LiteAccount liteAccount2 = LiteAccount.generate();
10
String response2 = client.getFaucet(liteAccount2.url().string());
11
System.out.println("Lite Account Response: "+response2);
12
13
IssueTokensArg issueTokensArg = new IssueTokensArg();
14
issueTokensArg.setRecipient(liteAccount2.url().string());
15
issueTokensArg.setAmount(1);
16
String issueTokensResponse = client.issueTokens(issueTokensArg,liteAccount);
17
System.out.println("Issue Token Response: "+issueTokensResponse);
18
}
19
}
Copied!
SendToken
1
public class SendToken {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
5
LiteAccount liteAccount = LiteAccount.generate();
6
String response = client.getFaucet(liteAccount.url().string());
7
System.out.println("Lite Account Response: "+response);
8
9
LiteAccount liteAccount2 = LiteAccount.generate();
10
String response2 = client.getFaucet(liteAccount2.url().string());
11
System.out.println("Lite Account Response: "+response2);
12
13
SendTokensArg sendTokensArg = new SendTokensArg();
14
List<TokenRecipientArg> to = new ArrayList<>();
15
TokenRecipientArg tokenRecipientArg = new TokenRecipientArg();
16
tokenRecipientArg.setAmount(20000000);
17
tokenRecipientArg.setUrl(liteAccount2.url().string());
18
to.add(tokenRecipientArg);
19
sendTokensArg.setTo(to);
20
String sendTokensResponse = client.sendToken(sendTokensArg,liteAccount);
21
System.out.println("Send Token Response: "+sendTokensResponse);
22
}
23
}
Copied!
UpdateKeyPage
1
public class UpdateKeyPage {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
5
LiteAccount liteAccount = LiteAccount.generate();
6
String response = client.getFaucet(liteAccount.url().string());
7
System.out.println("Lite Account Response: "+response);
8
9
CreateIdentityArg createIdentityArg = new CreateIdentityArg();
10
createIdentityArg.setUrl("acc://my-own-identity");
11
TweetNaclFast.Signature.KeyPair kp = TweetNaclFast.Signature.keyPair();
12
createIdentityArg.setPublicKey(kp.getPublicKey());
13
createIdentityArg.setKeyBookName("test-key-book");
14
createIdentityArg.setKeyPageName("test-key-page");
15
String createAdiResponse = client.createIdentity(createIdentityArg,liteAccount);
16
System.out.println("Create ADI Response: "+createAdiResponse);
17
18
UpdateKeyPageArg updateKeyPageArg = new UpdateKeyPageArg();
19
updateKeyPageArg.setOwner("acc://my-own-identity");
20
TweetNaclFast.Signature.KeyPair kp1 = TweetNaclFast.Signature.keyPair();
21
updateKeyPageArg.setNewKey(kp1.getPublicKey());
22
updateKeyPageArg.setKey(kp.getPublicKey());
23
updateKeyPageArg.setOperation(KeyPageOperation.UpdateKey);
24
String updateKeyPageResponse = client.updateKeyPage(updateKeyPageArg,liteAccount);
25
System.out.println("update KeyPage Response Response: "+updateKeyPageResponse);
26
}
27
}
Copied!
WriteData
1
public class WriteData {
2
public static void main(String[] args) throws Exception {
3
TestNetClient client = new TestNetClient();
4
LiteAccount liteAccount = LiteAccount.generate();
5
String response = client.getFaucet(liteAccount.url().string());
6
System.out.println("Lite Account Response: "+response);
7
8
String identityUrl = "acc://my-own-identity-1";
9
CreateIdentityArg createIdentityArg = new CreateIdentityArg();
10
createIdentityArg.setUrl(identityUrl);
11
TweetNaclFast.Signature.KeyPair kp = TweetNaclFast.Signature.keyPair();
12
createIdentityArg.setPublicKey(kp.getPublicKey());
13
createIdentityArg.setKeyBookName("test-key-book");
14
createIdentityArg.setKeyPageName("test-key-page");
15
String createAdiResponse = client.createIdentity(createIdentityArg,liteAccount);
16
System.out.println("Create ADI Response: "+createAdiResponse);
17
ADI adi = new ADI(AccURL.toAccURL(identityUrl),kp);
18
19
WriteDataArg writeDataArg = new WriteDataArg();
20
writeDataArg.setData("Test".getBytes(StandardCharsets.UTF_8));
21
List<byte[]> bytes = new ArrayList<>();
22
bytes.add(new byte[0]);
23
writeDataArg.setExtIds(bytes);
24
String writeDataResponse = client.writeData(writeDataArg,adi);
25
System.out.println("Write data Response Response: "+writeDataResponse);
26
}
27
}
Copied!