Skip to main content
Version: 2.0 beta

Swift Client (iOS)

Swift implementation of WalletConnect v.2 protocol for native iOS applications.

caution

Note: The Swift client is in Beta and should only be used for testing.

Requirements

  • iOS 13
  • XCode 13
  • Swift 5

Usage

Instantiate Client

You usually want to have a single instance of a client in you app.

let metadata = AppMetadata(name: String?,
description: String?,
url: String?,
icons: [String]?)
let client = WalletConnectClient(metadata: AppMetadata,
projectId: String,
isController: Bool,
relayHost: String)

Pair Clients

Pair client with a uri generated by the dapp.

let uri = "wc:..."
try! client.pair(uri: uri)

Approve Session

Sessions are always proposed by the Proposer client so Responder client needs either reject or approve a session proposal.

class ClientDelegate: WalletConnectClientDelegate {
...
func didReceive(sessionProposal: SessionProposal) {
client.approve(proposal: proposal, accounts: [String]) { result in ... }
...

or

func didReceive(sessionProposal: SessionProposal) {
client.reject(proposal: proposal, reason: Reason)
}

Handle Delegate methods

func didReceive(sessionProposal: SessionProposal) {
// handle session proposal
}
func didReceive(sessionRequest: SessionRequest) {
// handle session request
}

JSON-RPC Payloads

Receive

You can parse JSON-RPC Requests received from "Requester" in didReceive(sessionRequest: SessionRequest) delegate function.

Request parameters can be type casted based on request method as below:

let params = try! sessionRequest.request.params.get([EthSendTransaction].self)
Respond
let jsonrpcResponse = JSONRPCResponse<AnyCodable>(id: request.id, result: AnyCodable(responseParams))
client.respond(topic: sessionRequest.topic, response: .response(jsonrpcResponse))

Project ID

For the Project ID look at Project ID.