Skip to content

Latest commit

 

History

History
102 lines (72 loc) · 2.38 KB

wallet-connect.md

File metadata and controls

102 lines (72 loc) · 2.38 KB

WalletConnect

WalletConnect Swift SDK, implements 1.0.0 websocket based protocol.

Demo video:

How to Use WalletConnect to Trade on Binance DEX

Features:

  • Connect and disconnect
  • Approve / Reject / Kill session
  • Approve and reject ethereum transactions eth_sign / personal_sign / eth_sendTransaction
  • Approve and reject binance dex orders bnb_sign
  • Sign Transactions trust_sign (full documentation here)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

WalletConnect is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'WalletConnect', git: '[email protected]:trustwallet/wallet-connect-swift.git', branch: 'master'

Usage

parse session from scanned QR code:

let string = "wc:..."
guard let session = WCSession.from(string: string) else {
    // invalid session
    return
}
// handle session

configure and handle incoming message:

let interactor = WCInteractor(session: session, meta: clientMeta)
interactor.onSessionRequest = { [weak self] (id, peer) in
    // ask for user consent
}

interactor.onDisconnect = { [weak self] (error) in
    // handle disconnect
}

interactor.onEthSign = { [weak self] (id, params) in
    // handle eth_sign and personal_sign
}

interactor.onEthSendTransaction = { [weak self] (id, transaction) in
    // handle eth_sendTransaction
}

interactor.onBnbSign = { [weak self] (id, order) in
    // handle bnb_sign
}

interactor.onTrustSignTransaction = { [weak self] (id, transaction) in
    // handle trust_signTransaction
}

approve session

interactor.approveSession(accounts: accounts, chainId: chainId).done {
    print("<== approveSession done")
}.cauterize()

approve request

interactor.approveRequest(id: id, result: result.hexString).done {
    print("<== approveRequest done")
}.cauterize()

approve binance dex orders

interactor?.approveBnbOrder(id: id, signed: signed).done({ confirm in
    print("<== approveBnbOrder", confirm)
}).cauterize()

Author

hewigovens

License

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