Coder Social home page Coder Social logo

wallet-connect-kotlin's Introduction

WalletConnect

WalletConnect Kotlin SDK, implements 1.0.0 websocket based protocol.

Demo

Features

  • Connect and disconnect
  • Approve / Reject / Kill session
  • Approve and reject eth_sign / personal_sign / eth_signTypedData
  • Approve and reject eth_signTransaction / eth_sendTransaction
  • Approve and reject bnb_sign (binance dex orders)
  • session persistent / recovery

Installation

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

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

Add the following line to your app's build.gradle:

dependencies {
    implementation "com.github.TrustWallet:wallet-connect-kotlin:$wc_version"
}

Usage

parse session from scanned QR code:

val peerMeta = WCPeerMeta(name = "App name", url = "https://website.com")
val string = "wc:..."
val session = WCSession.from(string) ?: throw InvalidSessionError // invalid session
// handle session
wcClient.connect(wcSession, peerMeta)

configure and handle incoming message:

val wcClient = WCClient(GsonBuilder(), okHttpClient)

wcClient.onDisconnect = { _, _ -> 
    onDisconnect() 
}

wcClient.onSessionRequest = { _, peer -> 
    // ask for user consent
}

wcClient.onDisconnect = { _, _ -> 
    // handle disconnect
}
wcClient.onFailure = { t -> 
    // handle failure
}
wcClient.onGetAccounts = { id -> 
    // handle get_accounts
}

wcClient.onEthSign = { id, message -> 
    // handle eth_sign, personal_sign, eth_signTypedData
}
wcClient.onEthSignTransaction = { id, transaction -> 
    // handle eth_signTransaction
}
wcClient.onEthSendTransaction = { id, transaction -> 
    // handle eth_sendTransaction
}

wcClient.onSignTransaction = { id, transaction -> 
    // handle bnb_sign
}

approve session

wcClient.approveSession(listOf(address), chainId)

approve request

wcClient.approveRequest(id, signResult) // hex formatted sign

disconnect

if (wcClient.session != null) {
    wcClient.killSession()
} else {
    wcClient.disconnect()
}

License

WalletConnect is available under the MIT license. See the LICENSE file for more info.

wallet-connect-kotlin's People

Contributors

abdrasulov avatar abhriyaroy avatar leoneparise avatar madcake avatar omurovch avatar rafaelekol avatar vcoolish 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.