@vechain/vechain-kit 0.11.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -6
- package/dist/index.d.ts +1860 -227
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +64 -56
package/README.md
CHANGED
|
@@ -1,13 +1,267 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1><code>vechain-kit</code></h1>
|
|
3
|
+
<p>
|
|
4
|
+
<strong>An all-in-one library for building VeChain applications</strong>
|
|
5
|
+
</p>
|
|
6
|
+
</div>
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
# Features
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
- 🔌 **Wallet Connection**: VeWorld, Sync2, WalletConnect, VeChain Embedded Wallet, Social Login (Privy)
|
|
11
|
+
- 🪝 **React Hooks**: Read and write to the VeChainThor blockchain
|
|
12
|
+
- 🧩 **Components**: Pre-built components for wallet operations
|
|
13
|
+
- 🌍 **Multilanguage**: Built-in i18n support
|
|
14
|
+
- 💰 **Token Operations**: Send tokens, check balances, handle VET domains, and more
|
|
15
|
+
|
|
16
|
+
> **Note**: Currently supports React and Next.js only
|
|
17
|
+
|
|
18
|
+
📚 For detailed documentation, visit our [VeChain Kit Docs](https://vechain-foundation-san-marino.gitbook.io/social-login-dappkit-privy/~/changes/3deX4SvayBeNDBaxivMg)
|
|
19
|
+
|
|
20
|
+
Try out the [demo app](https://vechain.github.io/vechain-kit/) to see how it works.
|
|
21
|
+
|
|
22
|
+
Also check out the [sample app](https://github.com/vechain/vechain-kit/tree/main/examples/sample-next-vechain-app) to see how to integrate the library with Next.js.
|
|
23
|
+
|
|
24
|
+
# Installation
|
|
6
25
|
|
|
7
26
|
```bash
|
|
8
|
-
yarn add @vechain/
|
|
27
|
+
yarn add @vechain/vechain-kit
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
# Quick Start
|
|
31
|
+
|
|
32
|
+
## Basic Setup
|
|
33
|
+
|
|
34
|
+
Import the `VechainKit` provider and wrap your app in it.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { VeChainKit } from '@vechain/vechain-kit';
|
|
38
|
+
|
|
39
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
40
|
+
return (
|
|
41
|
+
<VeChainKit
|
|
42
|
+
feeDelegation={{
|
|
43
|
+
delegatorUrl: process.env.NEXT_PUBLIC_DELEGATOR_URL!,
|
|
44
|
+
delegateAllTransactions: true,
|
|
45
|
+
}}
|
|
46
|
+
dappKit={{
|
|
47
|
+
allowedWallets: ['veworld', 'wallet-connect', 'sync2'],
|
|
48
|
+
walletConnectOptions: {
|
|
49
|
+
projectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID!,
|
|
50
|
+
metadata: {
|
|
51
|
+
name: 'Your App',
|
|
52
|
+
description: 'Your app description',
|
|
53
|
+
url: typeof window !== 'undefined' ? window.location.origin : '',
|
|
54
|
+
icons: [
|
|
55
|
+
typeof window !== 'undefined'
|
|
56
|
+
? `${window.location.origin}/images/logo/my-dapp.png`
|
|
57
|
+
: '',
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}}
|
|
62
|
+
loginModalUI={{
|
|
63
|
+
logo: 'https://i.ibb.co/ZHGmq3y/image-21.png',
|
|
64
|
+
description: 'Choose between social login through VeChain or by connecting your wallet.',
|
|
65
|
+
}}
|
|
66
|
+
darkMode={isDarkMode}
|
|
67
|
+
language="en"
|
|
68
|
+
network={{
|
|
69
|
+
type: 'main'
|
|
70
|
+
}}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</VeChainKit>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
This will allow you to connect to wallets (VeWorld, Sync2, WalletConnect) and to use Social Login trhough VeChain.
|
|
79
|
+
|
|
80
|
+
If you want to have your own Privy app, for enchanced user experience, you can use the `privy` prop.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { VeChainKit } from '@vechain/vechain-kit';
|
|
84
|
+
|
|
85
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
86
|
+
return (
|
|
87
|
+
<VeChainKit
|
|
88
|
+
privy={{
|
|
89
|
+
appId: process.env.NEXT_PUBLIC_PRIVY_APP_ID!,
|
|
90
|
+
clientId: process.env.NEXT_PUBLIC_PRIVY_CLIENT_ID!,
|
|
91
|
+
loginMethods: ['google', 'twitter', 'sms', 'email'],
|
|
92
|
+
appearance: {
|
|
93
|
+
walletList: ['metamask', 'rainbow'],
|
|
94
|
+
accentColor: '#696FFD',
|
|
95
|
+
loginMessage: 'Select a social media profile',
|
|
96
|
+
logo: 'https://i.ibb.co/ZHGmq3y/image-21.png',
|
|
97
|
+
},
|
|
98
|
+
embeddedWallets: {
|
|
99
|
+
createOnLogin: 'all-users',
|
|
100
|
+
},
|
|
101
|
+
allowPasskeyLinking: true,
|
|
102
|
+
}}
|
|
103
|
+
...
|
|
104
|
+
>
|
|
105
|
+
{children}
|
|
106
|
+
</VeChainKit>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Next.js Integration
|
|
112
|
+
|
|
113
|
+
To use the library with Next.js, you will need to dynamically import the `VeChainKit` provider in your `_app.tsx` file.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import dynamic from 'next/dynamic';
|
|
117
|
+
|
|
118
|
+
// Dynamic import is used here for several reasons:
|
|
119
|
+
// 1. The VechainKit component uses browser-specific APIs that aren't available during server-side rendering
|
|
120
|
+
// 2. Code splitting - this component will only be loaded when needed, reducing initial bundle size
|
|
121
|
+
// 3. The 'ssr: false' option ensures this component is only rendered on the client side
|
|
122
|
+
const VeChainKit = dynamic(
|
|
123
|
+
async () => (await import('@vechain/vechain-kit')).VeChainKit,
|
|
124
|
+
{
|
|
125
|
+
ssr: false,
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
export default function App({ Component, pageProps }: AppProps) {
|
|
130
|
+
return (
|
|
131
|
+
<VeChainKit>
|
|
132
|
+
<Component {...pageProps} />
|
|
133
|
+
</VeChainKit>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
9
136
|
```
|
|
10
137
|
|
|
11
|
-
|
|
138
|
+
# Usage Guide
|
|
139
|
+
|
|
140
|
+
## Wallet Connection
|
|
141
|
+
|
|
142
|
+
### Using the WalletButton Component
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { WalletButton } from '@vechain/vechain-kit';
|
|
146
|
+
|
|
147
|
+
<WalletButton />
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Custom Connection Button
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { useConnectModal } from '@vechain/vechain-kit';
|
|
154
|
+
|
|
155
|
+
const { open } = useConnectModal();
|
|
12
156
|
|
|
13
|
-
|
|
157
|
+
<Button onClick={open}>Connect Wallet</Button>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Wallet Information
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { useWallet } from '@vechain/vechain-kit';
|
|
164
|
+
|
|
165
|
+
const { account, connection } = useWallet();
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Transaction Management
|
|
169
|
+
|
|
170
|
+
You can use the `useSendTransaction` hook to send transactions to the blockchain, all you will need is to build the clause and pass it to the hook.
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { useSendTransaction } from '@vechain/vechain-kit';
|
|
174
|
+
|
|
175
|
+
const { sendTransaction } = useSendTransaction();
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
And you can mix it with the provided components to create a seamless experience for your users.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { TransactionModal, useSendTransaction, useTransactionModal } from '@vechain/vechain-kit';
|
|
182
|
+
|
|
183
|
+
const MyComponent = () => {
|
|
184
|
+
const {
|
|
185
|
+
sendTransaction,
|
|
186
|
+
status,
|
|
187
|
+
txReceipt,
|
|
188
|
+
resetStatus,
|
|
189
|
+
isTransactionPending,
|
|
190
|
+
error,
|
|
191
|
+
progress,
|
|
192
|
+
} = useSendTransaction({
|
|
193
|
+
signerAccountAddress: account?.address,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const {
|
|
197
|
+
open: openTransactionModal,
|
|
198
|
+
close: closeTransactionModal,
|
|
199
|
+
isOpen: isTransactionModalOpen,
|
|
200
|
+
} = useTransactionModal();
|
|
201
|
+
|
|
202
|
+
// A dummy tx sending 0 b3tr tokens
|
|
203
|
+
const clauses = useMemo(() => {
|
|
204
|
+
if (!connectedWallet.address) return [];
|
|
205
|
+
|
|
206
|
+
const clausesArray: any[] = [];
|
|
207
|
+
const abi = new Interface(b3trAbi);
|
|
208
|
+
clausesArray.push({
|
|
209
|
+
to: b3trMainnetAddress,
|
|
210
|
+
value: '0x0',
|
|
211
|
+
data: abi.encodeFunctionData('transfer', [
|
|
212
|
+
connectedWallet.address,
|
|
213
|
+
'0', // 1 B3TR (in wei)
|
|
214
|
+
]),
|
|
215
|
+
comment: `This is a dummy transaction to test the transaction modal. Confirm to transfer ${0} B3TR to ${humanAddress(
|
|
216
|
+
connectedWallet.address,
|
|
217
|
+
)}`,
|
|
218
|
+
abi: abi.getFunction('transfer'),
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
clausesArray.push({
|
|
222
|
+
to: b3trMainnetAddress,
|
|
223
|
+
value: '0x0',
|
|
224
|
+
data: abi.encodeFunctionData('transfer', [
|
|
225
|
+
connectedWallet.address,
|
|
226
|
+
'1', // 1 B3TR (in wei)
|
|
227
|
+
]),
|
|
228
|
+
comment: `This is a second close demonstrating multiclause with privy-corssapp. Transfer ${0.000001} B3TR to ${humanAddress(
|
|
229
|
+
connectedWallet.address,
|
|
230
|
+
)}`,
|
|
231
|
+
abi: abi.getFunction('transfer'),
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return clausesArray;
|
|
235
|
+
}, [connectedWallet.address]);
|
|
236
|
+
|
|
237
|
+
const handleTransactionWithModal = useCallback(async () => {
|
|
238
|
+
openTransactionModal();
|
|
239
|
+
await sendTransaction(clauses);
|
|
240
|
+
}, [sendTransaction, clauses]);
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<Button
|
|
244
|
+
onClick={handleTransactionWithModal}
|
|
245
|
+
isLoading={isTransactionPending}
|
|
246
|
+
isDisabled={isTransactionPending}
|
|
247
|
+
>
|
|
248
|
+
Tx with modal
|
|
249
|
+
</Button>
|
|
250
|
+
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
You can also use `useSignMessage` and `useSignTypedData` hooks to sign messages and typed data.
|
|
256
|
+
|
|
257
|
+
## Blockchain Data Reading
|
|
258
|
+
|
|
259
|
+
The kit provides tons of hooks to read data from the blockchain (VeBetterDAO, veDelegate, vetDomains, balances, etc.)
|
|
260
|
+
|
|
261
|
+
For example you can use `useGetB3trBalance` to get the balance of the user's wallet.
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { useGetB3trBalance } from '@vechain/vechain-kit';
|
|
265
|
+
|
|
266
|
+
const { data: balance, isLoading, isError } = useGetB3trBalance();
|
|
267
|
+
```
|