Usage
Configure Networking and Pair clients
Make sure that you properly configure Networking and Pair Clients first.
Initialize AppKit Client
In order to initialize a client just call a configure
method from the AppKit instance wrapper
let metadata = AppMetadata(
name: "Example Wallet",
description: "Wallet description",
url: "example.wallet",
icons: ["https://avatars.githubusercontent.com/u/179229932"],
// Used for the Verify: to opt-out verification ignore this parameter
verifyUrl: "verify.walletconnect.com"
)
AppKit.configure(
projectId: PROJECT_ID,
metadata: metadata
)
Don't have a project ID?
Head over to Reown Cloud and create a new project now!
This example will default to using following namespaces.
let methods: Set<String> = ["eth_sendTransaction", "personal_sign", "eth_signTypedData"]
let events: Set<String> = ["chainChanged", "accountsChanged"]
let blockchains: Set<Blockchain> = [Blockchain("eip155:1")!]
let namespaces: [String: ProposalNamespace] = [
"eip155": ProposalNamespace(
chains: blockchains,
methods: methods,
events: events
)
]
let defaultSessionParams = SessionParams(
requiredNamespaces: namespaces,
optionalNamespaces: nil,
sessionProperties: nil
)
If you want to change that you can call configure and define your own session parameters like this.
let metadata = AppMetadata(...)
let sessionParams = SessionParams(...)
AppKit.configure(
projectId: PROJECT_ID,
metadata: metadata,
sessionParams: sessionParams
)
or you can change them later by calling AppKit.set(sessionParams: SessionParams(...))
Provided UI components
Now you can use the AppKitButton
or AppKitNetworkButton
components. These two components reflect the state of the AppKit client,
including the session state, account address and balance, currently selected network, and will automatically update when the state changes.
More can be found in https://github.com/reown-com/reown-swift/blob/develop/Sample/Example/ContentView.swift as part of the Sample app.
Custom UI
If you want to use custom UI you can present the modal by simply calling.
AppKit.present()
It will traverse the view hierarchy and try to present from top most controller. This is meant more towards SwiftUI.
Otherwise you can specify the viewController to present from.
AppKit.present(from: viewController)
Subscribe for AppKit Publishers
The following publishers are available to subscribe:
public var sessionPublisher: AnyPublisher<[Session], Never>
public var sessionSettlePublisher: AnyPublisher<Session, Never>
public var sessionRejectionPublisher: AnyPublisher<(Session.Proposal, Reason), Never>
public var sessionDeletePublisher: AnyPublisher<(String, Reason), Never>
public var sessionResponsePublisher: AnyPublisher<Response, Never>
public var socketConnectionStatusPublisher: AnyPublisher<SocketConnectionStatus, Never>
public var authResponsePublisher: AnyPublisher<(id: RPCID, result: Result<(Session?, [Cacao]), AuthError>), Never>
Sign methods
AppKit is internally using Sign SDK and most of its method are being exposed through AppKit interface.
Where to go from here
Check the AppKit usage in our Sample app that is part of AppKit repository.