Skip to content

mariabeyrak/ScatterAndroid

Repository files navigation

Scatter Android

ScatterAndroid simulates Scatter plugin for EOS blockchain in WebView, and allows client apps to:

  • Retrieve account
  • Sign transactions
  • Sign arbitrary messages

Installation

Step 1: Add library

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'
}

Step 2: Configure

Create ScatterClientobject, 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();

Usage examples

Send EOS account to Scatter

        @Override
        public void getAccount(AccountReceived onAccountReceived) {
            onAccountReceived.onAccountReceivedSuccessCallback(accountName);
        }

Sign arbitrary message

        @Override
        public void completeMsgTransaction(MsgTransactionRequestParams params, MsgTransactionCompleted onMsgTransactionCompleted) {
            //generate signature
            Signature signature = signTransactionRaw(Hex.decode(params.getData()), privateKey).getSignature();
            onMsgTransactionCompleted.onMsgTransactionCompletedSuccessCallback(signature.toString());
        }

Sign transaction

        @Override
        public void completeTransaction(TransactionRequestParams transactionRequestParams, TransactionCompleted onTransactionCompleted) {
            //try to make transaction
            Transaction transaction = makeTransaction(transactionRequestParams, privateKey);
            String[] signatures = transaction.getSignatures();
            onTransactionCompleted.onTransactionCompletedSuccessCallback(signatures);
        }

Send errors to Scatter

onTransactionCompleted.onTransactionCompletedErrorCallback(new ResponseCodeInfo(ResponseType.UNKNOWN_ERROR, ResponseCode.UNKNOWN_ERROR), "Error");

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages