2022-03-04 11:42:20 +00:00
# Wallet Example (React, Typescript, Ethers, NextJS, Cosmos)
2022-11-09 15:42:53 +00:00
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.
2022-03-04 11:42:20 +00:00
# Useful links
2022-02-02 12:13:49 +00:00
2022-03-04 14:01:18 +00:00
🔗 Live wallet app - https://react-wallet.walletconnect.com < br / >
🔗 Live dapp - https://react-app.walletconnect.com < br / >
2022-02-18 12:53:57 +00:00
📚 WalletConnect docs - https://docs.walletconnect.com/2.0
2022-02-02 12:13:49 +00:00
2022-02-18 12:53:57 +00:00
## Getting started
2022-02-02 12:13:49 +00:00
2022-07-12 06:18:02 +00:00
Example is built atop of [NextJS ](https://nextjs.org/ ) 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
2022-02-02 12:13:49 +00:00
2022-02-18 13:20:00 +00:00
1. Go to [WalletConnect Cloud ](https://cloud.walletconnect.com/sign-in ) and obtain a project id
2022-04-04 11:49:32 +00:00
2022-03-04 11:42:20 +00:00
2. Add your project details in [WalletConnectUtil.ts ](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/utils/WalletConnectUtil.ts ) file
2022-04-04 11:49:32 +00:00
2022-03-04 11:42:20 +00:00
3. Install dependencies `yarn install` or `npm install`
2022-04-04 11:49:32 +00:00
4. Setup your environment variables
```bash
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.com
- `NEXT_PUBLIC_RELAY_URL` (already set)
5. Run `yarn dev` or `npm run dev` to start local development
2022-03-04 11:42:20 +00:00
## Navigating through example
1. Initial setup and initializations happen in [_app.ts ](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/pages/_app.tsx ) file
2. WalletConnect client, ethers and cosmos wallets are initialized in [useInitialization.ts ](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/hooks/useInitialization.ts ) hook
2022-11-09 15:42:53 +00:00
3. Subscription and handling of WalletConnect events happens in [useWalletConnectEventsManager.ts ](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/hooks/useWalletConnectEventsManager.ts ) hook, that opens related [Modal views ](https://github.com/WalletConnect/web-examples/tree/main/wallets/react-wallet-v2/src/views ) and passes them all necessary data
2022-03-04 11:42:20 +00:00
4. [Modal views ](https://github.com/WalletConnect/web-examples/tree/main/wallets/react-wallet-v2/src/views ) are responsible for data display and handling approval or rejection actions
2022-11-09 15:42:53 +00:00
5. Upon approval or rejection, modals pass the request data to [RequestHandlerUtil.ts ](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/utils/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
2022-03-04 12:35:48 +00:00
## Preview of wallet and dapp examples in action
https://user-images.githubusercontent.com/3154053/156764521-3492c232-7a93-47ba-88bd-2cee3f8366d4.mp4
2023-07-14 03:10:06 +00:00
## DOM Tags
This section is a key of the DOM elements used for internal E2E testing
Accessible with `data-testid`
### Navbar
| Key | Description |
| ----------- | ----------- |
| `accounts` | Accounts page |
| `sessions` | Sessions page |
| `wc-connect` | WC Connect page |
| `pairings` | Pairings page |
| `settings` | Settings Page |
### WC Connect Page
url: `/walletconnect`
| Key | Description |
| ----------- | ----------- |
| `uri-input` | Uri textbox |
| `uri-connect-button` | Uri connect button |
2023-08-02 08:18:51 +00:00
| `qrcode-button` | Use qrcode button |
2023-07-14 03:10:06 +00:00
### Sessions Page
url: `/session`
| Key | Description |
| ----------- | ----------- |
2023-08-02 08:18:51 +00:00
| `session-card` | Session cards can be accessed by topic |
| `session-icon` | Icon used on session card |
| `session-text` | Text listed on session card |
| `session-link` | Link listed on session card |
2023-07-14 03:10:06 +00:00
### Session Details Page
url: `/session?topic=`
| Key | Description |
| ----------- | ----------- |
| `session-card-${chain}` | Session chain info card |
| `session-delete-button` | Session delete button |
| `session-ping-button` | Session ping button |
| `session-emit-button` | Session emit button |
| `session-update-button` | Session update button |
### Pairing Page
url: `/pairings`
| Key | Description |
| ----------- | ----------- |
| `pairing-${topic}` | Pairing cards can be accessed by topic |
2023-08-02 08:18:51 +00:00
| `pairing-text-${topic}` | Pairing card text in label |
| `pairing-url-${topic}` | Pairing card link in label|
2023-07-14 03:10:06 +00:00
| `pairing-delete-${topic}` | Delete pairing by topic |
2023-08-02 08:18:51 +00:00
2023-07-14 03:10:06 +00:00
### Accounts Page
url: `/`
| Key | Description |
| ----------- | ----------- |
2023-07-21 01:31:22 +00:00
| `account-picker` | Account drop down selector|
2023-07-14 03:10:06 +00:00
| `chain-card-${chain id}` | Chain card by chain id |
| `chain-switch-button-${chain id}` | Chain switch button |
2023-08-02 08:18:51 +00:00
| `chain-switch-button-${chain id}` | Chain copy button |
### Settings Page
url: `/settings`
| Key | Description |
| ----------- | ----------- |
| `settings-toggle-testnets` | Toggle testnet support on/off |
| `settings-region-select` | Select relayer region |
### Session Proposal View
| Key | Description |
| ----------- | ----------- |
| `session-approve-button` | Session approve button |
| `session-reject-button` | Session reject button |
| `session-info-card-text` | Session text info in header |
| `session-info-card-url` | Session info url in header |
| `session-info-card-verify` | Session info verify api in header |
| `session-proposal-card-req-{chain}` | Session card for each required chain |
| `session-proposal-card-opt-{chain}` | Session card for each optional chain |
| `account-select-card-${req/opt}-${index}` | Account selection checkbox by account index|
| `account-select-text-${req/opt}-${index}` | Account selection text by account index |
### Sign Request View
| Key | Description |
| ----------- | ----------- |
| `request-details-chain` | List of chains in the request |
| `request-details-relay-protocol` | Protocol used for request |
| `request-methods` | Methods requested |
| `request-button-reject` | Reject button |
| `request-button-approve` | Approve button |