Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.zhujk:eos-rpc:v1.0'
}
dependencies {
implementation("com.github.zhujk:eos-rpc:v1.0")
}
<dependency>
<groupId>com.github.zhujk</groupId>
<artifactId>eos-rpc</artifactId>
<version>v1.0</version>
</dependency>
libraryDependencies += "com.github.zhujk" % "eos-rpc" % "v1.0"
:dependencies [[com.github.zhujk/eos-rpc "v1.0"]]
A Java implementation of the EOS RPC Calls. Under the MIT Licence.
Created by eos42.
The api documentation can be found in the official eos developers portal: https://developers.eos.io/eosio-nodeos/reference
All but the following queries are supported: 1. CHAIN
Install using maven build tool. The artifact will need to be published locally.
Currently the artifiac is not in the official maven repositories. If you want to use it in a maven build, you can add the following repository
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
and dependency
<dependency>
<groupId>com.github.EOSEssentials</groupId>
<artifactId>eos-java-rpc-wrapper</artifactId>
<version>master</version>
</dependency>
Create a new instance of EosApiClient using the EosApiClientFactory, this will require a baseurl to be passed in.
This will use the same base url for all three api endpoints (history/chain/wallet).
EosApiRestClient eosApiRestClient = EosApiClientFactory.newInstance("http://127.0.0.1:8888").newRestClient();
If you want to use separate urls for those endpoints (e.g. you have a local wallet):
EosApiRestClient eosApiRestClient = EosApiClientFactory.newInstance(
walletBaseUrl, chainBaseUrl, historyBaseUrl).newRestClient();
eosApiRestClient.createWallet("walletName");
eosApiRestClient.getBlock("blockNumberOrId")
/* Create the rest client */
EosApiRestClient eosApiRestClient = EosApiClientFactory.newInstance("http://127.0.0.1:8888").newRestClient();
/* Create the json array of arguments */
Map<String, String> args = new HashMap<>(4);
args.put("from", "currency");
args.put("to", "eosio");
args.put("quantity", "44.0000 CUR");
args.put("memo", "My First Transaction");
AbiJsonToBin data = eosApiRestClient.abiJsonToBin("currency", "transfer", args);```
/* Get the head block */
Block block = eosApiRestClient.getBlock(eosApiRestClient.getChainInfo().getHeadBlockId());
/* Create Transaction Action Authorization */
TransactionAuthorization transactionAuthorization = new TransactionAuthorization();
transactionAuthorization.setActor("currency");
transactionAuthorization.setPermission("active");
/* Create Transaction Action */
TransactionAction transactionAction = new TransactionAction();
transactionAction.setAccount("currency");
transactionAction.setName("transfer");
transactionAction.setData(data.getBinargs());
transactionAction.setAuthorization(Collections.singletonList(transactionAuthorization));
/* Create a transaction */
PackedTransaction packedTransaction = new PackedTransaction();
packedTransaction.setRefBlockPrefix(block.getRefBlockPrefix().toString());
packedTransaction.setRefBlockNum(block.getBlockNum().toString());
packedTransaction.setExpiration("2018-05-10T18:38:19");
packedTransaction.setRegion("0");
packedTransaction.setMax_net_usage_words("0");
packedTransaction.setActions(Collections.singletonList(transactionAction));
/* Sign the Transaction */
SignedPackedTransaction signedPackedTransaction = eosApiRestClient.signTransaction(packedTransaction, Collections.singletonList("EOS7LPJ7YnwYiEHbBLz96fNkt3kf6CDDdesV5EsWoc3u3DJy31V2y"), "chainId");
/* Push the transaction */
PushedTransaction = eosApiRestClient.pushTransaction("none", signedPackedTransaction);