-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e2e280
commit 4c52395
Showing
4 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,82 @@ | ||
# `wallet-helpers` | ||
# `@vecahin/dapp-kit` | ||
|
||
## Why ? | ||
|
||
- Allow easy interaction with all wallets. | ||
- Connex is designed to play nice with one wallet at a time, this library provides a layer on top of Connex to easily | ||
allow interaction with all wallets. | ||
- Easy setup for wallet connect. | ||
- Create your own | ||
|
||
## Installation | ||
|
||
- See the parent [README](../../README.md) for installation instructions. | ||
|
||
### Build | ||
|
||
```bash | ||
yarn build | ||
``` | ||
|
||
## Usage | ||
|
||
```bash | ||
yarn add @vechain/dapp-kit | ||
``` | ||
|
||
- Create a function to handle remote wallet disconnections. Some wallets can disconnect remotely (eg. Wallet Connect) | ||
|
||
```typescript | ||
const onDisconnected = () => { | ||
//TODO: handle disconnect | ||
}; | ||
``` | ||
|
||
- Optional: Configure wallet connect options | ||
|
||
```typescript | ||
import type { WalletConnectOptions } from '@vechain/wallet-connect'; | ||
|
||
const walletConnectOptions: WalletConnectOptions = { | ||
projectId: '<PROJECT_ID>', // Create your project here: https://cloud.walletconnect.com/sign-up | ||
metadata: { | ||
name: 'My dApp', | ||
description: 'My dApp description', | ||
url: window.location.origin, // Your app URL | ||
icons: [`${window.location.origin}/images/my-dapp-icon.png`], // Your app Icon | ||
}, | ||
}; | ||
``` | ||
|
||
- Create a new instance of `MultiWalletConnex` and pass in the options | ||
- `thor` will be ready to use to interact with the chain, but calling any methods requiring a wallet will throw an | ||
error. See the next step to finalise the setup. | ||
|
||
```typescript | ||
const { thor, vendor, wallet } = new MultiWalletConnex({ | ||
nodeUrl: 'https://sync-testnet.vechain.org/', //Required | ||
genesis: 'main', //Optional - "main" | "test" | Connex.Thor.Block | ||
walletConnectOptions, | ||
onDisconnected, | ||
}); | ||
``` | ||
|
||
- You can set the wallet source when the user selects a wallet, or if you want to default to a specific wallet. | ||
- Connex is ready to use as normal | ||
|
||
```typescript | ||
wallet.setSource('veworld-extension'); | ||
``` | ||
|
||
- Connect to the wallet. This will return the user's address | ||
- `verified` indicates whether a certificate is signed by the user. If a sign in is required and the account is not | ||
verified, you should request a subsequent certificate sign in | ||
|
||
```typescript | ||
const { account, verified } = await wallet.connect(); | ||
``` | ||
|
||
```typescript | ||
const tx = await thor.account("0x...123").method(...).transact().request(); | ||
const certRes = await vendor.sign("cert", {...}).requset(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters