Let me preface by reiterating the experimental nature of this repository. Right now the go-ethereum android library appears to be incomplete or at the very least convoluted. Most likely this 'client' will not be able to access all of the functionality that can be on other platforms (for now).
The official link for the new releases is https://geth.ethereum.org/downloads/
Add compile 'org.ethereum:geth:1.6.6'
(Or latest version) to your App level gradle file under dependencies
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
Important : Currently the send 'set string' button will have no functionaity: I have not been able to figure out the smart contract interaction step yet
<Button
android:text="Balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="getAccountBalanceButton"
android:id="@+id/button" />
<Button
android:text="Send Ether"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="sendTransaction"
android:id="@+id/transaction" />
<Button
android:text="SetString"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="smart_contract_interaction_get_string"
android:id="@+id/set_string" />
Create a file under your assets folder (may need to create assets folder) called 'rinkeby_genesis.json'
http://www.mobilefish.com/download/ethereum/rinkeby.json.txt
(You can test with https://jsonlint.com/ JSON Validator)
(Copy Paste these as global variables)
EthereumClient ec;
Context ctx;
TextView textbox;
Node node;
KeyStore keyStore;
NodeConfig conf;
long nonce;
final String TAG = "Transaction info";
textbox = (TextView) findViewById(R.id.textBox);
InputStream is = this.getAssets().open("rinkeby_genesis.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String genesis = new String(buffer, "UTF-8");
conf = Geth.newNodeConfig();
conf.setEthereumGenesis(genesis);
conf.setEthereumNetworkID(4);
node = Geth.newNode(getFilesDir() + "./ethereum", conf); //Folder to store the node
node.start(); // Start the node
NodeInfo info = node.getNodeInfo();
textbox.append("My name: " + info.getName() + "\n");
textbox.append("My address: " + info.getListenerAddress() + "\n");
textbox.append("My protocols: " + info.getProtocols() + "\n\n");
keyStore = new KeyStore(this.getFilesDir() + "/keystore",
Geth.StandardScryptN, Geth.StandardScryptP);
if (keyStore.getAccounts().size() == 0) {
Account acc = keyStore.newAccount("Password");
keyStore.getAccounts().set(0, acc);
acc = keyStore.newAccount("Password");
keyStore.getAccounts().set(1, acc);
}
textbox.append("Sender Address: " + keyStore.getAccounts().get(0).getAddress().getHex().toString() + "\n");
textbox.append("Receiver Address: " + keyStore.getAccounts().get(1).getAddress().getHex().toString() + "\n");
public void getAccountBalanceButton(View view) {
try {
ec = node.getEthereumClient();
System.out.println("Sender: " + ec.getBalanceAt(ctx, keyStore.getAccounts().get(0).getAddress(), -1).toString() + "\n");
System.out.println("Receiver: " + ec.getBalanceAt(ctx,
keyStore.getAccounts().get(1).getAddress(), -1).toString() + "\n");
} catch (Exception e) {
e.printStackTrace();
}
}
a) Go to https://www.rinkeby.io/
public void sendTransaction(View view) {
try {
ec = node.getEthereumClient();
nonce = ec.getPendingNonceAt(ctx, keyStore.getAccounts().get(0).getAddress());
String data_string = "Test Data for Transaction";
byte[] data = data_string.getBytes();
BigInt value = Geth.newBigInt(1000);
BigInt gasLimit = Geth.newBigInt(31500);
BigInt gasPrice = Geth.newBigInt(21001000100001L);
Transaction transaction = Geth.newTransaction(nonce, keyStore.getAccounts().get(1).getAddress(), value, gasLimit, gasPrice, data);
keyStore.timedUnlock(keyStore.getAccounts().get(0), "Password", 100000000);//probably too high of a timeout
transaction = keyStore.signTx(keyStore.getAccounts().get(0), transaction, new BigInt(4));//Network ID
ec.sendTransaction(ctx, transaction);
log_transaction(transaction);
} catch (Exception e) {
e.printStackTrace();
}
}
private void log_transaction(Transaction transaction) {
try {
android.util.Log.i(TAG, "Cost: " + transaction.getCost());
android.util.Log.i(TAG, "GasPrice: " + transaction.getGasPrice());
android.util.Log.i(TAG, "Gas: " + transaction.getGas());
android.util.Log.i(TAG, "Nonce: " + transaction.getNonce());
android.util.Log.i(TAG, "Value: " + transaction.getValue());
android.util.Log.i(TAG, "Sig-Hash Hex: " + transaction.getSigHash().getHex());
android.util.Log.i(TAG, "Hash Hex: " + transaction.getHash().getHex());
android.util.Log.i(TAG, "Data-Length: " + transaction.getData().length);
android.util.Log.i(TAG, "Receiver: " + transaction.getTo().getHex());
android.util.Log.i(TAG, "Sender: " + transaction.getFrom(new BigInt(4)).getHex().toString());//Network ID
} catch (Exception e) {
e.printStackTrace();
}
}
If you understand how to interact with Smart Contracts on the blockchain please answer my question below: