-
Notifications
You must be signed in to change notification settings - Fork 2
Configuration
Yenwen Feng edited this page Feb 28, 2018
·
6 revisions
Using EtherSpace.Builder
to construct a new instance.
EtherSpace etherSpace = new EtherSpace.Builder()
.provider("https://rinkeby.infura.io/") // Or your local node
.credentials(new Credentials(YOUR_PRIVATE_KEY_OR_WALLET))
.addCallAdapter(new CompletableFutureCallAdapter<>())
.client(OkHttpClient.Builder().build())
.build();
-
provider*:
Ethereum node URL
-
credentials:
Private Key or your wallet file. (format: UTC JSON Keystore File) Can be
null
if you only want to make calls to constant functions. You Can also supply different credentials in Options. -
calladapters:
Etherspace supports different response types through
CallAdapter
. See Sync / AsyncReturn Type CallAdapter kotlinx.coroutines.experimental.Deferred<T>
cc.etherspace.calladapter.CoroutineCallAdapter
java.util.concurrent.CompletableFuture<T>
cc.etherspace.calladapter.CompletableFutureCallAdapter
rx.Observable<T>
cc.etherspace.calladapter.RxCallAdapter
-
client:
An
OkHttpClient
All method calls in Smart Contract interface are synchronized by default.
Etherspace supports Coroutine (Kotlin), CompletableFuture (Java), RxJava (Java) for asynchronized calls.
Just make sure the corresponding CallAdapter
is added on EtherSpace builder.
// Kotlin
interface CoroutineGreeter {
@Throws(IOException::class)
@Call
fun greet(): Deferred<String>
}
val etherSpace = EtherSpace.build {
provider = "https://rinkeby.infura.io/"
callAdapters += CoroutineCallAdapter()
}
greeter = etherSpace.create(SMART_CONTRACT_ADDRESS, CoroutineGreeter::class.java)
runBlocking {
println(greeter.greet().await()) // Should be Hello World
}
// Java
interface CompletableFutureCallAdapter {
@Call
CompletableFuture<String> greet() throws IOException;
}
EtherSpace etherSpace = new EtherSpace.Builder()
.provider("https://rinkeby.infura.io/") // Or your local node
.addCallAdapter(new CompletableFutureCallAdapter<>())
.build();
Greeter greeter = etherSpace.create(SMART_CONTRACT_ADDRESS, CompletableFutureGreeter.class);
System.out.println(greeter.greet().join()); // Should be "Hello World"
// Java
interface RxGreeter {
@Call
Observable<String> greet();
}
EtherSpace etherSpace = new EtherSpace.Builder()
.provider("https://rinkeby.infura.io/") // Or your local node
.addCallAdapter(new RxCallAdapter<>())
.build();
Greeter greeter = etherSpace.create(SMART_CONTRACT_ADDRESS, RxGreeter.class);
greeter.greet().subscribe(System.out::println); // Should be "Hello World"