• This repository has been archived on 30/Aug/2022
  • Stars
    star
    125
  • Rank 286,335 (Top 6 %)
  • Language
    Java
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

EOSIO SDK for Java - API for integrating with EOSIO-based blockchains

Java Logo

EOSIO SDK for Java

Software License Language Java

EOSIO SDK for Java is an API for integrating with EOSIO-based blockchains using the EOSIO RPC API. This project is compatible with server-side Java and with Android 6+.

All product and company names are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Contents

Installation

Prerequisites

  • Java JDK 1.8+ (1.8 source compatibility is targeted)
  • Gradle 4.10.1+
  • For Android, Android 6 (Marshmallow)+

Note: Android 6 (Marshmallow) was selected as the minimum target level due to Keystore security concerns in older versions of Android.

Since EOSIO SDK for Java is not an Android-specific project, we recommend using IntelliJ if you are going to work on it. You can use Android Studio but be aware that some of the menu options under Build like Rebuild Project and Clean Project will not work correctly. You may still compile within Android Studio using Make Project under the Build menu, or by using Gradle from the command line.

Instructions

To use EOSIO SDK for Java in your app, add the following modules to your build.gradle:

implementation 'one.block:eosiojava:1.0.0'
implementation 'one.block:eosiojavasoftkeysignatureprovider:1.0.0'
implementation 'one.block:eosiojavaandroidabieosserializationprovider:1.0.0'
implementation 'one.block:eosio-java-rpc-provider:1.0.0'

If you are using EOSIO SDK for Java, or any library that depends on it, in an Android application, you must also add the following to your application's build.gradle file in the android section:

// Needed to get bitcoin-j to produce a valid apk for android.
packagingOptions {
    exclude 'lib/x86_64/darwin/libscrypt.dylib'
    exclude 'lib/x86_64/freebsd/libscrypt.so'
    exclude 'lib/x86_64/linux/libscrypt.so'
}

The build.gradle files for the project currently include configurations for publishing the project to Artifactory and Bintray. These should be removed if you are not planning to use Artifactory and Bintray or you will encounter build errors. To do so, make the changes marked by comments throughout the files.

Then refresh your gradle project. Then you're all set for the Basic Usage example!

Helpful Utilities

One of the most complicated and time consuming tasks about encryption can be figuring out how to transform keys into a format that works on the target blockchain. This library includes two utilities that make that process painless. The EOSFormatter and PEMProcessor classes include methods that allow you to convert a PEM or DER encoded public or private key to and from the standard EOS formats. The PEMProcessor wraps a key and gives you the ability to extract the type, the DER format, the algorithm used to generate the key, and to perform a checksum validation. The EOSFormatter utility converts keys between DER or PEM and the EOS format and formats signatures and transactions into an EOS compliant format as well. There is an abundance of documentation on the Internet about converting keys and signatures to a DER encoded or PEM (Privacy Enhanced Mail) format (See PEM and DER). If you can get your key into one of these formats we provide a simple transition to the EOS format.

Basic Usage

Transactions are instantiated via a TransactionSession() which must be configured with a number of providers and a TransactionProcessor(), which manipulates and performs actions on a Transaction, prior to use. The code below shows a very barebones flow. Error handling has been omitted for clarity but should be handled in normal usage. (See Provider Interface Architecture below for more information about providers.)

Some parameters for transaction processing can be altered by the use of the TransactionConfig. These are useLastIrreversible, blocksBehind and expiresSeconds. TransactionConfig defaults to useLastIrreversible equal to true, blocksBehind to 3 and expiresSeconds to 300. When useLastIrreversible is true, blocksBehind is ignored and TransactionProcessor uses the last irreversible block and expiresSeconds to calculate TAPOS. Otherwise, TransactionProcessor uses the current head block minus the number specified in blocksBehind and expiresSeconds for TAPOS. TransactionConfig defaults to useLastIrreversible to lessen the chances of transactions micro-forking under certain conditions.

IRPCProvider rpcProvider = new EosioJavaRpcProviderImpl("https://baseurl.com/v1/");
ISerializationProvider serializationProvider = new AbiEosSerializationProviderImpl();
IABIProvider abiProvider = new ABIProviderImpl(rpcProvider, serializationProvider);
ISignatureProvider signatureProvider = new SoftKeySignatureProviderImpl();

signatureProvider.importKey(privateKeyK1EOS);
// or...
signatureProvider.importKey(privateKeyR1EOS);

TransactionSession session = new TransactionSession(
        serializationProvider,
        rpcProvider,
        abiProvider,
        signatureProvider
);

TransactionProcessor processor = session.getTransactionProcessor();

// Now the TransactionConfig can be altered, if desired
TransactionConfig transactionConfig = processor.getTransactionConfig();

// Use blocksBehind (default 3) the current head block to calculate TAPOS
transactionConfig.setUseLastIrreversible(false);
// Set the expiration time of transactions 600 seconds later than the timestamp
// of the block used to calculate TAPOS
transactionConfig.setExpiresSeconds(600);

// Update the TransactionProcessor with the config changes
processor.setTransactionConfig(transactionConfig);

String jsonData = "{\n" +
        "\"from\": \"person1\",\n" +
        "\"to\": \"person2\",\n" +
        "\"quantity\": \"10.0000 EOS\",\n" +
        "\"memo\" : \"Something\"\n" +
        "}";

List<Authorization> authorizations = new ArrayList<>();
authorizations.add(new Authorization("myaccount", "active"));
List<Action> actions = new ArrayList<>();
actions.add(new Action("eosio.token", "transfer", authorizations, jsonData));

processor.prepare(actions);

SendTransactionResponse sendTransactionResponse = processor.signAndBroadcast();

// Starting with EOSIO 2.1 actions can have return values associated with them.
// If the actions have return values they can be accessed from the response.
ArrayList<Object> actionReturnValues = sendTransactionResponse.getActionValues();

// Or
try {
    Double actionReturnValue = response.getActionValueAtIndex(index, Double.class);
} catch (IndexOutOfBoundsException outOfBoundsError) {
    // Handle out of bounds error
} catch (ClassCastException castError) {
    // Handle class casting error
}

Android Example App

If you'd like to see EOSIO SDK for Java in action, check out our open source Android Example App--a working application that fetches an account's token balance and pushes a transfer action.

Provider Interface Architecture

The core EOSIO SDK for Java library uses a provider-interface-driven architecture to provide maximum flexibility in a variety of environments and use cases. TransactionSession and TransactionProcessor leverage those providers to prepare and process transactions. EOSIO SDK for Java exposes four interfaces. You, the developer, get to choose which conforming implementations to use.

Signature Provider Protocol

The Signature Provider abstraction is arguably the most useful of all of the providers. It is responsible for a) finding out what keys are available for signing and b) requesting and obtaining transaction signatures with a subset of the available keys.

By simply switching out the signature provider on a transaction, signature requests can be routed any number of ways. Need a signature from keys in the platform's Keystore or hardware backed security module such as Titan M? Configure the TransactionSession with a conforming signature provider that exposes that functionality, such as the Android Keystore Signature Provider. Need signatures from a wallet app on the user's device? A signature provider can do that too!

EOSIO SDK for Java does not include a signature provider implementation; one must be installed separately.

*Softkey Signature Provider stores keys in memory and is therefore not secure. It should only be used for development purposes. In production, we strongly recommend using a signature provider that interfaces with a secure vault, authenticator or wallet.

RPC Provider Protocol

The RPC Provider is responsible for all RPC calls to nodeos, as well as general network handling (offline detection, retry logic, etc.)

EOSIO SDK for Java does not include an RPC provider implementation; one must be installed separately.

*Alternate RPC providers can be used assuming they conform to the minimal RPC Provider Interface. The core EOSIO SDK for Java library depends only on the five RPC endpoints set forth in that Interface. Other endpoints, however, are planned to be exposed in the default RPC provider.

Serialization Provider Protocol

The Serialization Provider is responsible for ABI-driven transaction and action serialization and deserialization between JSON and binary data representations. These implementations often contain platform-sensitive C++ code and larger dependencies. For those reasons, EOSIO SDK for Java does not include a serialization provider implementation; one must be installed separately.

ABI Provider Protocol

The ABI Provider is responsible for fetching and caching ABIs for use during serialization and deserialization. One must be explicitly set on the TransactionSession with the other providers. EOSIO SDK for Java provides a default ABIProviderImpl that can be used. (The default implementation suffices for most use cases.)

Design Documents

For more details about the complete workflow of EOSIO SDK for Java, see EOSIO SDK for Java - Complete workflow. An overview of the error model used in this library can be found in the EOSIO SDK for Java - Error Model.

Releases

  • 11/05/2020 - Version 1.0.0 - Support for EOSIO 3.0 functionality, including action return values and KV tables. Confirmed implementation works on both Android and server-side Java. Updates documentation and examples to use new provider libraries and library versions.
  • 10/22/2020 - Version 0.1.5 - Adds support for GetBlockInfo which replaces GetBlock in IRPCProvider as the preferred way to calculate TAPOS for transactions. GetBlock is still available. Removes PushTransaction from IRPCProvider in favor of SendTransaction. PushTransaction is still available.
  • 10/9/2020 - Version 0.1.3 - Adds support for send_transaction endpoint, return values and KV tables.
  • 2/25/2020 - Version 0.1.2 - Uses JDK11 to build and targets 1.8 for source and target compatibility.
  • 2/21/2020 - Version 0.1.1 - Fixes a transaction expiration error.

Want to help?

Interested in contributing? That's awesome! Here are some Contribution Guidelines and the Code of Conduct.

We're always looking for ways to improve EOSIO SDK for Java. Check out our #enhancement Issues for ways you can pitch in.

License

MIT

Important

See LICENSE for copyright and license terms. Block.one makes its contribution on a voluntary basis as a member of the EOSIO community and is not responsible for ensuring the overall performance of the software or any related applications. We make no representation, warranty, guarantee or undertaking in respect of the software or any related documentation, whether expressed or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall we be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or documentation or the use or other dealings in the software or documentation. Any test results or performance figures are indicative and will not reflect performance under all conditions. Any reference to any third party or third-party product, service or other resource is not an endorsement or recommendation by Block.one. We are not responsible, and disclaim any and all responsibility and liability, for your use of or reliance on any of these resources. Third-party resources may be updated, changed or terminated at any time, so the information here may be out of date or inaccurate. Any person using or offering this software in connection with providing software, goods or services to third parties shall advise such third parties of these license terms, disclaimers and exclusions of liability. Block.one, EOSIO, EOSIO Labs, EOS, the heptahedron and associated logos are trademarks of Block.one.

Wallets and related components are complex software that require the highest levels of security. If incorrectly built or used, they may compromise users’ private keys and digital assets. Wallet applications and related components should undergo thorough security evaluations before being used. Only experienced developers should work with this software.

More Repositories

1

eos

An open source smart contract platform
C++
11,274
star
2

Documentation

EOSIO Documents
2,084
star
3

eosjs

General purpose library for the EOSIO blockchain.
TypeScript
1,436
star
4

eosio.cdt

EOSIO.CDT (Contract Development Toolkit) is a suite of tools used to build EOSIO contracts
C++
511
star
5

eosio.contracts

Smart contracts that provide some of the basic functions of the EOSIO blockchain
C++
323
star
6

demux-js

💫 Deterministic event-sourced state and side effect handling for blockchain applications
TypeScript
306
star
7

eosjs-ecc

Elliptic curve cryptography functions: Private Key, Public Key, Signature, AES, Encryption, Decryption
JavaScript
283
star
8

eos-token-distribution

Shell
196
star
9

eos-vm

A Low-Latency, High Performance and Extensible WebAssembly Backend Library
C++
193
star
10

eosjs-api

Application programming interface to EOS blockchain nodes.
JavaScript
178
star
11

eosio-card-game-repo

The Elemental Battles Tutorial is divided into easy to follow lessons that take you through the process of creating your own fully-functional blockchain-based dApp.
158
star
12

eosio-web-ide

eosio-web-ide
TypeScript
151
star
13

eosio-project-boilerplate-simple

This repository demonstrates the eosio platform running a blockchain as a local single node test net with a simple DApp, NoteChain.
Shell
141
star
14

universal-authenticator-library

A library for allowing apps to easily use different auth providers.
TypeScript
127
star
15

eosio-explorer

An application providing Web GUI to communicate with EOSIO blockchain in a local development environment.
JavaScript
115
star
16

eosio-project-demux-example

Simple Blog DApp built with Demux and React for the EOSIO Blockchain
JavaScript
89
star
17

eosjs-keygen

Javascript keys generator for EOS
JavaScript
72
star
18

history-tools

EOSIO History Tools
C++
65
star
19

eosio-reference-ios-authenticator-app

iOS reference app demonstrating inter-application transaction signing for EOSIO blockchain apps
Swift
65
star
20

eosio-swift

EOSIO SDK for Swift - API for integrating with EOSIO-based blockchains
C
61
star
21

patroneos

RPC Checkpoint for EOS nodes
Go
47
star
22

ricardian-template-toolkit

Renderer for the Ricardian Contract specification
TypeScript
41
star
23

spec-repo

EOSIO Specifications Repository
40
star
24

demux-js-eos

Demux-js Action Reader implementations for EOSIO blockchains
TypeScript
38
star
25

fc

C++
38
star
26

eosio-webauthn-example-app

Example web app demonstrating EOSIO signing via WebAuthn
TypeScript
38
star
27

welcome

Documentation that covers EOSIO Overview, Getting Started and Protocol documents
C++
38
star
28

abieos

Binary <> JSON conversion using ABIs. Compatible with languages which can interface to C
C++
34
star
29

eosio-java-android-example-app

Application demonstrating integration with EOSIO-based blockchains using EOSIO SDK for Java
Java
32
star
30

eosio-swift-ios-example-app

Application demonstrating integration with EOSIO-based blockchains using EOSIO SDK for Swift
Swift
30
star
31

eosjs-json

Information about the EOS blockchain in the JSON file format.
JavaScript
28
star
32

eosio-reference-chrome-extension-authenticator-app

Chrome extension reference app demonstrating how users could sign transactions using various EOSIO Labs tools
TypeScript
25
star
33

ual-token-pocket

authenticator meant to be used with Token Pocket and the Universal Authenticator Library
TypeScript
24
star
34

ricardian-spec

Specification defining valid Ricardian contracts
23
star
35

ual-reactjs-renderer

This library provides a React renderer around the Universal Authenticator Library
JavaScript
23
star
36

tropical-example-web-app

An example for developers showing an application built on EOSIO combining UAL, Manifest Spec, and Ricardian Contracts
JavaScript
22
star
37

eosio.exchange

C++
21
star
38

eosjs-secp256k1

Compiles c++ secp256k1 pedersen commitments, borromean ring signatures, and ZK range proofs into JavaScript.
JavaScript
17
star
39

hackathon-howto-guide

Getting started guide for EOS Global Hackathon series
16
star
40

musl

Mirror of git://git.musl-libc.org/musl
C
14
star
41

eosio-toppings

A monorepo with tools working on top of nodeos
TSQL
14
star
42

ual-scatter

authenticator meant to be used with Scatter and Universal Authenticator Library
TypeScript
14
star
43

ual-authenticator-walkthrough

tutorial walking through the steps required to create a new authenticator for the Universal Authenticator Library
JavaScript
13
star
44

EEPs

EOSIO Enhancement Proposals
13
star
45

eosio-swift-vault

Utility library for managing keys and signing with Apple's Keychain and Secure Enclave
Swift
12
star
46

eosio.assert

A security feature to reduce the need for users to trust blockchain apps when a user signs a transaction for a trusted blockchain network with a trusted wallet application
C++
12
star
47

eosio-java-softkey-signature-provider

Example pluggable signature provider for EOSIO SDK for Java for signing transactions using in-memory keys
Java
12
star
48

eosio.forum

C++
12
star
49

eosio-swift-ecc

Swift utilities for working with keys, cryptographic signatures, encryption/decryption, etc.
Swift
11
star
50

key-value-example-app

An example app for using the key value database feature new to 2.1 of EOSIO.
TypeScript
11
star
51

eosio-java-android-abieos-serialization-provider

Pluggable serialization provider for EOSIO SDK for Java using ABIEOS
Java
11
star
52

eosio-authentication-transport-protocol-spec

EOSIO authentication transport protocol specification for consistent request-response lifecycle
10
star
53

ual-plainjs-renderer

library providers a Plain JS renderer around the Universal Authenticator Library
TypeScript
10
star
54

eosio-wasm-spec-tests

Repo for holding the generated wasm spec tests, as well as the generator
C++
10
star
55

demux-js-postgres

Demux-js Action Handler implementation for Postgres databases
TypeScript
10
star
56

eosjs-ledger-signature-provider

EOSJS Ledger Signature Provider Interface
TypeScript
10
star
57

demux-cli

CLI tool for starting, developing, and interacting with demux-js projects.
JavaScript
10
star
58

mojey

Swift
9
star
59

tutorials

Tutorials, examples and how-tos for EOS.IO
9
star
60

eosio.system

Reference system contract for an EOSIO based chain
C++
9
star
61

eosio-java-android-rpc-provider

Pluggable RPC provider for EOSIO SDK for Java
Java
9
star
62

manifest-spec

A specification detailing how EOSIO-enabled applications comply with the application manifest requirements of EOSIO-compatible user agents
9
star
63

eosio-android-keystore-signature-provider

Pluggable signature provider for EOSIO SDK for Java using Android's Keystore
Kotlin
9
star
64

vt-blockchain-bootcamp-starter

JavaScript
8
star
65

homebrew-eosio

homebrew tap for EOSIO
Shell
8
star
66

ual-eosio-reference-authenticator

Authenticator meant for use with EOSIO Reference Authenticator Apps and the Universal Authenticator Library
TypeScript
7
star
67

eosio.helm

Helm charts for EOSIO.
Shell
6
star
68

return-values-example-app

An example app for using the action return value feature new to 2.1 of EOSIO.
Shell
6
star
69

training-EED101

C++
6
star
70

eosio-swift-reference-ios-authenticator-signature-provider

A pluggable signature provider for EOSIO SDK for Swift for signing transactions with EOSIO Reference iOS Authenticator App
Swift
6
star
71

test-state-history

JavaScript
5
star
72

eosio-java-rpc-provider

Pluggable RPC provider for EOSIO SDK for Java
Java
5
star
73

eosio-java-abieos-serialization-provider

Java version of the ABIEOS Serialization Provider
Java
5
star
74

ual-ledger

authenticator meant to be used with Ledger and the Universal Authenticator Library
TypeScript
5
star
75

ual-lynx

authenticator meant to be used with Lynx and Universal Authenticator Library
TypeScript
5
star
76

taurus-node

EOSIO-Taurus - The Most Powerful Infrastructure for Decentralized Applications
C++
4
star
77

eosio-swift-abieos-serialization-provider

Pluggable serialization provider for EOSIO SDK for Swift using ABIEOS
C++
4
star
78

eosio.token

Reference contract for an EOSIO based token
C++
4
star
79

eosio-swift-vault-signature-provider

Pluggable signature provider for EOSIO SDK for Swift using Apple's Keychain or Secure Enclave
Swift
4
star
80

history-tools-docs

history-tools migrated docs for dev portal consumption
3
star
81

eosjs-ios-browser-signature-provider-interface

a Signature Provider Interface for communicating with an authenticator from iOS Safari using the EOSIO Authentication Transport Protocol Specification
TypeScript
3
star
82

chain-kv

key-value storage for blockchains
C++
3
star
83

eosio-swift-softkey-signature-provider

Example pluggable signature provider for EOSIO SDK for Swift for signing transactions using in-memory keys
Swift
3
star
84

eosjs-window-message-signature-provider-interface

A Signature Provider Interface for communicating with an authenticator over the Window Messaging API using the EOSIO Authentication Transport Protocol Spec.
TypeScript
3
star
85

eosjs-signature-provider-interface

An abstract class that implements the EOSJS SignatureProvider interface, and provides helper methods for interacting with an authenticator using the EOSIO Authentication Transport Protocol Specification.
TypeScript
3
star
86

homebrew-eosio.cdt

homebrew tap for eosio.cdt
Ruby
2
star
87

training-tictactoe

Bootstrap for certain training courses
C++
2
star
88

auto-request-generator

Python
2
star
89

eos-vm-test-wasms

Binary wasms for testing eos-vm.
1
star
90

taurus-zpp-bits

C++
1
star