Code Monkey home page Code Monkey logo

eos-java-rpc-wrapper's Introduction

EOS Java API Wrapper

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
  • get_header_block_state
  • get_producers
  • push_block
  1. WALLET
  • set_dir
  • set_eosio_key
  1. NET
  • connect
  • disconnect
  • connections
  • status
  1. PRODUCER
  • pause
  • resume
  • paused

Requirements

  • Java 8
  • Maven

Installation

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>

Configuration

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();

Example Usage

Creating a wallet
eosApiRestClient.createWallet("walletName");

Getting a block

eosApiRestClient.getBlock("blockNumberOrId")

Signing and pushing a transaction

/* 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);

Notes

  • All methods are synchronous and blocking.
  • All methods will throw a catchable EOSApiException.

eos-java-rpc-wrapper's People

Contributors

adyliu avatar artjoma avatar dappstore123 avatar fletch153 avatar spebern avatar zhujk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.