Add FCL Support for WalletConnect 2.0
To improve developer experience and streamline Flow dApp integration with WalletConnect 2.0 wallets, FCL ^1.3.0
introduces support for discovery-service
plugins. These ServicePlugins
allow for injection of client configured services, service methods, and the execution strategies required to interact with them.
FCL dApps can opt-in through use of the fcl-wc package and FCL Plugin Registry.
When using FCL Discovery for authentication, dApps are able to support most FCL-compatible wallets and their users on Flow without any custom integrations or changes needed to the dApp code.
These instructions explain how dApps can also add support for FCL compatible wallets that use the WalletConnect 2.0 protocol.
How does it work?
- The
fc-wc
package is used to initialize a WalletConnect 2.0SignClient
instance, and build adiscovery-service
ServicePlugin
based on dApp specified options. discovery-service
plugins are used to add opt-in wallets and other services to FCL Wallet Discovery (UI/API).- The FCL Plugin Registry offers dApps the ability to add new services, methods, and the execution strategies needed to interact with them.
Requirements
fcl
version >=1.3.0
fcl-wc
version >=1.0.0
Implementation path
1 | Add required packages | Install and import minimum fcl and fcl-wc versions |
2 | Obtain a WalletConnect projectID | Visit WalletConnect Cloud Registry and register for public relay server access and an application projectId |
3 | Initialize WalletConnect SignClient and FclWcServicePlugin | Initialize WalletConnect SignClient and FclWcServicePlugin with configuration options |
4 | Add FclWcServicePlugin to FCL Plugin Registry | Inject FclWcServicePlugin via fcl.pluginRegistry.add(FclWcServicePlugin) |
1. Add required packages
Install the fcl
and fcl-wc
packages:
_10npm install @onflow/fcl@ @onflow/fcl-wc
2. Obtain a WalletConnect projectID
Visit WalletConnect Cloud Registry and register for public relay server access and an application projectId
.
3. Initialize WalletConnect SignClient
and FclWcServicePlugin
In addition to the WalletConnect SignClient
, the init
method of fcl-wc
returns a ServicePlugin
object. This object can be injected using the FCL Plugin Registry to add support for new service methods and their corresponding execution strategies (like WC/RPC
for WalletConnect ).
A discovery-service
ServicePlugin
may also include additional opt-in wallets to offer your users through FCL Wallet Discovery.