Git Product home page Git Product logo

web3kotlin's Introduction

Web3Kotlin

Web3Kotlin is an Android toolbelt for interaction with the Ethereum network.

language jitpack jitpack

For more specific usage, please refer to the demo

JitPack.io

I strongly recommend https://jitpack.io

repositories {
    ...
    maven { url 'https://jitpack.io' }
}
dependencies {
    implementation 'com.github.smithSophiav:Web3Kotlin:1.0.1'
}
Setup Web3Kotlin
val onCompleted = {result : Boolean ->
    /*Do something*/
}
if (web3?.isWeb3LoadFinished == false) {
    web3?.setup(true,onCompleted)
} else  {
    /*Do something*/
}
Generate Account
val onCompleted = {state : Boolean,address:String, mnemonic:String, privateKey:String, keystore:String,error: String ->
      this.runOnUiThread {
        if (state) {
            val text =
            "address: " + address + "\n\n" +
            "mnemonic: " + mnemonic + "\n\n" +
            "privateKey: " + privateKey + "\n\n" +
            "keystore: " + keystore
            walletDetail?.setText(text)
        } else {
            walletDetail?.setText(error)
        }
      }
}
walletDetail?.setText("generate Accounting.......")
web3?.generateAccount(password,onCompleted = onCompleted)
Import Account From Keystore
val onCompleted = {state : Boolean, address: String,privateKey: String,error: String ->
    this.runOnUiThread {
        if (state) {
            val text =
                "address: " + address + "\n\n" +
                "privateKey: " + privateKey
            walletDetailEditText?.setText(text)
        } else {
            walletDetailEditText?.setText(error)
        }
    }
}
walletDetailEditText?.setText("Import Accounting.......")
web3?.importAccountFromKeystore(password,keystore,onCompleted = onCompleted)
Import Account From PrivateKey
val onCompleted = {state : Boolean, address: String,keystore: String,error: String ->
    this.runOnUiThread {
        if (state) {
            val text =
                "address: " + address + "\n\n" +
                "keystore: " + keystore
            walletDetailEditText?.setText(text)
        } else {
            walletDetailEditText?.setText(error)
        }
    }
}
walletDetailEditText?.setText("Import Accounting.......")
web3?.importAccountFromPrivateKey(privateKey,password,onCompleted = onCompleted)
Import Account From Mnemonic
val onCompleted = {state : Boolean, address: String,privateKey: String,keystore: String,error: String ->
    this.runOnUiThread {
        if (state) {
            val text =
                "address: " + address + "\n\n" +
                "privateKey: " + privateKey + "\n\n" +
                "keystore: " + keystore
            walletDetailEditText?.setText(text)
        } else {
            walletDetailEditText?.setText(error)
        }
    }
}
walletDetailEditText?.setText("Import Accounting.......")
web3?.importAccountFromMnemonic(mnemonic,password,onCompleted = onCompleted)
Send ETH
val onCompleted = {state : Boolean, txid: String,error:String ->
    this.runOnUiThread {
        if (state){
            hashValue?.text = txid
        } else {
            hashValue?.text = error
        }
    }
}
web3?.ethTransfer(toAddress,amount,privateKey,onCompleted = onCompleted)
Send ERC20Token
val onCompleted = {state : Boolean, txid: String,error:String ->
    this.runOnUiThread {
        if (state){
            hashValue?.text = txid
        } else {
            hashValue?.text = error
        }
    }
}
web3?.erc20TokenTransfer(
    amount,
    privateKey,
    toAddress,
    decimal= 6.0,
    providerUrl = ETHMainNet,
    erc20ContractAddress = erc20TokenAddress,
    onCompleted = onCompleted)

For more specific usage, please refer to the demo

License

Web3Kotlin is released under the MIT license. See LICENSE for details.

web3kotlin's People

Contributors

smithsophiav avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.