d774f52135
* Added UI infastructure to support chain switching, need to update the session to swap chains * Fixed type of chainId, string -> number * Added helper method to find full chainname ex/ cosmoshub-4 -> cosmons:cosmoshub-4. Added a method updateSignClientChainId to emit a new update with the new namespace for the respected chain switch * Added checks to ensure no dup accounts get added to namespaces during chainswitching from chain A->B->A for ex * Fixed chainId type, eip155 uses number but the other chains use strings, making string the default type for chainId * Update wallets/react-wallet-v2/src/utils/WalletConnectUtil.ts Co-authored-by: Ben Kremer <ben@walletconnect.com> * Switched the way account card components are generated in index page, removed unnecessary helper fx * Fixed the chain changed event by updating the session if the chainId namespace does not currently exist, then emitting the correct chainChanged event on the same session --------- Co-authored-by: Ben Kremer <ben@walletconnect.com> |
||
---|---|---|
.. | ||
public | ||
src | ||
.env.local.example | ||
.eslintrc.json | ||
.gitignore | ||
.prettierrc.json | ||
next-env.d.ts | ||
next.config.js | ||
package.json | ||
README.md | ||
tsconfig.json | ||
yarn.lock |
Wallet Example (React, Typescript, Ethers, NextJS, Cosmos)
This example aims to demonstrate basic and advanced use cases enabled by WalletConnect's Sign SDK.
The wallet implements Sign v1 and v2 side-by-side, to serve as a reference for wallet developers
aiming to support both major versions for backwards compatibility. All files containing code for the legacy
v1 implementation are prefixed with Legacy...
.
Please only use this for reference and development purposes, otherwise you are at risk of losing your funds.
Useful links
🔗 Live wallet app - https://react-wallet.walletconnect.com
🔗 Live dapp - https://react-app.walletconnect.com
📚 WalletConnect docs - https://docs.walletconnect.com/2.0
Getting started
Example is built atop of NextJS in order to abstract complexity of setting up bundlers, routing etc. So there are few steps you need to follow in order to set everything up
-
Go to WalletConnect Cloud and obtain a project id
-
Add your project details in WalletConnectUtil.ts file
-
Install dependencies
yarn install
ornpm install
-
Setup your environment variables
cp .env.local.example .env.local
Your .env.local
now contains the following environment variables:
NEXT_PUBLIC_PROJECT_ID
(placeholder) - You can generate your own ProjectId at https://cloud.walletconnect.comNEXT_PUBLIC_RELAY_URL
(already set)
- Run
yarn dev
ornpm run dev
to start local development
Navigating through example
- Initial setup and initializations happen in _app.ts file
- WalletConnect client, ethers and cosmos wallets are initialized in useInitialization.ts hook
- Subscription and handling of WalletConnect events happens in useWalletConnectEventsManager.ts hook, that opens related Modal views and passes them all necessary data
- Modal views are responsible for data display and handling approval or rejection actions
- Upon approval or rejection, modals pass the request data to RequestHandlerUtil.ts that performs all necessary work based on the request method and returns formated json rpc result data that can be then used for WalletConnect client responses
Preview of wallet and dapp examples in action
https://user-images.githubusercontent.com/3154053/156764521-3492c232-7a93-47ba-88bd-2cee3f8366d4.mp4