-
Notifications
You must be signed in to change notification settings - Fork 2
Configuration
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"
An Options
can be appended to the parameter list in Smart Contract methods.
Properties in Options
will override predefined settings in runtime.
public interface Greeter {
@Call
String greet() throws IOException;
}
EtherSpace etherSpace = new EtherSpace.Builder()
.provider("https://rinkeby.infura.io/") // Or your local node
.build();
Greeter greeter = etherSpace.create(SMART_CONTRACT_ADDRESS, Greeter.class);
Options options = new Options(BigInteger.ZERO, BigInteger.valueOf(8_000_000), BigInteger.valueOf(22_000_000_000L), new Credentials(YOUR_PRIVATE_KEY_OR_WALLET));
TransactionReceipt receipt = greeter.greeter("Hello World", options);
Adding a @cc.etherspace.Gas
annotation to SmartContract interface or method to override the default gas settings.
@Gas(gas = "8000000", gasPrice = "22000000000")
public interface Greeter {
@Send
@Gas(gas = "8000000", gasPrice = "22000000000")
TransactionReceipt greeter(String greeting) throws IOException;
}