ScatterAndroid simulates Scatter plugin for EOS blockchain in WebView, and allows client apps to:
- Retrieve account
- Sign transactions
- Sign arbitrary messages
You can download a jar from GitHub's releases page.
Or use Gradle:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.mariabeyrak:ScatterAndroid:1.0.0'
}
Create ScatterClient
object, which implements actions, which you wish to handle:
private ScatterClient scatterClient = new ScatterClient() {
@Override
public void getAccount(AccountReceived onAccountReceived) {
/*some code*/
}
/*other actions*/
};
Create Scatter
object, where webView
- is your WebView:
Scatter scatterImplementation = new Scatter(webView, scatterClient);
Don`t forget to enable Javascript:
webView.getSettings().setJavaScriptEnabled(true);
Clean all after your activity/fragment destroys:
scatterImplementation.removeInterface();
@Override
public void getAccount(AccountReceived onAccountReceived) {
onAccountReceived.onAccountReceivedSuccessCallback(accountName);
}
@Override
public void completeMsgTransaction(MsgTransactionRequestParams params, MsgTransactionCompleted onMsgTransactionCompleted) {
//generate signature
Signature signature = signTransactionRaw(Hex.decode(params.getData()), privateKey).getSignature();
onMsgTransactionCompleted.onMsgTransactionCompletedSuccessCallback(signature.toString());
}
@Override
public void completeTransaction(TransactionRequestParams transactionRequestParams, TransactionCompleted onTransactionCompleted) {
//try to make transaction
Transaction transaction = makeTransaction(transactionRequestParams, privateKey);
String[] signatures = transaction.getSignatures();
onTransactionCompleted.onTransactionCompletedSuccessCallback(signatures);
}
onTransactionCompleted.onTransactionCompletedErrorCallback(new ResponseCodeInfo(ResponseType.UNKNOWN_ERROR, ResponseCode.UNKNOWN_ERROR), "Error");