Skip to content

An interface for interacting with the blockchain wallet operation for android

License

Notifications You must be signed in to change notification settings

JCCDex/jcc-android-base-lib

Repository files navigation

jcc-android-base-lib

An interface for interacting with the blockchain wallet operation for android.

JitPack Build Status codecov PRs Welcome

Usage

Installation

Step 1. Add it in your root build.gradle at the end of repositories:

repositories {
    maven { url 'https://jitpack.io' }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.JCCDex:jcc-android-base-lib:0.1.8'
}

API of JingtumWallet

Interface for interacting with the node sdk of jingtum & jingtum alliance chains. Now supports SWTC & BIZAIN chain.

Create JingtumWallet with Context in your activity.

private JingtumWallet mJingtumWallet;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mJingtumWallet = JingtumWallet.getInstance();
    mJingtumWallet.init(this);
}

createWallet

String chain = JingtumWallet.SWTC_CHAIN;
// String chain = JingtumWallet.BIZAIN_CHAIN;

mJingtumWallet.createWallet(chain, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        // the secret and address is not null if create wallet successfully
    }
});

importSecret

String secret = "";

String chain = JingtumWallet.SWTC_CHAIN;
// String chain = JingtumWallet.BIZAIN_CHAIN;

mJingtumWallet.importSecret(secret, chain, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        // the secret and address is not null if import secret successfully
    }
});

isValidAddress

String address = "";

String chain = JingtumWallet.SWTC_CHAIN;
// String chain = JingtumWallet.BIZAIN_CHAIN;

mJingtumWallet.isValidAddress(address, chain, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        Boolean isValid = jccJson.getBoolean("isValid");
        // the isValid is true if the address is valid
    }
});

isValidSecret

String secret = "";

String chain = JingtumWallet.SWTC_CHAIN;
// String chain = JingtumWallet.BIZAIN_CHAIN;

mJingtumWallet.isValidSecret(secret, chain, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        Boolean isValid = jccJson.getBoolean("isValid");
        // the isValid is true if the secret is valid
    }
});

sign

JSONObject transaction = null;

String secret = "";

String chain = JingtumWallet.SWTC_CHAIN;
// String chain = JingtumWallet.BIZAIN_CHAIN;

mJingtumWallet.sign(transaction, secret, chain, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String signature = jccJson.getString("signature");
        // the signature is not null if sign successfully
    }
});

For more structure of transaction data, see jcc_exchange.

API of EthereumWallet

Interface for interacting with the node sdk of web3. Create EthereumWallet with Context in your activity.

private EthereumWallet mEthereumWallet;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mEthereumWallet = EthereumWallet.getInstance();
    mEthereumWallet.init(this);
    String ethereumNode = "";
    mEthereumWallet.initWeb3Provider(ethereumNode);
}

createWallet

mEthereumWallet.createWallet(new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        String words = jccJson.getString("words");
        // the secret、address and words is not null if create wallet successfully
    }
});

isValidAddress

String address = "";

mEthereumWallet.isValidAddress(address, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        Boolean isValid = jccJson.getBoolean("isValid");
        // the isValid is true if the address is valid
    }
});

isValidSecret

String secret = "";

mEthereumWallet.isValidSecret(secret, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        Boolean isValid = jccJson.getBoolean("isValid");
        // the isValid is true if the secret is valid
    }
});

importSecret

String secret = "";

mEthereumWallet.importSecret(secret, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        // the secret and address is not null if import secret successfully
    }
});

importWords

String words = "";

mEthereumWallet.importWords(words, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        // the secret and address is not null if import words successfully
    }
});

toIban

String address = "";

mEthereumWallet.toIban(address, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String iban = json.getString("iban");
        // the iban is not null if the address is valid
    }
});

fromIban

String iban = "";

mEthereumWallet.fromIban(iban, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String address = json.getString("address");
        // the address is not null if the iban is valid
    }
});

sign

Only support eth except erc20 for now.

JSONObject transaction = new JSONObject();

transaction.put("from", "");
transaction.put("value", "");
transaction.put("to", "");
transaction.put("gas", "");
transaction.put("gasPrice", "");

String secret = "";

mEthereumWallet.sign(transaction, secret, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String rawTransaction = json.getString("rawTransaction");
        // the rawTransaction is not null if sign successfully
    }
});

sendSignedTransaction

String rawTransaction = "";

mEthereumWallet.sendSignedTransaction(rawTransaction, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String hash = json.getString("hash");
        // the hash is not null if the send successfully.
    }
});

gasPrice

mEthereumWallet.gasPrice(new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String gas = json.getString("gasPrice");
        // the gas is not null if request gas price successfully.
    }
});

getBalance

String address = "";

mEthereumWallet.getBalance(address, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String balance = json.getString("balance");
        // the balance is not null if request balance successfully.
    }
});

API of MoacWallet

Interface for interacting with the node sdk of chain3. Create MoacWallet with Context in your activity.

private MoacWallet mMoacWallet;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mMoacWallet = MoacWallet.getInstance();
    mMoacWallet.init(this);
    String moacNode = "";
    mMoacWallet.initChain3Provider(moacNode);
}

createWallet

mMoacWallet.createWallet(new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        String words = jccJson.getString("words");
        // the secret、address and words is not null if create wallet successfully
    }
});

isValidAddress

String address = "";

mMoacWallet.isValidAddress(address, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        Boolean isValid = jccJson.getBoolean("isValid");
        // the isValid is true if the address is valid
    }
});

isValidSecret

String secret = "";

mMoacWallet.isValidSecret(secret, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        Boolean isValid = jccJson.getBoolean("isValid");
        // the isValid is true if the secret is valid
    }
});

importSecret

String secret = "";

mMoacWallet.importSecret(secret, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        // the secret and address is not null if import secret successfully
    }
});

importWords

String words = "";

mMoacWallet.importWords(words, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        // the secret and address is not null if import words successfully
    }
});

toIban

String address = "";

mMoacWallet.toIban(address, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String iban = json.getString("iban");
        // the iban is not null if the address is valid
    }
});

fromIban

String iban = "";

mMoacWallet.fromIban(iban, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String address = json.getString("address");
        // the address is not null if the iban is valid
    }
});

sign

Only support moac except erc20 for now.

JSONObject transaction = new JSONObject();

transaction.put("from", "");
transaction.put("value", "");
transaction.put("to", "");
transaction.put("gas", "");
transaction.put("gasPrice", "");

String secret = "";

mMoacWallet.sign(transaction, secret, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String rawTransaction = json.getString("rawTransaction");
        // the rawTransaction is not null if sign successfully
    }
});

sendSignedTransaction

String rawTransaction = "";

mMoacWallet.sendSignedTransaction(rawTransaction, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String hash = json.getString("hash");
        // the hash is not null if the send successfully.
    }
});

gasPrice

mMoacWallet.gasPrice(new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String gas = json.getString("gasPrice");
        // the gas is not null if request gas price successfully.
    }
});

getBalance

String address = "";

mMoacWallet.getBalance(address, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String balance = json.getString("balance");
        // the balance is not null if request balance successfully.
    }
});

API of EosWallet

Interface for interacting with the node sdk of eos. Create EosWallet with Context in your activity.

private EosWallet mEosWallet;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mEosWallet = EosWallet.getInstance();
    mEosWallet.init(this);
    String eosChainId = "";
    String eosHttpEndpoint = "";
    mEosWallet.initEosProvider(eosChainId, eosHttpEndpoint);
}

importSecret

String secret = "";

mEosWallet.importSecret(secret, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String secret = jccJson.getString("secret");
        String address = jccJson.getString("address");
        // the secret and address is not null if import secret successfully
    }
});

sendTransaction

JSONObject transaction = new JSONObject();

transaction.put("contract", "");
transaction.put("from", "");
transaction.put("value", "");
transaction.put("to", "");
transaction.put("memo", "");

String secret = "";

mEosWallet.sendTransaction(transaction, secret, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String hash = json.getString("hash");
        // the hash is not null if the send successfully.
    }
});

getBalance

String account = "";

mEosWallet.getBalance(account, new JCallback() {
    @Override
    public void completion(JCCJson jccJson) {
        String balance = json.getString("balance");
        // the balance is not null if request balance successfully.
    }
});