@varity-labs/client-js 2.0.0-alpha.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/LICENSE +31 -0
- package/README.md +82 -0
- package/dist/VarityClient.d.ts +104 -0
- package/dist/VarityClient.js +212 -0
- package/dist/__tests__/client.test.d.ts +4 -0
- package/dist/__tests__/client.test.js +251 -0
- package/dist/auth/SIWEAuth.d.ts +105 -0
- package/dist/auth/SIWEAuth.js +328 -0
- package/dist/contracts/ContractManager.d.ts +109 -0
- package/dist/contracts/ContractManager.js +306 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +76 -0
- package/dist/react/hooks.d.ts +170 -0
- package/dist/react/hooks.js +398 -0
- package/dist/storage/StorageManager.d.ts +122 -0
- package/dist/storage/StorageManager.js +296 -0
- package/dist/types.d.ts +157 -0
- package/dist/types.js +51 -0
- package/dist/utils/formatting.d.ts +123 -0
- package/dist/utils/formatting.js +236 -0
- package/dist/varity-s3-client.d.ts +119 -0
- package/dist/varity-s3-client.js +179 -0
- package/dist/wallet/WalletManager.d.ts +120 -0
- package/dist/wallet/WalletManager.js +355 -0
- package/package.json +76 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Contract Manager - Handle smart contract interactions
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ContractManager = void 0;
|
|
7
|
+
const thirdweb_1 = require("thirdweb");
|
|
8
|
+
const deploys_1 = require("thirdweb/deploys");
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
/**
|
|
11
|
+
* ContractManager - Manage smart contract operations
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Read from contract
|
|
16
|
+
* const balance = await contractManager.read({
|
|
17
|
+
* address: '0x...',
|
|
18
|
+
* abi: ERC20_ABI,
|
|
19
|
+
* functionName: 'balanceOf',
|
|
20
|
+
* args: ['0x...']
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Write to contract
|
|
24
|
+
* const result = await contractManager.write({
|
|
25
|
+
* address: '0x...',
|
|
26
|
+
* abi: ERC20_ABI,
|
|
27
|
+
* functionName: 'transfer',
|
|
28
|
+
* args: ['0x...', 1000000n]
|
|
29
|
+
* }, account);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
class ContractManager {
|
|
33
|
+
constructor(client, chain) {
|
|
34
|
+
this.client = client;
|
|
35
|
+
this.chain = chain;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get contract instance
|
|
39
|
+
* @param address Contract address
|
|
40
|
+
* @param abi Contract ABI
|
|
41
|
+
* @returns Contract instance
|
|
42
|
+
*/
|
|
43
|
+
getContractInstance(address, abi) {
|
|
44
|
+
return (0, thirdweb_1.getContract)({
|
|
45
|
+
client: this.client,
|
|
46
|
+
chain: this.chain,
|
|
47
|
+
address,
|
|
48
|
+
abi,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read from contract (no gas required)
|
|
53
|
+
* @param options Contract read options
|
|
54
|
+
* @returns Read result
|
|
55
|
+
*/
|
|
56
|
+
async read(options) {
|
|
57
|
+
try {
|
|
58
|
+
const contract = this.getContractInstance(options.address, options.abi);
|
|
59
|
+
const result = await (0, thirdweb_1.readContract)({
|
|
60
|
+
contract,
|
|
61
|
+
method: options.functionName,
|
|
62
|
+
params: options.args || [],
|
|
63
|
+
});
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw new types_1.ContractError(`Failed to read from contract: ${error.message}`, {
|
|
68
|
+
address: options.address,
|
|
69
|
+
functionName: options.functionName,
|
|
70
|
+
error,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Write to contract (requires gas and wallet signature)
|
|
76
|
+
* @param options Contract write options
|
|
77
|
+
* @param account Wallet account
|
|
78
|
+
* @returns Transaction result
|
|
79
|
+
*/
|
|
80
|
+
async write(options, account) {
|
|
81
|
+
try {
|
|
82
|
+
const contract = this.getContractInstance(options.address, options.abi);
|
|
83
|
+
// Prepare contract call
|
|
84
|
+
const transaction = (0, thirdweb_1.prepareContractCall)({
|
|
85
|
+
contract,
|
|
86
|
+
method: options.functionName,
|
|
87
|
+
params: options.args || [],
|
|
88
|
+
value: options.value,
|
|
89
|
+
});
|
|
90
|
+
// Send transaction
|
|
91
|
+
const result = await (0, thirdweb_1.sendTransaction)({
|
|
92
|
+
transaction,
|
|
93
|
+
account,
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
transactionHash: result.transactionHash,
|
|
97
|
+
blockNumber: 0, // Will be filled after confirmation
|
|
98
|
+
from: account.address,
|
|
99
|
+
to: options.address,
|
|
100
|
+
gasUsed: BigInt(0), // Will be filled after confirmation
|
|
101
|
+
status: 'success',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw new types_1.ContractError(`Failed to write to contract: ${error.message}`, {
|
|
106
|
+
address: options.address,
|
|
107
|
+
functionName: options.functionName,
|
|
108
|
+
error,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Deploy new contract
|
|
114
|
+
* @param options Deployment options
|
|
115
|
+
* @param account Deployer account
|
|
116
|
+
* @returns Deployed contract address and transaction
|
|
117
|
+
*/
|
|
118
|
+
async deploy(options, account) {
|
|
119
|
+
try {
|
|
120
|
+
// deployContract in v5 returns the contract address as a string
|
|
121
|
+
const contractAddress = await (0, deploys_1.deployContract)({
|
|
122
|
+
client: this.client,
|
|
123
|
+
chain: this.chain,
|
|
124
|
+
account,
|
|
125
|
+
abi: options.abi || [],
|
|
126
|
+
bytecode: options.bytecode,
|
|
127
|
+
constructorParams: {}, // v5 expects params as object
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
address: contractAddress,
|
|
131
|
+
transactionHash: '', // v5 doesn't return transactionHash directly
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
throw new types_1.ContractError(`Failed to deploy contract: ${error.message}`, {
|
|
136
|
+
error,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get contract events
|
|
142
|
+
* @param filter Event filter options
|
|
143
|
+
* @returns Array of events
|
|
144
|
+
*/
|
|
145
|
+
async getEvents(filter) {
|
|
146
|
+
try {
|
|
147
|
+
const contract = this.getContractInstance(filter.address, filter.abi);
|
|
148
|
+
// Prepare event using prepareEvent with proper event signature format
|
|
149
|
+
const preparedEvent = (0, thirdweb_1.prepareEvent)({
|
|
150
|
+
signature: filter.eventName,
|
|
151
|
+
});
|
|
152
|
+
const events = await (0, thirdweb_1.getContractEvents)({
|
|
153
|
+
contract,
|
|
154
|
+
events: [preparedEvent],
|
|
155
|
+
fromBlock: BigInt(filter.fromBlock || 0),
|
|
156
|
+
toBlock: filter.toBlock ? BigInt(filter.toBlock) : undefined,
|
|
157
|
+
});
|
|
158
|
+
return events.map((event) => ({
|
|
159
|
+
eventName: filter.eventName,
|
|
160
|
+
args: event.args,
|
|
161
|
+
blockNumber: Number(event.blockNumber),
|
|
162
|
+
transactionHash: event.transactionHash,
|
|
163
|
+
logIndex: event.logIndex,
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
throw new types_1.ContractError(`Failed to get contract events: ${error.message}`, {
|
|
168
|
+
address: filter.address,
|
|
169
|
+
eventName: filter.eventName,
|
|
170
|
+
error,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Listen to contract events (real-time)
|
|
176
|
+
* @param filter Event filter options
|
|
177
|
+
* @param callback Event callback
|
|
178
|
+
* @returns Cleanup function
|
|
179
|
+
*/
|
|
180
|
+
watchEvents(filter, callback) {
|
|
181
|
+
const contract = this.getContractInstance(filter.address, filter.abi);
|
|
182
|
+
let isActive = true;
|
|
183
|
+
// Poll for new events
|
|
184
|
+
const pollInterval = setInterval(async () => {
|
|
185
|
+
if (!isActive)
|
|
186
|
+
return;
|
|
187
|
+
try {
|
|
188
|
+
const latestBlock = filter.toBlock || 'latest';
|
|
189
|
+
const events = await this.getEvents({
|
|
190
|
+
...filter,
|
|
191
|
+
fromBlock: filter.fromBlock,
|
|
192
|
+
toBlock: typeof latestBlock === 'string' ? undefined : latestBlock,
|
|
193
|
+
});
|
|
194
|
+
events.forEach(callback);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
console.error('Error watching events:', error);
|
|
198
|
+
}
|
|
199
|
+
}, 5000); // Poll every 5 seconds
|
|
200
|
+
// Return cleanup function
|
|
201
|
+
return () => {
|
|
202
|
+
isActive = false;
|
|
203
|
+
clearInterval(pollInterval);
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Estimate gas for contract call
|
|
208
|
+
* @param options Contract write options
|
|
209
|
+
* @param account Wallet account
|
|
210
|
+
* @returns Estimated gas
|
|
211
|
+
*/
|
|
212
|
+
async estimateGas(options, account) {
|
|
213
|
+
try {
|
|
214
|
+
const contract = this.getContractInstance(options.address, options.abi);
|
|
215
|
+
const transaction = (0, thirdweb_1.prepareContractCall)({
|
|
216
|
+
contract,
|
|
217
|
+
method: options.functionName,
|
|
218
|
+
params: options.args || [],
|
|
219
|
+
value: options.value,
|
|
220
|
+
});
|
|
221
|
+
// Estimate gas (this is a simplified version)
|
|
222
|
+
// In production, use proper gas estimation
|
|
223
|
+
return BigInt(200000); // Default gas limit
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
throw new types_1.ContractError(`Failed to estimate gas: ${error.message}`, {
|
|
227
|
+
address: options.address,
|
|
228
|
+
functionName: options.functionName,
|
|
229
|
+
error,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Batch read multiple contract calls
|
|
235
|
+
* @param calls Array of read options
|
|
236
|
+
* @returns Array of results
|
|
237
|
+
*/
|
|
238
|
+
async batchRead(calls) {
|
|
239
|
+
try {
|
|
240
|
+
const results = await Promise.all(calls.map((call) => this.read(call)));
|
|
241
|
+
return results;
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
throw new types_1.ContractError(`Failed to batch read: ${error.message}`, {
|
|
245
|
+
error,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Batch write multiple contract calls (in sequence)
|
|
251
|
+
* @param calls Array of write options
|
|
252
|
+
* @param account Wallet account
|
|
253
|
+
* @returns Array of transaction results
|
|
254
|
+
*/
|
|
255
|
+
async batchWrite(calls, account) {
|
|
256
|
+
const results = [];
|
|
257
|
+
for (const call of calls) {
|
|
258
|
+
try {
|
|
259
|
+
const result = await this.write(call, account);
|
|
260
|
+
results.push(result);
|
|
261
|
+
}
|
|
262
|
+
catch (error) {
|
|
263
|
+
throw new types_1.ContractError(`Failed to execute batch write at index ${results.length}: ${error.message}`, {
|
|
264
|
+
completedCalls: results.length,
|
|
265
|
+
error,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return results;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Check if contract exists at address
|
|
273
|
+
* @param address Contract address
|
|
274
|
+
* @returns True if contract exists
|
|
275
|
+
*/
|
|
276
|
+
async contractExists(address) {
|
|
277
|
+
try {
|
|
278
|
+
// Try to get contract code
|
|
279
|
+
// This is a simplified check
|
|
280
|
+
return true; // In production, check for bytecode
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Get contract bytecode
|
|
288
|
+
* @param address Contract address
|
|
289
|
+
* @returns Contract bytecode
|
|
290
|
+
*/
|
|
291
|
+
async getBytecode(address) {
|
|
292
|
+
try {
|
|
293
|
+
// Get contract bytecode
|
|
294
|
+
// This requires additional Thirdweb SDK methods
|
|
295
|
+
return '0x'; // Placeholder
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
throw new types_1.ContractError(`Failed to get bytecode: ${error.message}`, {
|
|
299
|
+
address,
|
|
300
|
+
error,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
exports.ContractManager = ContractManager;
|
|
306
|
+
exports.default = ContractManager;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Varity JavaScript/TypeScript Client Library
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive SDK for Varity L3 blockchain interactions powered by Thirdweb.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { VarityClient, VARITY_L3_CHAIN, ARBITRUM_SEPOLIA_CHAIN, ARBITRUM_ONE_CHAIN } from './VarityClient';
|
|
9
|
+
export { default as VarityClientClass } from './VarityClient';
|
|
10
|
+
export { ContractManager } from './contracts/ContractManager';
|
|
11
|
+
export { WalletManager } from './wallet/WalletManager';
|
|
12
|
+
export { SIWEAuth } from './auth/SIWEAuth';
|
|
13
|
+
export { StorageManager } from './storage/StorageManager';
|
|
14
|
+
export type { VarityClientConfig, ChainConfig, WalletConnectionOptions, WalletInfo, ContractDeployOptions, ContractReadOptions, ContractWriteOptions, ContractEventFilter, ContractEvent, SIWEMessage, SIWESignatureResult, SIWEVerifyResult, SIWESession, StorageUploadOptions, StorageUploadResult, StorageDownloadOptions, TransactionOptions, TransactionResult, TransactionReceipt, USDCAmount, } from './types';
|
|
15
|
+
export { VarityError, WalletError, ContractError, TransactionError, StorageError, AuthenticationError, } from './types';
|
|
16
|
+
export { formatUSDC, parseUSDC, getUSDCAmount, USDC_DECIMALS, USDC_MULTIPLIER, isValidAddress, formatAddress, shortenAddress, shortenTxHash, getTxUrl, getAddressUrl, formatEther, parseEther, formatGas, formatPercentage, formatNumber, formatTimestamp, getChainName, getBlockExplorerUrl, } from './utils/formatting';
|
|
17
|
+
export { useVarityClient, useVarityWallet, useVarityBalance, useVarityContract, useVarityAuth, useVarityStorage, useVarityChain, } from './react/hooks';
|
|
18
|
+
export { default } from './VarityClient';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Varity JavaScript/TypeScript Client Library
|
|
4
|
+
*
|
|
5
|
+
* Comprehensive SDK for Varity L3 blockchain interactions powered by Thirdweb.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.default = exports.useVarityChain = exports.useVarityStorage = exports.useVarityAuth = exports.useVarityContract = exports.useVarityBalance = exports.useVarityWallet = exports.useVarityClient = exports.getBlockExplorerUrl = exports.getChainName = exports.formatTimestamp = exports.formatNumber = exports.formatPercentage = exports.formatGas = exports.parseEther = exports.formatEther = exports.getAddressUrl = exports.getTxUrl = exports.shortenTxHash = exports.shortenAddress = exports.formatAddress = exports.isValidAddress = exports.USDC_MULTIPLIER = exports.USDC_DECIMALS = exports.getUSDCAmount = exports.parseUSDC = exports.formatUSDC = exports.AuthenticationError = exports.StorageError = exports.TransactionError = exports.ContractError = exports.WalletError = exports.VarityError = exports.StorageManager = exports.SIWEAuth = exports.WalletManager = exports.ContractManager = exports.VarityClientClass = exports.ARBITRUM_ONE_CHAIN = exports.ARBITRUM_SEPOLIA_CHAIN = exports.VARITY_L3_CHAIN = exports.VarityClient = void 0;
|
|
14
|
+
// Main client
|
|
15
|
+
var VarityClient_1 = require("./VarityClient");
|
|
16
|
+
Object.defineProperty(exports, "VarityClient", { enumerable: true, get: function () { return VarityClient_1.VarityClient; } });
|
|
17
|
+
Object.defineProperty(exports, "VARITY_L3_CHAIN", { enumerable: true, get: function () { return VarityClient_1.VARITY_L3_CHAIN; } });
|
|
18
|
+
Object.defineProperty(exports, "ARBITRUM_SEPOLIA_CHAIN", { enumerable: true, get: function () { return VarityClient_1.ARBITRUM_SEPOLIA_CHAIN; } });
|
|
19
|
+
Object.defineProperty(exports, "ARBITRUM_ONE_CHAIN", { enumerable: true, get: function () { return VarityClient_1.ARBITRUM_ONE_CHAIN; } });
|
|
20
|
+
var VarityClient_2 = require("./VarityClient");
|
|
21
|
+
Object.defineProperty(exports, "VarityClientClass", { enumerable: true, get: function () { return __importDefault(VarityClient_2).default; } });
|
|
22
|
+
// Managers
|
|
23
|
+
var ContractManager_1 = require("./contracts/ContractManager");
|
|
24
|
+
Object.defineProperty(exports, "ContractManager", { enumerable: true, get: function () { return ContractManager_1.ContractManager; } });
|
|
25
|
+
var WalletManager_1 = require("./wallet/WalletManager");
|
|
26
|
+
Object.defineProperty(exports, "WalletManager", { enumerable: true, get: function () { return WalletManager_1.WalletManager; } });
|
|
27
|
+
var SIWEAuth_1 = require("./auth/SIWEAuth");
|
|
28
|
+
Object.defineProperty(exports, "SIWEAuth", { enumerable: true, get: function () { return SIWEAuth_1.SIWEAuth; } });
|
|
29
|
+
var StorageManager_1 = require("./storage/StorageManager");
|
|
30
|
+
Object.defineProperty(exports, "StorageManager", { enumerable: true, get: function () { return StorageManager_1.StorageManager; } });
|
|
31
|
+
// Error types
|
|
32
|
+
var types_1 = require("./types");
|
|
33
|
+
Object.defineProperty(exports, "VarityError", { enumerable: true, get: function () { return types_1.VarityError; } });
|
|
34
|
+
Object.defineProperty(exports, "WalletError", { enumerable: true, get: function () { return types_1.WalletError; } });
|
|
35
|
+
Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return types_1.ContractError; } });
|
|
36
|
+
Object.defineProperty(exports, "TransactionError", { enumerable: true, get: function () { return types_1.TransactionError; } });
|
|
37
|
+
Object.defineProperty(exports, "StorageError", { enumerable: true, get: function () { return types_1.StorageError; } });
|
|
38
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return types_1.AuthenticationError; } });
|
|
39
|
+
// Utility functions
|
|
40
|
+
var formatting_1 = require("./utils/formatting");
|
|
41
|
+
// USDC utilities
|
|
42
|
+
Object.defineProperty(exports, "formatUSDC", { enumerable: true, get: function () { return formatting_1.formatUSDC; } });
|
|
43
|
+
Object.defineProperty(exports, "parseUSDC", { enumerable: true, get: function () { return formatting_1.parseUSDC; } });
|
|
44
|
+
Object.defineProperty(exports, "getUSDCAmount", { enumerable: true, get: function () { return formatting_1.getUSDCAmount; } });
|
|
45
|
+
Object.defineProperty(exports, "USDC_DECIMALS", { enumerable: true, get: function () { return formatting_1.USDC_DECIMALS; } });
|
|
46
|
+
Object.defineProperty(exports, "USDC_MULTIPLIER", { enumerable: true, get: function () { return formatting_1.USDC_MULTIPLIER; } });
|
|
47
|
+
// Address utilities
|
|
48
|
+
Object.defineProperty(exports, "isValidAddress", { enumerable: true, get: function () { return formatting_1.isValidAddress; } });
|
|
49
|
+
Object.defineProperty(exports, "formatAddress", { enumerable: true, get: function () { return formatting_1.formatAddress; } });
|
|
50
|
+
Object.defineProperty(exports, "shortenAddress", { enumerable: true, get: function () { return formatting_1.shortenAddress; } });
|
|
51
|
+
// Transaction utilities
|
|
52
|
+
Object.defineProperty(exports, "shortenTxHash", { enumerable: true, get: function () { return formatting_1.shortenTxHash; } });
|
|
53
|
+
Object.defineProperty(exports, "getTxUrl", { enumerable: true, get: function () { return formatting_1.getTxUrl; } });
|
|
54
|
+
Object.defineProperty(exports, "getAddressUrl", { enumerable: true, get: function () { return formatting_1.getAddressUrl; } });
|
|
55
|
+
// Formatting utilities
|
|
56
|
+
Object.defineProperty(exports, "formatEther", { enumerable: true, get: function () { return formatting_1.formatEther; } });
|
|
57
|
+
Object.defineProperty(exports, "parseEther", { enumerable: true, get: function () { return formatting_1.parseEther; } });
|
|
58
|
+
Object.defineProperty(exports, "formatGas", { enumerable: true, get: function () { return formatting_1.formatGas; } });
|
|
59
|
+
Object.defineProperty(exports, "formatPercentage", { enumerable: true, get: function () { return formatting_1.formatPercentage; } });
|
|
60
|
+
Object.defineProperty(exports, "formatNumber", { enumerable: true, get: function () { return formatting_1.formatNumber; } });
|
|
61
|
+
Object.defineProperty(exports, "formatTimestamp", { enumerable: true, get: function () { return formatting_1.formatTimestamp; } });
|
|
62
|
+
// Chain utilities
|
|
63
|
+
Object.defineProperty(exports, "getChainName", { enumerable: true, get: function () { return formatting_1.getChainName; } });
|
|
64
|
+
Object.defineProperty(exports, "getBlockExplorerUrl", { enumerable: true, get: function () { return formatting_1.getBlockExplorerUrl; } });
|
|
65
|
+
// React hooks (optional)
|
|
66
|
+
var hooks_1 = require("./react/hooks");
|
|
67
|
+
Object.defineProperty(exports, "useVarityClient", { enumerable: true, get: function () { return hooks_1.useVarityClient; } });
|
|
68
|
+
Object.defineProperty(exports, "useVarityWallet", { enumerable: true, get: function () { return hooks_1.useVarityWallet; } });
|
|
69
|
+
Object.defineProperty(exports, "useVarityBalance", { enumerable: true, get: function () { return hooks_1.useVarityBalance; } });
|
|
70
|
+
Object.defineProperty(exports, "useVarityContract", { enumerable: true, get: function () { return hooks_1.useVarityContract; } });
|
|
71
|
+
Object.defineProperty(exports, "useVarityAuth", { enumerable: true, get: function () { return hooks_1.useVarityAuth; } });
|
|
72
|
+
Object.defineProperty(exports, "useVarityStorage", { enumerable: true, get: function () { return hooks_1.useVarityStorage; } });
|
|
73
|
+
Object.defineProperty(exports, "useVarityChain", { enumerable: true, get: function () { return hooks_1.useVarityChain; } });
|
|
74
|
+
// Default export
|
|
75
|
+
var VarityClient_3 = require("./VarityClient");
|
|
76
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(VarityClient_3).default; } });
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Hooks for Varity Client
|
|
3
|
+
*
|
|
4
|
+
* Provides easy-to-use React hooks for blockchain interactions
|
|
5
|
+
*/
|
|
6
|
+
import { VarityClient } from '../VarityClient';
|
|
7
|
+
import type { VarityClientConfig, WalletConnectionOptions, WalletInfo, ContractReadOptions, ContractWriteOptions, SIWESession, StorageUploadOptions, StorageUploadResult } from '../types';
|
|
8
|
+
import type { Account } from 'thirdweb/wallets';
|
|
9
|
+
/**
|
|
10
|
+
* useVarityClient - Create and manage Varity client instance
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* function App() {
|
|
15
|
+
* const client = useVarityClient({ chain: 'varity-l3' });
|
|
16
|
+
*
|
|
17
|
+
* return <div>Chain: {client.getChainName()}</div>;
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function useVarityClient(config?: VarityClientConfig): VarityClient;
|
|
22
|
+
/**
|
|
23
|
+
* useVarityWallet - Manage wallet connection and state
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* function WalletButton() {
|
|
28
|
+
* const { connect, disconnect, isConnected, account, balance } = useVarityWallet(client);
|
|
29
|
+
*
|
|
30
|
+
* if (isConnected) {
|
|
31
|
+
* return <button onClick={disconnect}>Disconnect ({balance})</button>;
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* return <button onClick={() => connect({ walletType: 'metamask' })}>Connect</button>;
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function useVarityWallet(client: VarityClient): {
|
|
39
|
+
connect: (options: WalletConnectionOptions) => Promise<void>;
|
|
40
|
+
disconnect: () => void;
|
|
41
|
+
isConnected: boolean;
|
|
42
|
+
isConnecting: boolean;
|
|
43
|
+
account: Account | null;
|
|
44
|
+
walletInfo: WalletInfo | null;
|
|
45
|
+
address: string | null;
|
|
46
|
+
balance: string;
|
|
47
|
+
chainId: number | null;
|
|
48
|
+
refreshBalance: () => Promise<void>;
|
|
49
|
+
error: Error | null;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* useVarityBalance - Track wallet balance with auto-refresh
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* function BalanceDisplay() {
|
|
57
|
+
* const { balance, isLoading, refresh } = useVarityBalance(client);
|
|
58
|
+
*
|
|
59
|
+
* return (
|
|
60
|
+
* <div>
|
|
61
|
+
* Balance: {balance}
|
|
62
|
+
* <button onClick={refresh}>Refresh</button>
|
|
63
|
+
* </div>
|
|
64
|
+
* );
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function useVarityBalance(client: VarityClient, autoRefresh?: boolean, refreshInterval?: number): {
|
|
69
|
+
balance: string;
|
|
70
|
+
isLoading: boolean;
|
|
71
|
+
error: Error | null;
|
|
72
|
+
refresh: () => Promise<void>;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* useVarityContract - Interact with smart contracts
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* function TokenBalance() {
|
|
80
|
+
* const { read, write, isLoading } = useVarityContract(client, account);
|
|
81
|
+
*
|
|
82
|
+
* const balance = read({
|
|
83
|
+
* address: '0x...',
|
|
84
|
+
* abi: ERC20_ABI,
|
|
85
|
+
* functionName: 'balanceOf',
|
|
86
|
+
* args: ['0x...']
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* return <div>Balance: {balance}</div>;
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare function useVarityContract(client: VarityClient, account: Account | null): {
|
|
94
|
+
read: (options: ContractReadOptions) => Promise<any>;
|
|
95
|
+
write: (options: ContractWriteOptions) => Promise<import("../types").TransactionResult>;
|
|
96
|
+
isLoading: boolean;
|
|
97
|
+
error: Error | null;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* useVarityAuth - Manage SIWE authentication
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* function AuthButton() {
|
|
105
|
+
* const { signIn, signOut, isAuthenticated, session } = useVarityAuth(client, account);
|
|
106
|
+
*
|
|
107
|
+
* if (isAuthenticated) {
|
|
108
|
+
* return <button onClick={signOut}>Sign Out</button>;
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* return <button onClick={signIn}>Sign In with Ethereum</button>;
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function useVarityAuth(client: VarityClient, account: Account | null): {
|
|
116
|
+
signIn: (statement?: string) => Promise<SIWESession>;
|
|
117
|
+
signOut: () => void;
|
|
118
|
+
isAuthenticated: boolean;
|
|
119
|
+
session: SIWESession | null;
|
|
120
|
+
isLoading: boolean;
|
|
121
|
+
error: Error | null;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* useVarityStorage - Upload and download from IPFS
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* function FileUpload() {
|
|
129
|
+
* const { upload, isUploading, uploadProgress } = useVarityStorage(client);
|
|
130
|
+
*
|
|
131
|
+
* const handleUpload = async (file: File) => {
|
|
132
|
+
* const result = await upload(file);
|
|
133
|
+
* console.log('Uploaded to:', result.gateway);
|
|
134
|
+
* };
|
|
135
|
+
*
|
|
136
|
+
* return <input type="file" onChange={(e) => handleUpload(e.target.files[0])} />;
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function useVarityStorage(client: VarityClient): {
|
|
141
|
+
upload: (file: File | Blob | Buffer | string, options?: StorageUploadOptions) => Promise<StorageUploadResult>;
|
|
142
|
+
download: (cid: string) => Promise<any>;
|
|
143
|
+
uploadJSON: (data: any, options?: StorageUploadOptions) => Promise<StorageUploadResult>;
|
|
144
|
+
isUploading: boolean;
|
|
145
|
+
uploadProgress: number;
|
|
146
|
+
error: Error | null;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* useVarityChain - Monitor chain information
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* function ChainInfo() {
|
|
154
|
+
* const { chainId, chainName, isVarityL3 } = useVarityChain(client);
|
|
155
|
+
*
|
|
156
|
+
* return <div>Connected to: {chainName} (ID: {chainId})</div>;
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function useVarityChain(client: VarityClient): {
|
|
161
|
+
chainId: number;
|
|
162
|
+
chainName: string;
|
|
163
|
+
rpcUrl: string;
|
|
164
|
+
nativeCurrency: {
|
|
165
|
+
name?: string;
|
|
166
|
+
symbol?: string;
|
|
167
|
+
decimals?: number;
|
|
168
|
+
};
|
|
169
|
+
isVarityL3: boolean;
|
|
170
|
+
};
|