• Stars
    star
    328
  • Rank 128,352 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WalletConnect Swift SDK

WalletConnectSwift

Swift SDK implementing WalletConnect 1.x.x protocol for native iOS Dapps and Wallets.

Features

  • Server (wallet side)

    • Create, reconnect, disconnect, and update session
    • Flexible, extendable request handling with Codable support via JSON RPC 2.0
  • Client (native dapp side)

    • Create, reconnect, disconnect, and update session
    • Default implementation of WalletConnect SDK API
      • personal_sign
      • eth_sign
      • eth_signTypedData
      • eth_sendTransaction
      • eth_signTransaction
      • eth_sendRawTransaction
    • Send custom RPC requests with Codable support via JSON RPC 2.0

Example Code

Example code is in a separate repository: https://github.com/WalletConnect/WalletConnectSwift-Example

  • Wallet Example App:
    • Connecting via QR code reader
    • Connecting via deep link ("wc" scheme)
    • Reconnecting after restart
    • Examples of request handlers
  • Dapp Example App:
    • Connecting via QR code reader
    • Connecting via deep link ("wc" scheme)
    • Reconnecting after restart
    • Examples of request handlers

Usage in a Wallet

To start connections, you need to create and retain a Server object to which you provide a delegate:

let server = Server(delegate: self)

The library handles WalletConnect-specific session requests for you - wc_sessionRequest and wc_sessionUpdate.

To register for the important session update events, implement the delegate methods shouldStart, didConnect, didDisconnect and didFailToConnect.

By default, the server cannot handle any other reqeusts - you need to provide your implementation.

You do this by registering request handlers. You have the flexibility to register one handler per request method, or a catch-all request handler.

server.register(handler: PersonalSignHandler(for: self, server: server, wallet: wallet))

Handlers are asked (in order of registration) whether they can handle each request. First handler that returns true from canHandle(request:) method will get the handle(request:) call. All other handlers will be skipped.

In the request handler, check the incoming request's method in canHandle implementation, and handle actual request in the handle(request:) implementation.

func canHandle(request: Request) -> Bool {
   return request.method == "eth_signTransaction"
}

You can send back response for the request through the server using send method:

func handle(request: Request) {
  // do you stuff here ...
  
  // error response - rejected by user
  server.send(.reject(request))

  // or send actual response - assuming the request.id exists, and MyCodableStruct type defined
  try server.send(Response(url: request.url, value: MyCodableStruct(value: "Something"), id: request.id!))
}

For more details, see the ExampleApps/ServerApp

Usage in a Dapp

To start connections, you need to create and keep alive a Client object to which you provide DappInfo and a delegate:

let client = Client(delegate: self, dAppInfo: dAppInfo)

The delegate then will receive calls when connection established, failed, or disconnected.

Upon successful connection, you can invoke various API methods on the Client.

try? client.personal_sign(url: session.url, message: "Hi there!", account: session.walletInfo!.accounts[0]) {
      [weak self] response in
      // handle the response from Wallet here
  }

You can also send a custom request. The request ID required by JSON RPC is generated and handled by the library internally.

try? client.send(Request(url: url, method: "eth_gasPrice")) { [weak self] response in
    // handle the response
}

You can convert the received response result to a Decodable type.

let nonceString = try response.result(as: String.self)

You can also check if the wallet responded with error:

if let error = response.error { // NSError
  // handle error
}

For more details, see the ExampleApps/ClientApp

Logs

Filter the type of logs being printed by changing the log level LogService.level = .info.

Running Example Apps

Please open ExampleApps/ExampleApps.xcodeproj

Installation

Prerequisites

  • iOS 13.0 or macOS 10.14
  • Swift 5

WalletConnectSwift dependencies

  • CryptoSwift - for cryptography operations

Swift Package Manager

In your Package.swift:

dependencies: [
    .package(url: "https://github.com/WalletConnect/WalletConnectSwift.git", .upToNextMinor(from: "1.2.0"))
]

CocoaPods

In your Podfile:

platform :ios, '13.0'
use_frameworks!

target 'MyApp' do
  pod 'WalletConnectSwift'
end

Carthage

In your Cartfile:

github "WalletConnect/WalletConnectSwift"

Run carthage update to build the framework and drag the WalletConnectSwift.framework in your Xcode project.

Acknowledgments

We'd like to thank Trust Wallet team for inspiration in implementing this library.

Contributors

License

MIT License (see the LICENSE file).

More Repositories

1

web3modal

A single Web3 provider solution for all Wallets
TypeScript
4,753
star
2

create-eth-app

Create Ethereum-powered apps with one command
JavaScript
2,746
star
3

walletconnect-monorepo

WalletConnect Monorepo
TypeScript
1,455
star
4

walletconnect-docs

WalletConnect Documentation
CSS
449
star
5

walletconnect-example-dapp

Example Dapp
TypeScript
367
star
6

web-examples

Wallet and dapp examples implementing WalletConnect v2
TypeScript
358
star
7

WalletConnectSwiftV2

WalletConnect Swift SDK v2
Swift
251
star
8

walletconnect-test-wallet

Test Wallet (Web)
TypeScript
186
star
9

web3modal-vanilla-js-example

An example application how to use Web3modal from vanilla JavaScript
JavaScript
169
star
10

WalletConnectKotlinV2

WalletConnect Kotlin SDK v2
Kotlin
168
star
11

kotlin-walletconnect-lib

library to use WalletConnect with Kotlin or Java
Kotlin
156
star
12

a2

An Asynchronous Apple Push Notification (apns2) Client for Rust
Rust
142
star
13

WalletConnectSharp

A C# implementation of the WalletConnect client
C#
134
star
14

walletconnect-website

WalletConnect Website
TypeScript
125
star
15

WalletConnectUnity

An extension of WalletConnectSharp that brings WalletConnect to Unity 🎮
C#
118
star
16

walletconnect-registry

App Registry for WalletConnect Protocol
JavaScript
115
star
17

walletconnect-utils

Javascript Utilities for WalletConnect
TypeScript
113
star
18

WalletConnectFlutterV2

WalletConnect v2 client made in Dart for Flutter.
Dart
103
star
19

react-native-examples

React Native examples implementing WalletConnect v2
TypeScript
75
star
20

py-walletconnect-bridge

WalletConnect Bridge Python Implementation
Python
64
star
21

web3modal-examples

JavaScript
57
star
22

awesome-walletconnect

A curated list of awesome WalletConnect resources, libraries, tools and more
55
star
23

walletconnect-assets

WalletConnect Brand Guidelines
55
star
24

walletconnect-demo-app

Demo React-Native App to Test WalletConnect integration
TypeScript
52
star
25

web3modal-react-native

Web3Modal React-Native SDK
TypeScript
51
star
26

web3modal-swift

Swift
50
star
27

node-walletconnect-bridge

[Deprecated] Moved to walletconnect-monorepo
Shell
48
star
28

web3inbox

TypeScript
46
star
29

EIP6963

A web application showcasing the implementation and usage of EIP-6963 for Multi Injected Provider Discovery
TypeScript
34
star
30

web3modal-checkout

Payment checkout with Web3Modal
TypeScript
33
star
31

Web3ModalFlutter

The Web3Modal for WalletConnect built using Flutter.
Dart
33
star
32

WalletConnectSwift-Example

Example code for WalletConnectSwift library
Swift
32
star
33

walletconnect-specs

WalletConnect Specifications
CSS
27
star
34

cosmos-wallet

Configurable Wallet for Cosmos SDK Chains
TypeScript
26
star
35

blockchain-api

WalletConnect's Blockchain API
Rust
26
star
36

modal-react-native

Simplest and most minimal way to connect your users with WalletConnect
TypeScript
25
star
37

WalletConnectRust

WalletConnect Rust SDK
Rust
23
star
38

create-wc-dapp

create-wc-dapp is an npx starter template that allows you to easily set up a WalletConnect integrated dApp.
TypeScript
23
star
39

firebase-walletconnect-push

WalletConnect Push Notification Firebase Webhook
TypeScript
22
star
40

relay

This repository contains the minimal relay server for WalletConnect v2.0
TypeScript
22
star
41

echo-server

WalletConnect Push Server Implementation
Rust
22
star
42

WalletConnectModalFlutter

The WalletConnectModal for WalletConnect built using Flutter.
Dart
20
star
43

gm-hackers

Get started in minutes with WalletConnect Notify API.
TypeScript
19
star
44

swift-walletconnect-lib

[Deprecated] Please refer to wallet-connect-swift repo
Swift
15
star
45

solib

Solana friendly API
TypeScript
14
star
46

WCIPs

WalletConnect Improvement Proposals
13
star
47

cloud-auth-api

PoC of the GoTrue replacement
HCL
10
star
48

cast-server

Rust
10
star
49

.github

10
star
50

auth-client-js

TypeScript
10
star
51

node-walletconnect-push

[Deprecated] Moved to walletconnect-monorepo
TypeScript
8
star
52

keys-server

Microservice to manage identity keys and invite keys for Chat SDK
Rust
7
star
53

association

WalletConnect Association (Verein) in Zug, Switzerland
6
star
54

CloudSIWE

Files that support Cloud's Ethereum login
HCL
6
star
55

session-keys-demo-contracts

Solidity
6
star
56

modal

WalletConnectModal repository
TypeScript
6
star
57

py-walletconnect-push

Reference Push Server implementation in Python3 for WalletConnect
Python
6
star
58

solana-wallet

TypeScript
5
star
59

Community

A place to store public documents related to our community
5
star
60

hyper-alpn

An ALPN connector for Hyper
Rust
5
star
61

KotlinCodingChallenge

Kotlin
5
star
62

chat-client-js

TypeScript
4
star
63

www-web3modal

Website for Web3Modal
TypeScript
4
star
64

notify-server

notify.walletconnect.com
Rust
4
star
65

actions

WalletConnect GitHub Actions
4
star
66

gm-dapp

dapp publishing example of WalletConnect Push
TypeScript
3
star
67

modal-swift

Swift
3
star
68

rs-common

Rust
3
star
69

gilgamesh

Rust
3
star
70

web3inbox-widget

TypeScript
2
star
71

notify-client-js

TypeScript
2
star
72

rust-http-starter

Starter project for a Rust HTTP server with Axum backed by a Postgres database
HCL
2
star
73

supabase-prometheus-exporter

Shell
2
star
74

terraform-null-label

HCL
2
star
75

verify-server

You either get in or you don't
Smarty
2
star
76

terraform-aws-dns

Terraform module to create a public Route53 zone for a fqdn and generate a wildcard certificate for it.
HCL
2
star
77

walletconnect-legacy

Monorepo for WalletConnect (v1.0) legacy JS packages
TypeScript
2
star
78

erc6492

Universal Etheruem signature verification with ERC-6492
Rust
2
star
79

gorgon

Analytics exporter
Rust
1
star
80

self-host-relay

1
star
81

cerberus

Rust
1
star
82

se-sdk

TypeScript
1
star
83

push-webhook-test-server

Test Server to allow us integ test our push offering
HCL
1
star
84

session-keys-demo

TypeScript
1
star