Skip to content

This repository hosts the SDK for the Loopring Protocol on Android.

License

Notifications You must be signed in to change notification settings

dolomite-exchange/loopr-android-sdk

Repository files navigation

loopr-android-sdk

This repository is used as a library for loopr-android, the official Loopring Wallet for Android.

It contains the necessary APIs and libraries to interact with all of the network-based features for the application. Developers are encouraged to add features, make changes, and use this library as a dependency for other Android Loopr Wallets.

This library uses Kotlin's Coroutines to make asynchronous requests. For more information on Kotlin's Coroutines, see here.

Adding the Library

To add this library as a dependency to your project via Gradle, add the following Maven URL to your project-level build.gradle file:

allprojects {
    repositories {
        maven {
            url  "https://jcenter.bintray.com"
        }
    }
}

Then, add the following dependency to your app-level build.gradle file:

implementation 'org.loopring.android:loopr-android-sdk:0.9.x'

Using the ETH Wrapper

Sending ETH is really simple. BigIntegers are used, so no decimals are ever needed. Instead the number should be formatted as follows:

  • amount = amountAsInteger * 10^(decimalPlaces)
  • Meaning, the amount is calculated using the decimal value (as seen in the UI) times the 10^(18; number of decimal places that ETH has)
fun sendEther(
        web3j: Web3j,
        amount: BigDecimal, 
        destAddress: String, 
        credentials: Credentials,
        gasPrice: BigInteger,
        gasLimit: BigInteger
) = runBlocking {
    EthService.getInstance(web3j)
        .sendEth(amount, destAddress, credentials, gasPrice, gasLimit)
        .await()
}

Using the ERC-20 Token Wrapper

Sending an ERC-20 token is also easy, with the help of the wrapper class. BigIntegers are used, so no decimals are ever needed. Instead the number should be formatted as follows:

  • tokenAmount = tokenAmountAsDecimal * 10^(decimalPlaces)
  • Meaning, the tokenAmount is calculated using the integer value (as seen in the UI) times the 10^(number of decimal places the token has)
fun sendToken(
        contractAddress: String,
        web3j: Web3j,
        credentials: Credentials,
        gasPrice: BigInteger,
        gasLimit: BigInteger,
        binary: String,
        receiverAddress: String,
        tokenAmount: BigInteger
) = runBlocking {
    Erc20Wrapper.getInstance(contractAddress, web3j, credentials, gasPrice, gasLimit, binary)
            .transfer(receiverAddress, tokenAmount)
            .await()
}

Setting up the Etherscan and Ethplorer APIs

To use the Etherscan API, you need to set the API key. To do so, set the apiKey variable, as seen below.

Notice that the Ethplorer API key is optional as of right now, since they have a free tier.

fun setupKey() {
    EtherscanService.apiKey = "your-api-key"
    EthplorerService.apiKey = "your-api-key" // Optional, since you can use a free key
}

Using the Etherscan and Ethplorer APIs

Using the API is as simple as using Retrofit, which has been orchestrated work to with the respective APIs.

// Assume that [apiKey] was already set!!
fun getAddressHistory(address: String) = runBlocking {
    EthplorerService.getService().getAddressHistory(address).await()
}
 // Assume that [apiKey] was already set!!
fun getTransactions(address: String) = runBlocking {
    EtherscanService.getService().getTransactions(address).await()
}

Thanks and Credits

License

Copyright (C) 2018 Dolomite

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>. 

About

This repository hosts the SDK for the Loopring Protocol on Android.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published