Easy-to-use Ethereum Geth wrapper for Android
⚠️ This project isn't maintained anymore, this is why it is read-only.
If you are interested to work on it, feel free to contact us at
[email protected], we will be happy to help you.
If you think that smartphone is future of blockchain, Ethdroid is here to help you building amazing decentralized smartphone apps.
This project was born as soon as the Geth community built the first android archive. Our needs was to allow an Android App communicate with an inproc Geth node.
Thanks to our hard work, we've reached our goals and built 3 differents use-cases of decentralized smartphone apps :
Contact us for more informations on our works.
With Ethereum-android it becomes easier to :
Futhermore Rx-java 1 and its extensions simplify control of asynchronous flows and background processes.
This package can be used on Android 22+ and with Geth 1.6.2+.
Ethdroid and Geth stable versions are distribued throught jCenter.
Because Geth project evolves independently of Ethdroid library. That's why you are free to set the latest compatible Geth version as dependency.
repositories {
jCenter()
}
dependencies {
compile 'io.ethmobile:ethdroid:2.0.0-m2'
compile 'org.ethereum:geth:1.6.5'
}
For current develop version of Ethdroid, you can download via :
repositories {
jCenter()
maven { url "https://oss.jfrog.org/artifactory/oss-snapshot-local" }
}
dependencies {
compile 'io.ethmobile:ethdroid:2.0.0-m3-SNAPSHOT'
compile 'org.ethereum:geth:1.6.5'
}
With Ethdroid you can easly connect a smartphone to an Ethereum blockchain.
You can connect to :
Thanks to the Ethdroid.Builder class, you can customize your node.
First of all, to create a Builder you have to provide the directory path where blockchain data files will be saved.
Then, provide the chain configuration, or use the default ones.
Optionally, reference a Key Manager if you have already built it. It's mandatory in order to use account related node functions, but you can reference it later.
Optionally, reference a Go Context to use as default when making calls to node (See golang doc). Default is backgroundContext.
Finally, build to get the node reference and start communication with it.
new EthDroid.Builder(datadir) //Whatever directory path where blockchain files must be saved.
.onMainnet()
.build()
.start();
new EthDroid.Builder(datadir) //Whatever directory path where blockchain files must be saved.
.onTestnet()
.build()
.start();
Private network is a little bit trickier because you have to provide more information.
You can find an example at EthdroidBuilderTest
EthDroid ethdroid = EthDroid.Builder(datadir) //Whatever directory path where blockchain files must be saved.
.withChainConfig(new ChainConfig.Builder(networkID, genesis, bootnode).build())
.build()
.start();
//TODO
//TODO
From the following Solidity smart-contract source code:
contract ContractExample {
event e(bool);
event multipleEvent(bool,bool,bool);
void foo(){
[...]
}
uint bar(int a){
[...]
}
event eventOutputMatrix(int[3][3]){
[...]
}
function functionOutputMatrix() returns(uint8[2][8]){
[...]
}
function functionInputMatrix(uint8[3]){
[...]
}
function functionOutputMultiple() returns(bool,uint8[2][3]){
[...]
}
}
interface ContractExample extends ContractType{
SolidityEvent<SBool> e();
SolidityEvent3<SBool,SBool,SBool> multipleEvent();
SolidityFunction foo();
SolidityFunction bar(SInt.SInt256 a);
@SolidityElement.ReturnParameters({@SArray.Size({3,3})})
SolidityEvent<SArray<SArray<SInt.SInt256>>> eventOutputMatrix();
@SolidityElement.ReturnParameters({@SArray.Size({2,8})})
SolidityFunction<SArray<SArray<SUInt.SUInt8>>> functionOutputMatrix();
SolidityFunction functionInputMatrix(@SArray.Size({3}) SArray<SUInt.SUInt8> a);
@SolidityElement.ReturnParameters({@SArray.Size(),@SArray.Size({2,3})})
SolidityFunction2<SBool,SArray<SArray<SUInt.SUInt8>>> functionOutputMultiple();
}
When an input/output parameter of a function/event is an array, you have to specify its size with the annotation : @SArray.Size.
Its parameter is an array of integers like @SArray.Size{2,3,4} (its equivalent to an array of a size type[2][3][4])
When your function/event returns an array, to specify its length you have to use the annotation @SolidityElement.ReturnParameters({}) which takes an array of @SArray.Size annotations as value.
When your function returns multiple types, you have to specify the related SolidityFunction. For exemple, if your function returns 2 booleans you must use return SolidityFunction2<SBool,SBool>
Table of multiple return type elements and their related wrapper :
Number of Returns | Function | Event | Output |
---|---|---|---|
0 | SolidityFunction | SolidityEvent | SType |
1 | SolidityFunction<T> |
SolidityEvent<T> |
SingleReturn<T> |
2 | SolidityFunction2<T1,T2> |
SolidityEvent2<T1,T2> |
PairReturn<T1,T2> |
3 | SolidityFunction3<T1,T2,T3> |
SolidityEvent3<T1,T2,T3> |
TripleReturn<T1,T2,T3> |
Instanciate the smart-contract available on the blockchain at the given address
//TODO
PairReturn<SBool,SArray<SArray<SUInt.SUInt8>>> result = contract.functionOutputMultiple().call();
SBool resultSBool = result.getElement1();
SArray<SArray<SUInt.SUInt8>> resultMatrix = result.getElement2();
//TODO
From Android app, subscribe to Solidity events in a background process and be notified in main thread to update the view.
contract.e.listen()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(booleanAnswer -> doWhenEventTriggered());
/*
doWhenEventTriggered is a local method called when event is triggered by the deployed smart-contract
booleanAnswer is the parameter returned by the triggered event.
You can directly update your app view
*/
//TODO
//TODO
For IntelliJ 13+ :
For previous versions click here
Ethdroid is released under the MIT License (MIT), see Licence.
Ethdroid depends on libraries with different licenses:
Please respect terms and conditions of each licenses.