Skip to content

Repository files navigation

etherspace-java

A Retrofit-like Ethereum client for Android, Java, and Kotlin.

ReleaseBuild Status

Introduction

Etherspace is a type-safe Ethereum client to interact with Ethereum Smart Contract.

For example, to access greeter smart contract from ETHEREUM » Create a digital greeter (Slightly modified because we need a setter):

contractgreeter{/* Define variable greeting of the type string */stringgreeting;/* This runs when the contract is executed */functiongreeter(string_greeting)public{greeting=_greeting;}/* Main function */functiongreet()constantreturns(string){returngreeting;}/* Update greeting */functionnewGreeting(string_greeting)publicreturns(string){greeting=_greeting;returngreeting;}}

By defining a Smart Contract interface in Kotlin / Java: (see: Smart Contract Interface)

// KotlininterfaceGreeter {
@Throws(IOException::class)
@Send
funnewGreeting(greeting:String): TransactionHash
@Throws(IOException::class)
@Call
fungreet(): String
}
// JavapublicinterfaceGreeter {
@SendTransactionHashnewGreeting(Stringgreeting) throwsIOException;
@CallStringgreet() throwsIOException;
}

Etherspace generates an implementation of Greeter interface.

You can than use greeter to interact with Smart Contract on Ethereum!

// Kotlinval etherSpace =EtherSpace.build {
provider ="https://rinkeby.infura.io/"// Or your local node 
credentials =Credentials(YOUR_PRIVATE_KEY_OR_WALLET)
}
var greeter = etherSpace.create(SMART_CONTRACT_ADDRESS, Greeter::class.java)
val hash = greeter.newGreeting("Hello World")
val receipt = hash.requestTransactionReceipt<TransactionReceipt>()
println(greeter.greet()) // Should be "Hello World"
// JavaEtherSpaceetherSpace = newEtherSpace.Builder()
.provider("https://rinkeby.infura.io/") // Or your local node
.credentials(newCredentials(YOUR_PRIVATE_KEY_OR_WALLET))
.build();
Greetergreeter = etherSpace.create(SMART_CONTRACT_ADDRESS, Greeter.class);
TransactionHashhash = greeter.newGreeting("Hello World");
TransactionReceiptreceipt = hash.requestTransactionReceipt();
System.out.println(greeter.greet()); // Should be "Hello World"

Example Apps

Declaring Smart Contract Interfaces

Configuration

Download

Release

  • Gradle

    repositories {
    ...
    maven { url 'https://jitpack.io' } // should be the last entry
    }
    dependencies {
    ...
    // JDK 8
    compile 'cc.etherspace.etherspace-java:etherspace-java:{version}'// Android
    implementation 'cc.etherspace.etherspace-java:etherspace-android:{version}'
    }
  • Maven

    <repositories>
    <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
    </repository>
    </repositories>
    <!-- JDK 8 -->
    <dependency>
    <groupId>cc.etherspace.etherspace-java</groupId>
    <artifactId>etherspace-java</artifactId>
    <version>{version}</version>
    </dependency>
    <!-- Android -->
    <dependency>
    <groupId>cc.etherspace.etherspace-java</groupId>
    <artifactId>etherspace-android</artifactId>
    <version>{version}</version>
    </dependency>

Bug reports & feature requests

Please submit issues or pull requests for bugs and features, or contact me at tempo@zaoo.com. Any feedback is welcome!

Credits

About

A Retrofit-like Ethereum client for Android, Java, and Kotlin.

Topics

Resources

Stars

29 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages