You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Yenwen Feng edited this page Jun 22, 2018
·
6 revisions
Configuration
Builder
Using EtherSpace.Builder to construct a new instance.
EtherSpaceetherSpace = newEtherSpace.Builder()
.provider("https://rinkeby.infura.io/") // Or your local node
.credentials(newCredentials(YOUR_PRIVATE_KEY_OR_WALLET))
.addCallAdapter(newCompletableFutureCallAdapter<>())
.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 / Async
All method calls in Smart Contract interface are synchronized by default.
Etherspace supports Coroutine (Kotlin), CompletableFuture (Java), RxJava 1 (Java) for asynchronized calls.
Just make sure the corresponding CallAdapter is added on EtherSpace builder.
CoroutineCallAdapter
// KotlininterfaceCoroutineGreeter {
@Throws(IOException::class)
@Call
fungreet(): 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
}
CompletableFutureCallAdapter
// JavainterfaceCompletableFutureCallAdapter {
@CallCompletableFuture<String> greet() throwsIOException;
}
EtherSpaceetherSpace = newEtherSpace.Builder()
.provider("https://rinkeby.infura.io/") // Or your local node
.addCallAdapter(newCompletableFutureCallAdapter<>())
.build();
Greetergreeter = etherSpace.create(SMART_CONTRACT_ADDRESS, CompletableFutureGreeter.class);
System.out.println(greeter.greet().join()); // Should be "Hello World"
RxJavaCallAdapter
// JavainterfaceRxJavaGreeter {
@CallObservable<String> greet();
}
EtherSpaceetherSpace = newEtherSpace.Builder()
.provider("https://rinkeby.infura.io/") // Or your local node
.addCallAdapter(newRxJavaCallAdapter<>())
.build();
Greetergreeter = etherSpace.create(SMART_CONTRACT_ADDRESS, RxJavaGreeter.class);
greeter.greet().subscribe(System.out::println); // Should be "Hello World"
Multi-threads
Because of nonce, transactions need to be submitted in order. After the transactions submitted, transaction receipts can be requested asynchronously.