Code Monkey home page Code Monkey logo

bitverseconnectkotlin's Introduction

bitverseConnectKotlin

library to use bitverseConnect with Kotlin or Java

添加SDK依赖

将@jitpack添加到gradle文件中

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

添加sdk依赖

https://jitpack.io/#bitbeen/BitverseConnectKotlin查找最新版本号

dependencies {
 implementation 'com.github.bitbeen:BitverseConnectKotlin:1.1.0'
}

使用方式

初始化bitverseConnectApi

val connection = BitverseConnectApi(object :bitverseConnectDelegate{
        override fun didConnect(chainId: Int?, accounts: String?) {
            TODO("连接成功,返回chain id 和钱包地址")
        }

        override fun didDisconnect() {
            TODO("连接断开")
        }

        override fun failedToConnect() {
            TODO("连接失败")
        }

    })

连接钱包

需要配置deeplink,用于Bitverse App处理完事务后,返回当前App

<intent-filter >
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Accepts URIs that begin with "example://gizmos” -->
    <data android:scheme="bitversedapp"
        android:host="wc" />
</intent-filter>

调用连接钱包API

connection.connect(
        context = requireContext(),
        dappName = "Example App",
        dappDescription = "bitverseconnect_android_example",
        dappUrl = "https://example.com",
        icons = listOf("用于bitverse App展示dapp的图片"),
        callbackUrl = "bitversedapp://wallet", // 设置返回当前App的deeplink
    )

签名

SDK 支持 eth sign 、personal sign 和 signTypedData

eth_sign 是危险操作,会导致资金丢失,bitverse Wallet 已经把 eth_sign 封禁

connection.personalSign(
            requireContext(),
            message = "0xff",
            account = "钱包地址"
        ) {resp ->
            // 回调方式位于子线程,务必切换到UI线程进行UI展示
            uiScope.launch {    
                binding.txRespData.text = it.result.toString()
            }
        }

交易

connection.ethSendTransaction(
        requireContext(),
        Transaction(
            from = binding.txAddress.text.toString(),
            to = binding.txAddress.text.toString(),
            nonce = null,
            gasPrice = null,
            gasLimit = null,
            value = "0xff",
            data = "0x",
        )
    ) {
        uiScope.launch {
            binding.txRespData.text = it.result.toString()
        }
    }

typed sign签名

connection.ethSignTypedData(
    requireContext(),
    message = "{\"types\":{\"EIP712Domain\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"version\",\"type\":\"string\"},{\"name\":\"chainId\",\"type\":\"uint256\"},{\"name\":\"verifyingContract\",\"type\":\"address\"}],\"Person\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"wallet\",\"type\":\"address\"}],\"Mail\":[{\"name\":\"from\",\"type\":\"Person\"},{\"name\":\"to\",\"type\":\"Person\"},{\"name\":\"contents\",\"type\":\"string\"}]},\"primaryType\":\"Mail\",\"domain\":{\"name\":\"Ether Mail\",\"version\":\"1\",\"chainId\":1,\"verifyingContract\":\"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC\"},\"message\":{\"from\":{\"name\":\"Cow\",\"wallet\":\"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826\"},\"to\":{\"name\":\"Bob\",\"wallet\":\"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB\"},\"contents\":\"Hello, Bob!\"}}",
    account = it
){
        uiScope.launch {
            binding.txRespData.text = it.result.toString()
        }
    }

bitverseconnectkotlin's People

Stargazers

 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.