All Projects → trustwallet → wallet-connect-kotlin

trustwallet / wallet-connect-kotlin

Licence: other
No description, website, or topics provided.

Programming Languages

kotlin
9241 projects

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].