A Retrofit-like Ethereum client for Android, Java, and Kotlin.
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"- Java / Kotlin: etherspace-java-example
- Android: etherspace-android-example
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>
Please submit issues or pull requests for bugs and features, or contact me at tempo@zaoo.com. Any feedback is welcome!
- Etherspace is built with Kotlin.
- Built on top of web3j.
- Inspired by Retrofit.
- Included libraries:
- web3j: https://github.com/web3j/web3j
- kotlin-unsigned: https://github.com/kotlin-graphics/kotlin-unsigned
- jackson: https://github.com/FasterXML/jackson
- guava: https://github.com/google/guava