Swift implementation of WalletConnect v.2 protocol for native iOS applications.
- iOS 13
- XCode 13
- Swift 5
- In order to build API documentation in XCode go to Product -> Build Documentation
- Getting started with wallet integration
- Beginner guide to WalletConnect v2.0 for iOS Developers
- Protocol Documentation
- Glossary
Responder client is usually a wallet.
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,
relayHost: String)
After instantiation of a client set its delegate.
Pair client with a uri generated by the proposer
client.
let uri = "wc:..."
try! client.pair(uri: uri)
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: Session.Proposal) {
client.approve(proposal: proposal, accounts: [String])
}
...
or
func didReceive(sessionProposal: Session.Proposal) {
client.reject(proposal: proposal, reason: Reason)
}
NOTE: addresses provided in accounts
array should follow CAPI10 semantics.
func didReceive(sessionProposal: Session.Proposal) {
// handle session proposal
}
func didReceive(sessionRequest: Request) {
// handle session request
}
You can parse JSON-RPC Requests received from "Requester" in didReceive(sessionRequest: Request)
delegate function.
Request parameters can be type casted based on request method as below:
let params = try! sessionRequest.request.params.get([EthSendTransaction].self)
let jsonrpcResponse = JSONRPCResponse<AnyCodable>(id: request.id, result: AnyCodable(responseParams))
client.respond(topic: sessionRequest.topic, response: .response(jsonrpcResponse))
Add .package(url:_:) to your Package.swift:
dependencies: [
.package(url: "https://github.com/WalletConnect/WalletConnectSwiftV2", .branch("main")),
],
open Example/ExampleApp.xcodeproj
Apache 2.0