zano_web3 9.2.0 → 9.2.1

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 CHANGED
@@ -1,411 +1,461 @@
1
-
2
- # ZanoWallet
3
-
4
- `zano_web3` is a TypeScript library for interacting with the ZanoWallet extension in the browser. It allows you to connect to a user's ZanoWallet, handle authentication, and manage wallet credentials.
5
-
6
- ## Features
7
-
8
- - **Easy Integration**: Simplifies the process of connecting to the ZanoWallet extension.
9
- - **Local Storage Support**: Optionally store wallet credentials in local storage.
10
- - **Customizable**: Offers hooks for various connection lifecycle events.
11
- - **Error Handling**: Provides a structured way to handle errors during the connection process.
12
- - **Alias Management**: Allows retrieving and creating aliases.
13
-
14
- ## Installation
15
-
16
- To install `zano_web3`, use npm or yarn:
17
-
18
- ```bash
19
- npm install zano_web3
20
- ```
21
-
22
- or
23
-
24
- ```bash
25
- yarn add zano_web3
26
- ```
27
-
28
- # WEB API (extension):
29
-
30
- ## Usage
31
-
32
- ### Importing the Library
33
-
34
- ```typescript
35
- import ZanoWallet from 'zano_web3/web';
36
- ```
37
-
38
- ### Creating a ZanoWallet Instance
39
-
40
- To create a `ZanoWallet` instance, you need to provide configuration options via the `ZanoWalletParams` interface.
41
-
42
- ```typescript
43
- const zanoWallet = new ZanoWallet({
44
- authPath: '/api/auth', // Custom server path for authentication
45
- useLocalStorage: true, // Store wallet credentials in local storage (default: true)
46
- aliasRequired: false, // Whether an alias is required (optional)
47
- customLocalStorageKey: 'myWalletKey', // Custom key for local storage (optional)
48
- customNonce: 'customNonceValue', // Custom nonce for signing (optional)
49
- disableServerRequest: false, // Disable server request after signing (optional)
50
-
51
- onConnectStart: () => {
52
- console.log('Connecting to ZanoWallet...');
53
- },
54
- onConnectEnd: (data) => {
55
- console.log('Connected:', data);
56
- },
57
- onConnectError: (error) => {
58
- console.error('Connection error:', error);
59
- },
60
- beforeConnect: async () => {
61
- console.log('Preparing to connect...');
62
- },
63
- onLocalConnectEnd: (data) => {
64
- console.log('Local connection established:', data);
65
- }
66
- });
67
- ```
68
-
69
- ### React / Next.js
70
-
71
- For React or Next.js projects, you can use the `useZanoWallet` hook to create a `ZanoWallet` instance:
72
-
73
- ```tsx
74
-
75
- import { useZanoWallet } from 'zano_web3/web';
76
-
77
- const MyComponent = () => {
78
- const zanoWallet = useZanoWallet({
79
- // same options as for ZanoWallet constructor
80
- });
81
-
82
- return (
83
- <div>
84
- <button onClick={() => zanoWallet.connect()}>Connect to ZanoWallet</button>
85
- </div>
86
- );
87
- };
88
- ```
89
-
90
- ### Connecting to ZanoWallet
91
-
92
- To initiate the connection process, call the `connect` method:
93
-
94
- ```typescript
95
- await zanoWallet.connect();
96
- ```
97
-
98
- ### Handling Wallet Credentials
99
-
100
- You can manually manage wallet credentials using `getSavedWalletCredentials` and `setWalletCredentials` methods:
101
-
102
- ```typescript
103
- const credentials = zanoWallet.getSavedWalletCredentials();
104
- if (credentials) {
105
- console.log('Stored credentials:', credentials);
106
- }
107
-
108
- zanoWallet.setWalletCredentials({
109
- nonce: 'newNonce',
110
- signature: 'newSignature',
111
- publicKey: 'newPublicKey'
112
- });
113
- ```
114
-
115
- ### Retrieving Wallet Data
116
-
117
- You can retrieve the wallet data using the `getWallet` method:
118
-
119
- ```typescript
120
- const wallet = await zanoWallet.getWallet();
121
- console.log('Wallet data:', wallet);
122
- ```
123
-
124
- ### Getting Address by Alias
125
-
126
- To get an address by alias, use the `getAddressByAlias` method:
127
-
128
- ```typescript
129
- const address = await zanoWallet.getAddressByAlias('exampleAlias');
130
- console.log('Address:', address);
131
- ```
132
-
133
- ### Creating an Alias
134
-
135
- To create a new alias, use the `createAlias` method:
136
-
137
- ```typescript
138
- const newAliasData = await zanoWallet.createAlias('newAlias');
139
- console.log('Alias created:', newAliasData);
140
- ```
141
-
142
-
143
- ## Exported Types
144
-
145
- The following TypeScript interfaces are exported by the `zano_web3` library.
146
- You can import them directly from library:
147
-
148
- ```typescript
149
- import { Wallet, Asset, Transfer, Transaction } from 'zano_web3';
150
- ```
151
-
152
- ```typescript
153
- export interface Asset {
154
- name: string;
155
- ticker: string;
156
- assetId: string;
157
- decimalPoint: number;
158
- balance: string;
159
- unlockedBalance: string;
160
- }
161
-
162
- export interface Transfer {
163
- amount: string;
164
- assetId: string;
165
- incoming: boolean;
166
- }
167
-
168
- export interface Transaction {
169
- isConfirmed: boolean;
170
- txHash: string;
171
- blobSize: number;
172
- timestamp: number;
173
- height: number;
174
- paymentId: string;
175
- comment: string;
176
- fee: string;
177
- isInitiator: boolean;
178
- transfers: Transfer[];
179
- }
180
-
181
- export interface Wallet {
182
- address: string;
183
- alias: string;
184
- balance: string;
185
- assets: Asset[];
186
- transactions: Transaction[];
187
- }
188
- ```
189
-
190
- ## Requirements
191
-
192
- - ZanoWallet browser extension must be installed.
193
-
194
-
195
- # Server api (Wallet RPC, Daemon):
196
-
197
- #### Methods
198
-
199
- - `updateWalletRpcUrl(rpcUrl: string)`: Updates the wallet RPC URL.
200
- - `updateDaemonRpcUrl(rpcUrl: string)`: Updates the daemon RPC URL.
201
- - `getAssetsList()`: Retrieves the list of assets.
202
- - `getAssetDetails(assetId: string)`: Retrieves details of a specific asset.
203
- - `getAssetInfo(assetId: string)`: Retrieves info of a specific asset.
204
- - `sendTransfer(assetId: string, address: string, amount: string)`: Sends a transfer to an address.
205
- - `getBalances()`: Retrieves the balances.
206
- - `validateWallet(rpcUrl: string, authData: AuthData)`: Validates the wallet.
207
- - `getAliasDetails(alias:string)` : Retrieves information about a specific address alias.
208
-
209
-
210
- #### 1. **Updating Wallet RPC URL**
211
-
212
- ```javascript
213
- import { ServerWallet } from "zano_web3/server";
214
-
215
- (async () => {
216
- const zanoServerAPI = new ServerWallet({
217
- walletUrl: "http://127.0.0.1:11211/json_rpc",
218
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
219
- });
220
-
221
- // Update the wallet RPC URL
222
- await zanoServerAPI.updateWalletRpcUrl("http://new_wallet_url:11211/json_rpc");
223
-
224
- console.log("Wallet RPC URL updated.");
225
- })();
226
- ```
227
-
228
- #### 2. **Updating Daemon RPC URL**
229
-
230
- ```javascript
231
- import { ServerWallet } from "zano_web3/server";
232
-
233
- (async () => {
234
- const zanoServerAPI = new ServerWallet({
235
- walletUrl: "http://127.0.0.1:11211/json_rpc",
236
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
237
- });
238
-
239
- // Update the daemon RPC URL
240
- await zanoServerAPI.updateDaemonRpcUrl("http://new_daemon_url:11211/json_rpc");
241
-
242
- console.log("Daemon RPC URL updated.");
243
- })();
244
- ```
245
-
246
- #### 3. **Getting the List of Assets**
247
-
248
- ```javascript
249
- import { ServerWallet } from "zano_web3/server";
250
-
251
- (async () => {
252
- const zanoServerAPI = new ServerWallet({
253
- walletUrl: "http://127.0.0.1:11211/json_rpc",
254
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
255
- });
256
-
257
- // Get the list of assets
258
- const assets = await zanoServerAPI.getAssetsList();
259
-
260
- console.log("Assets List:", assets);
261
- })();
262
- ```
263
-
264
- #### 4. **Getting Asset Details**
265
-
266
- ```javascript
267
- import { ServerWallet } from "zano_web3/server";
268
-
269
- (async () => {
270
- const zanoServerAPI = new ServerWallet({
271
- walletUrl: "http://127.0.0.1:11211/json_rpc",
272
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
273
- });
274
-
275
- // Get details of a specific asset by ID
276
- const assetId = "example-asset-id";
277
- const assetDetails = await zanoServerAPI.getAssetDetails(assetId);
278
-
279
- console.log(`Details for Asset ID ${assetId}:`, assetDetails);
280
- })();
281
- ```
282
-
283
- #### 5. **Getting Asset Info**
284
-
285
- ```javascript
286
- import { ServerWallet } from "zano_web3/server";
287
-
288
- (async () => {
289
- const zanoServerAPI = new ServerWallet({
290
- walletUrl: "http://127.0.0.1:11211/json_rpc",
291
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
292
- });
293
-
294
- // Get info for a specific asset by ID
295
- const assetId = "example-asset-id";
296
- const assetInfo = await zanoServerAPI.getAssetInfo(assetId);
297
-
298
- console.log(`Info for Asset ID ${assetId}:`, assetInfo);
299
- })();
300
- ```
301
-
302
- #### 6. **Sending a Transfer**
303
-
304
- ```javascript
305
- import { ServerWallet } from "zano_web3/server";
306
-
307
- (async () => {
308
- const zanoServerAPI = new ServerWallet({
309
- walletUrl: "http://127.0.0.1:11211/json_rpc",
310
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
311
- });
312
-
313
- // Send a transfer
314
- const assetId = "example-asset-id";
315
- const address = "recipient-address";
316
- const amount = "10.5"; // in asset units
317
-
318
- try {
319
- const transferResult = await zanoServerAPI.sendTransfer(assetId, address, amount);
320
- console.log("Transfer successful:", transferResult);
321
- } catch (error) {
322
- console.error("Transfer failed:", error.message);
323
- }
324
- })();
325
- ```
326
-
327
- #### 7. **Getting Balances**
328
-
329
- ```javascript
330
- import { ServerWallet } from "zano_web3/server";
331
-
332
- (async () => {
333
- const zanoServerAPI = new ServerWallet({
334
- walletUrl: "http://127.0.0.1:11211/json_rpc",
335
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
336
- });
337
-
338
- // Get the balances
339
- const balances = await zanoServerAPI.getBalances();
340
-
341
- console.log("Balances:", balances);
342
- })();
343
- ```
344
-
345
- #### 8. **Validating a Wallet**
346
-
347
- ```javascript
348
- import { ServerWallet } from "zano_web3/server";
349
- import { AuthData } from "./types";
350
-
351
- (async () => {
352
- const zanoServerAPI = new ServerWallet({
353
- walletUrl: "http://127.0.0.1:11211/json_rpc",
354
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
355
- });
356
-
357
- // Validate wallet using AuthData
358
- const authData: AuthData = {
359
- message: "message to sign",
360
- address: "wallet-address",
361
- signature: "signature",
362
- alias: "wallet-alias"
363
- };
364
-
365
- try {
366
- const isValid = await zanoServerAPI.validateWallet(authData);
367
- console.log("Wallet validation:", isValid ? "Valid" : "Invalid");
368
- } catch (error) {
369
- console.error("Validation failed:", error.message);
370
- }
371
- })();
372
- ```
373
-
374
- #### 9. **Get Alias details**
375
-
376
- ```javascript
377
- import { ServerWallet } from "zano_web3/server";
378
-
379
- const alias = "alias";
380
-
381
- (async (alias) => {
382
- const zanoServerAPI = new ServerWallet({
383
- walletUrl: "http://127.0.0.1:11211/json_rpc",
384
- daemonUrl: "http://127.0.0.1:11211/json_rpc"
385
- });
386
-
387
- try {
388
- const aliasDetails = await zanoServerAPI.getAliasDetails(alias);
389
- console.log(aliasDetails);
390
- } catch (error) {
391
- console.error(error.message);
392
- }
393
- })(alias);
394
- ```
395
-
396
- ## Requirements
397
-
398
- - Correct RPC URLs for the wallet and daemon.
399
-
400
- # Shared logic
401
- ## Usage
402
- ### validateTokensInput util
403
- validateTokensInput function checks whether a numeric or string value can be used as an amount for an asset with the specified DP.
404
-
405
- ```typescript
406
- import { validateTokensInput } from "zano_web3/shared";
407
-
408
- let isValidAmount = validateTokensInput("18446744.073709551615", 12); // true
409
-
410
- isValidAmount = validateTokensInput("18446744.073709551616", 12); // false
1
+
2
+ # ZanoWallet
3
+
4
+ `zano_web3` is a TypeScript library for interacting with the ZanoWallet extension in the browser. It allows you to connect to a user's ZanoWallet, handle authentication, and manage wallet credentials.
5
+
6
+ ## Features
7
+
8
+ - **Easy Integration**: Simplifies the process of connecting to the ZanoWallet extension.
9
+ - **Local Storage Support**: Optionally store wallet credentials in local storage.
10
+ - **Customizable**: Offers hooks for various connection lifecycle events.
11
+ - **Error Handling**: Provides a structured way to handle errors during the connection process.
12
+ - **Alias Management**: Allows retrieving and creating aliases.
13
+
14
+ ## Installation
15
+
16
+ To install `zano_web3`, use npm or yarn:
17
+
18
+ ```bash
19
+ npm install zano_web3
20
+ ```
21
+
22
+ or
23
+
24
+ ```bash
25
+ yarn add zano_web3
26
+ ```
27
+
28
+ # WEB API (extension):
29
+
30
+ ## Usage
31
+
32
+ ### Importing the Library
33
+
34
+ ```typescript
35
+ import ZanoWallet from 'zano_web3/web';
36
+ ```
37
+
38
+ ### Creating a ZanoWallet Instance
39
+
40
+ To create a `ZanoWallet` instance, you need to provide configuration options via the `ZanoWalletParams` interface.
41
+
42
+ ```typescript
43
+ const zanoWallet = new ZanoWallet({
44
+ authPath: '/api/auth', // Custom server path for authentication
45
+ useLocalStorage: true, // Store wallet credentials in local storage (default: true)
46
+ aliasRequired: false, // Whether an alias is required (optional)
47
+ customLocalStorageKey: 'myWalletKey', // Custom key for local storage (optional)
48
+ customNonce: 'customNonceValue', // Custom nonce for signing (optional)
49
+ disableServerRequest: false, // Disable server request after signing (optional)
50
+
51
+ onConnectStart: () => {
52
+ console.log('Connecting to ZanoWallet...');
53
+ },
54
+ onConnectEnd: (data) => {
55
+ console.log('Connected:', data);
56
+ },
57
+ onConnectError: (error) => {
58
+ console.error('Connection error:', error);
59
+ },
60
+ beforeConnect: async () => {
61
+ console.log('Preparing to connect...');
62
+ },
63
+ onLocalConnectEnd: (data) => {
64
+ console.log('Local connection established:', data);
65
+ }
66
+ });
67
+ ```
68
+
69
+ ### React / Next.js
70
+
71
+ For React or Next.js projects, you can use the `useZanoWallet` hook to create a `ZanoWallet` instance:
72
+
73
+ ```tsx
74
+
75
+ import { useZanoWallet } from 'zano_web3/web';
76
+
77
+ const MyComponent = () => {
78
+ const zanoWallet = useZanoWallet({
79
+ // same options as for ZanoWallet constructor
80
+ });
81
+
82
+ return (
83
+ <div>
84
+ <button onClick={() => zanoWallet.connect()}>Connect to ZanoWallet</button>
85
+ </div>
86
+ );
87
+ };
88
+ ```
89
+
90
+ ### Connecting to ZanoWallet
91
+
92
+ To initiate the connection process, call the `connect` method:
93
+
94
+ ```typescript
95
+ await zanoWallet.connect();
96
+ ```
97
+
98
+ ### Handling Wallet Credentials
99
+
100
+ You can manually manage wallet credentials using `getSavedWalletCredentials` and `setWalletCredentials` methods:
101
+
102
+ ```typescript
103
+ const credentials = zanoWallet.getSavedWalletCredentials();
104
+ if (credentials) {
105
+ console.log('Stored credentials:', credentials);
106
+ }
107
+
108
+ zanoWallet.setWalletCredentials({
109
+ nonce: 'newNonce',
110
+ signature: 'newSignature',
111
+ publicKey: 'newPublicKey'
112
+ });
113
+ ```
114
+
115
+ ### Retrieving Wallet Data
116
+
117
+ You can retrieve the wallet data using the `getWallet` method:
118
+
119
+ ```typescript
120
+ const wallet = await zanoWallet.getWallet();
121
+ console.log('Wallet data:', wallet);
122
+ ```
123
+
124
+ ### Getting Address by Alias
125
+
126
+ To get an address by alias, use the `getAddressByAlias` method:
127
+
128
+ ```typescript
129
+ const address = await zanoWallet.getAddressByAlias('exampleAlias');
130
+ console.log('Address:', address);
131
+ ```
132
+
133
+ ### Creating an Alias
134
+
135
+ To create a new alias, use the `createAlias` method:
136
+
137
+ ```typescript
138
+ const newAliasData = await zanoWallet.createAlias('newAlias');
139
+ console.log('Alias created:', newAliasData);
140
+ ```
141
+
142
+
143
+ ## Exported Types
144
+
145
+ The following TypeScript interfaces are exported by the `zano_web3` library.
146
+ You can import them directly from library:
147
+
148
+ ```typescript
149
+ import { Wallet, Asset, Transfer, Transaction } from 'zano_web3';
150
+ ```
151
+
152
+ ```typescript
153
+ export interface Asset {
154
+ name: string;
155
+ ticker: string;
156
+ assetId: string;
157
+ decimalPoint: number;
158
+ balance: string;
159
+ unlockedBalance: string;
160
+ }
161
+
162
+ export interface Transfer {
163
+ amount: string;
164
+ assetId: string;
165
+ incoming: boolean;
166
+ }
167
+
168
+ export interface Transaction {
169
+ isConfirmed: boolean;
170
+ txHash: string;
171
+ blobSize: number;
172
+ timestamp: number;
173
+ height: number;
174
+ paymentId: string;
175
+ comment: string;
176
+ fee: string;
177
+ isInitiator: boolean;
178
+ transfers: Transfer[];
179
+ }
180
+
181
+ export interface Wallet {
182
+ address: string;
183
+ alias: string;
184
+ balance: string;
185
+ assets: Asset[];
186
+ transactions: Transaction[];
187
+ }
188
+ ```
189
+
190
+ ## Requirements
191
+
192
+ - ZanoWallet browser extension must be installed.
193
+
194
+
195
+ # Server api (Wallet RPC, Daemon):
196
+
197
+ #### Methods
198
+
199
+ - `updateWalletRpcUrl(rpcUrl: string)`: Updates the wallet RPC URL.
200
+ - `updateDaemonRpcUrl(rpcUrl: string)`: Updates the daemon RPC URL.
201
+ - `getAssetsList()`: Retrieves the list of assets.
202
+ - `getAssetDetails(assetId: string)`: Retrieves details of a specific asset.
203
+ - `getAssetInfo(assetId: string)`: Retrieves info of a specific asset.
204
+ - `sendTransfer(assetId: string, address: string, amount: string)`: Sends a transfer to an address.
205
+ - `getBalances()`: Retrieves the balances.
206
+ - `validateWallet(rpcUrl: string, authData: AuthData)`: Validates the wallet.
207
+ - `getAliasDetails(alias:string)` : Retrieves information about a specific address alias.
208
+ - `fetchDaemon(method: string, params: any)`: Fetches daemon with given method & params and returns an AxiosResponse object.
209
+ - `fetchWallet(method: string, params: any)`: Fetches wallet with given method & params and returns an AxiosResponse object.
210
+
211
+
212
+ #### 1. **Updating Wallet RPC URL**
213
+
214
+ ```javascript
215
+ import { ServerWallet } from "zano_web3/server";
216
+
217
+ (async () => {
218
+ const zanoServerAPI = new ServerWallet({
219
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
220
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
221
+ });
222
+
223
+ // Update the wallet RPC URL
224
+ await zanoServerAPI.updateWalletRpcUrl("http://new_wallet_url:11211/json_rpc");
225
+
226
+ console.log("Wallet RPC URL updated.");
227
+ })();
228
+ ```
229
+
230
+ #### 2. **Updating Daemon RPC URL**
231
+
232
+ ```javascript
233
+ import { ServerWallet } from "zano_web3/server";
234
+
235
+ (async () => {
236
+ const zanoServerAPI = new ServerWallet({
237
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
238
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
239
+ });
240
+
241
+ // Update the daemon RPC URL
242
+ await zanoServerAPI.updateDaemonRpcUrl("http://new_daemon_url:11211/json_rpc");
243
+
244
+ console.log("Daemon RPC URL updated.");
245
+ })();
246
+ ```
247
+
248
+ #### 3. **Getting the List of Assets**
249
+
250
+ ```javascript
251
+ import { ServerWallet } from "zano_web3/server";
252
+
253
+ (async () => {
254
+ const zanoServerAPI = new ServerWallet({
255
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
256
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
257
+ });
258
+
259
+ // Get the list of assets
260
+ const assets = await zanoServerAPI.getAssetsList();
261
+
262
+ console.log("Assets List:", assets);
263
+ })();
264
+ ```
265
+
266
+ #### 4. **Getting Asset Details**
267
+
268
+ ```javascript
269
+ import { ServerWallet } from "zano_web3/server";
270
+
271
+ (async () => {
272
+ const zanoServerAPI = new ServerWallet({
273
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
274
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
275
+ });
276
+
277
+ // Get details of a specific asset by ID
278
+ const assetId = "example-asset-id";
279
+ const assetDetails = await zanoServerAPI.getAssetDetails(assetId);
280
+
281
+ console.log(`Details for Asset ID ${assetId}:`, assetDetails);
282
+ })();
283
+ ```
284
+
285
+ #### 5. **Getting Asset Info**
286
+
287
+ ```javascript
288
+ import { ServerWallet } from "zano_web3/server";
289
+
290
+ (async () => {
291
+ const zanoServerAPI = new ServerWallet({
292
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
293
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
294
+ });
295
+
296
+ // Get info for a specific asset by ID
297
+ const assetId = "example-asset-id";
298
+ const assetInfo = await zanoServerAPI.getAssetInfo(assetId);
299
+
300
+ console.log(`Info for Asset ID ${assetId}:`, assetInfo);
301
+ })();
302
+ ```
303
+
304
+ #### 6. **Sending a Transfer**
305
+
306
+ ```javascript
307
+ import { ServerWallet } from "zano_web3/server";
308
+
309
+ (async () => {
310
+ const zanoServerAPI = new ServerWallet({
311
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
312
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
313
+ });
314
+
315
+ // Send a transfer
316
+ const assetId = "example-asset-id";
317
+ const address = "recipient-address";
318
+ const amount = "10.5"; // in asset units
319
+
320
+ try {
321
+ const transferResult = await zanoServerAPI.sendTransfer(assetId, address, amount);
322
+ console.log("Transfer successful:", transferResult);
323
+ } catch (error) {
324
+ console.error("Transfer failed:", error.message);
325
+ }
326
+ })();
327
+ ```
328
+
329
+ #### 7. **Getting Balances**
330
+
331
+ ```javascript
332
+ import { ServerWallet } from "zano_web3/server";
333
+
334
+ (async () => {
335
+ const zanoServerAPI = new ServerWallet({
336
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
337
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
338
+ });
339
+
340
+ // Get the balances
341
+ const balances = await zanoServerAPI.getBalances();
342
+
343
+ console.log("Balances:", balances);
344
+ })();
345
+ ```
346
+
347
+ #### 8. **Validating a Wallet**
348
+
349
+ ```javascript
350
+ import { ServerWallet } from "zano_web3/server";
351
+ import { AuthData } from "./types";
352
+
353
+ (async () => {
354
+ const zanoServerAPI = new ServerWallet({
355
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
356
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
357
+ });
358
+
359
+ // Validate wallet using AuthData
360
+ const authData: AuthData = {
361
+ message: "message to sign",
362
+ address: "wallet-address",
363
+ signature: "signature",
364
+ alias: "wallet-alias"
365
+ };
366
+
367
+ try {
368
+ const isValid = await zanoServerAPI.validateWallet(authData);
369
+ console.log("Wallet validation:", isValid ? "Valid" : "Invalid");
370
+ } catch (error) {
371
+ console.error("Validation failed:", error.message);
372
+ }
373
+ })();
374
+ ```
375
+
376
+ #### 9. **Get Alias details**
377
+
378
+ ```javascript
379
+ import { ServerWallet } from "zano_web3/server";
380
+
381
+ const alias = "alias";
382
+
383
+ (async (alias) => {
384
+ const zanoServerAPI = new ServerWallet({
385
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
386
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
387
+ });
388
+
389
+ try {
390
+ const aliasDetails = await zanoServerAPI.getAliasDetails(alias);
391
+ console.log(aliasDetails);
392
+ } catch (error) {
393
+ console.error(error.message);
394
+ }
395
+ })(alias);
396
+ ```
397
+
398
+ #### 10. **Fetch Daemon**
399
+
400
+ ```javascript
401
+ import { ServerWallet } from "zano_web3/server";
402
+
403
+ (async () => {
404
+ const zanoServerAPI = new ServerWallet({
405
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
406
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
407
+ });
408
+
409
+ try {
410
+ // Fetch daemon and retrieve a response (e.g., the getinfo method)
411
+ const getInfoResponse = await zanoServerAPI.fetchDaemon("getinfo", {
412
+ "flags": 1048575
413
+ });
414
+
415
+ console.log("Info:", getInfoResponse.data.result);
416
+ } catch (error) {
417
+ console.error('Error fetching getinfo:', error);
418
+ }
419
+
420
+ })();
421
+ ```
422
+
423
+ #### 11. **Fetch Wallet**
424
+
425
+ ```javascript
426
+ import { ServerWallet } from "zano_web3/server";
427
+
428
+ (async () => {
429
+ const zanoServerAPI = new ServerWallet({
430
+ walletUrl: "http://127.0.0.1:11211/json_rpc",
431
+ daemonUrl: "http://127.0.0.1:11211/json_rpc"
432
+ });
433
+
434
+ try {
435
+ // Fetch wallet and retrieve a response (e.g., the getaddress method)
436
+ const getAddressResponse = await zanoServerAPI.fetchWallet("getaddress", {});
437
+
438
+ console.log("Address Info:", getAddressResponse.data.result);
439
+ } catch (error) {
440
+ console.error('Error fetching getaddress:', error);
441
+ }
442
+
443
+ })();
444
+ ```
445
+
446
+ ## Requirements
447
+
448
+ - Correct RPC URLs for the wallet and daemon.
449
+
450
+ # Shared logic
451
+ ## Usage
452
+ ### validateTokensInput util
453
+ validateTokensInput function checks whether a numeric or string value can be used as an amount for an asset with the specified DP.
454
+
455
+ ```typescript
456
+ import { validateTokensInput } from "zano_web3/shared";
457
+
458
+ let isValidAmount = validateTokensInput("18446744.073709551615", 12); // true
459
+
460
+ isValidAmount = validateTokensInput("18446744.073709551616", 12); // false
411
461
  ```