anchor-sdk 0.1.36
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 +21 -0
- package/README.md +735 -0
- package/dist/AnchorApiClient.d.ts +203 -0
- package/dist/AnchorApiClient.js +279 -0
- package/dist/AnchorApiClientV2.d.ts +270 -0
- package/dist/AnchorApiClientV2.js +424 -0
- package/dist/AnchorERC1155Client.d.ts +85 -0
- package/dist/AnchorERC1155Client.js +280 -0
- package/dist/AnchorPayClient.d.ts +79 -0
- package/dist/AnchorPayClient.js +217 -0
- package/dist/abi/AnchorERC1155.d.ts +1359 -0
- package/dist/abi/AnchorERC1155.js +1122 -0
- package/dist/abi/AnchorPay.json +452 -0
- package/dist/api/AnchorApiHttpClient.d.ts +210 -0
- package/dist/api/AnchorApiHttpClient.js +411 -0
- package/dist/api/types.d.ts +764 -0
- package/dist/api/types.js +2 -0
- package/dist/constants.d.ts +49 -0
- package/dist/constants.js +221 -0
- package/dist/generated/Api.d.ts +1083 -0
- package/dist/generated/Api.js +571 -0
- package/dist/index.d.ts +341 -0
- package/dist/index.js +1377 -0
- package/dist/react/AnchorReactSDK.d.ts +59 -0
- package/dist/react/AnchorReactSDK.js +181 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +8 -0
- package/dist/typechain/AnchorERC1155.d.ts +999 -0
- package/dist/typechain/AnchorERC1155.js +2 -0
- package/dist/typechain/AnchorPay.d.ts +242 -0
- package/dist/typechain/AnchorPay.js +2 -0
- package/dist/typechain/common.d.ts +50 -0
- package/dist/typechain/common.js +2 -0
- package/dist/typechain/factories/AnchorERC1155__factory.d.ts +1365 -0
- package/dist/typechain/factories/AnchorERC1155__factory.js +1766 -0
- package/dist/typechain/factories/AnchorPay__factory.d.ts +358 -0
- package/dist/typechain/factories/AnchorPay__factory.js +469 -0
- package/dist/typechain/factories/index.d.ts +2 -0
- package/dist/typechain/factories/index.js +10 -0
- package/dist/typechain/index.d.ts +5 -0
- package/dist/typechain/index.js +41 -0
- package/dist/types.d.ts +109 -0
- package/dist/types.js +2 -0
- package/package.json +87 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { Address, type TransactionReceipt } from "viem";
|
|
2
|
+
import { AnchorPayClient } from "./AnchorPayClient";
|
|
3
|
+
import { AnchorERC1155Client } from "./AnchorERC1155Client";
|
|
4
|
+
import { AnchorApiClientV2 } from "./AnchorApiClientV2";
|
|
5
|
+
import { AnchorSDKConfig, PaymentOptions, SignedMintRequest } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Anchor SDK
|
|
8
|
+
* 用于与 AnchorPay 和 AnchorERC1155 合约交互的 SDK
|
|
9
|
+
*/
|
|
10
|
+
export declare class AnchorSDK {
|
|
11
|
+
private publicClient;
|
|
12
|
+
private walletClient?;
|
|
13
|
+
private account?;
|
|
14
|
+
private network;
|
|
15
|
+
private config;
|
|
16
|
+
/** Anchor 合约地址 */
|
|
17
|
+
private contracts;
|
|
18
|
+
/** AnchorPay 客户端 */
|
|
19
|
+
anchorPay: AnchorPayClient;
|
|
20
|
+
/** AnchorERC1155 客户端 */
|
|
21
|
+
anchorERC1155: AnchorERC1155Client;
|
|
22
|
+
/** Anchor API 客户端 */
|
|
23
|
+
anchorApi?: AnchorApiClientV2;
|
|
24
|
+
/**
|
|
25
|
+
* 创建 Anchor SDK 实例
|
|
26
|
+
* @param config SDK 配置
|
|
27
|
+
*/
|
|
28
|
+
constructor(config: AnchorSDKConfig);
|
|
29
|
+
/**
|
|
30
|
+
* 设置 Token 过期回调
|
|
31
|
+
* @param callback Token 过期回调函数
|
|
32
|
+
*/
|
|
33
|
+
setTokenExpiredCallback(callback: (error: Error) => void): void;
|
|
34
|
+
/**
|
|
35
|
+
* 设置钱包客户端
|
|
36
|
+
* 在 SDK 初始化后动态更新钱包客户端和账户
|
|
37
|
+
* @param walletClient 新的钱包客户端
|
|
38
|
+
*/
|
|
39
|
+
setWalletClient(signerOrWalletClient: any): this;
|
|
40
|
+
/**
|
|
41
|
+
* 初始化公共客户端
|
|
42
|
+
* @param provider 提供者(URL或Web3提供者)
|
|
43
|
+
* @returns 公共客户端
|
|
44
|
+
*/
|
|
45
|
+
private initializePublicClient;
|
|
46
|
+
/**
|
|
47
|
+
* 初始化钱包客户端
|
|
48
|
+
* @param signer 签名者
|
|
49
|
+
* @returns 钱包客户端
|
|
50
|
+
*/
|
|
51
|
+
private initializeWalletClient;
|
|
52
|
+
/**
|
|
53
|
+
* 从签名者获取账户
|
|
54
|
+
* @param signer 签名者
|
|
55
|
+
* @returns 账户
|
|
56
|
+
*/
|
|
57
|
+
private getAccountFromSigner;
|
|
58
|
+
/**
|
|
59
|
+
* 从网络信息创建Chain对象
|
|
60
|
+
* @param network 网络信息
|
|
61
|
+
* @returns Chain对象
|
|
62
|
+
*/
|
|
63
|
+
private createChainFromNetwork;
|
|
64
|
+
/**
|
|
65
|
+
* 购买 Badge(使用 ETH,直接使用签名请求)
|
|
66
|
+
* @param signedRequest 签名铸造请求
|
|
67
|
+
* @param receiptAddress 接收地址,如果提供,将作为 ERC20 转账的接收地址使用
|
|
68
|
+
* @param options 支付选项
|
|
69
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
70
|
+
*/
|
|
71
|
+
buyBadgeWithETHWithSignedRequest(signedRequest: SignedMintRequest, receiptAddress: string, options?: PaymentOptions): Promise<TransactionReceipt | {
|
|
72
|
+
to: string;
|
|
73
|
+
data: string;
|
|
74
|
+
value: bigint;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* 购买 Badge(使用 ERC20 代币,直接使用签名请求)
|
|
78
|
+
* @param signedRequest 签名铸造请求
|
|
79
|
+
* @param receiptAddress 接收地址,如果提供,将作为接收地址使用
|
|
80
|
+
* @param options 支付选项
|
|
81
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
82
|
+
*/
|
|
83
|
+
buyBadgeWithERC20WithSignedRequest(signedRequest: SignedMintRequest, receiptAddress: string, options?: PaymentOptions): Promise<TransactionReceipt | {
|
|
84
|
+
to: string;
|
|
85
|
+
data: string;
|
|
86
|
+
value: bigint;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* 使用 ETH 购买徽章
|
|
90
|
+
* @param customerAddress 客户地址
|
|
91
|
+
* @param contractAddress NFT 地址
|
|
92
|
+
* @param tokenId 代币 ID
|
|
93
|
+
* @param quantity 数量
|
|
94
|
+
* @param receiptAddress 接收地址,如果提供,将作为接收地址使用
|
|
95
|
+
* @param options 支付选项
|
|
96
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
97
|
+
*/
|
|
98
|
+
buyBadgeWithETH(customerAddress: string, contractAddress: string, tokenId: string | number | bigint, quantity: string | number | bigint | undefined, receiptAddress: string, options?: PaymentOptions): Promise<TransactionReceipt | {
|
|
99
|
+
to: string;
|
|
100
|
+
data: string;
|
|
101
|
+
value: bigint;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* 使用自定义签名数据购买徽章(ETH)
|
|
105
|
+
* @param signedRequest 用户自己组装的签名铸造请求
|
|
106
|
+
* @param receiptAddress 接收地址,如果提供,将作为接收地址使用
|
|
107
|
+
* @param options 支付选项
|
|
108
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
109
|
+
*/
|
|
110
|
+
buyBadgeWithETHWithCustomSignature(signedRequest: {
|
|
111
|
+
to: string;
|
|
112
|
+
tokenId: string | number | bigint;
|
|
113
|
+
quantity: string | number | bigint;
|
|
114
|
+
price: string | number | bigint;
|
|
115
|
+
currency?: string;
|
|
116
|
+
validityEndTimestamp?: string | number | bigint;
|
|
117
|
+
validityStartTimestamp?: string | number | bigint;
|
|
118
|
+
uid: string;
|
|
119
|
+
signature: string;
|
|
120
|
+
chainId?: string;
|
|
121
|
+
projectHandle?: string;
|
|
122
|
+
}, receiptAddress: string, options?: PaymentOptions): Promise<TransactionReceipt | {
|
|
123
|
+
to: string;
|
|
124
|
+
data: string;
|
|
125
|
+
value: bigint;
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* 使用 ERC20 代币购买徽章
|
|
129
|
+
* @param customerAddress 客户地址
|
|
130
|
+
* @param contractAddress NFT 地址
|
|
131
|
+
* @param tokenId 代币 ID
|
|
132
|
+
* @param quantity 数量
|
|
133
|
+
* @param currency ERC20 代币地址
|
|
134
|
+
* @param receiptAddress 接收地址,如果提供,将作为接收地址使用
|
|
135
|
+
* @param options 支付选项
|
|
136
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
137
|
+
*/
|
|
138
|
+
buyBadgeWithERC20(customerAddress: string, contractAddress: string, tokenId: string | number | bigint, quantity: string | number | bigint | undefined, currency: string, receiptAddress: string, options?: PaymentOptions): Promise<TransactionReceipt | {
|
|
139
|
+
to: string;
|
|
140
|
+
data: string;
|
|
141
|
+
value: bigint;
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* 使用自定义签名数据购买徽章(ERC20)
|
|
145
|
+
* @param signedRequest 用户自己组装的签名铸造请求
|
|
146
|
+
* @param receiptAddress 接收地址,如果提供,将作为 ERC20 转账的接收地址使用
|
|
147
|
+
* @param options 支付选项
|
|
148
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
149
|
+
*/
|
|
150
|
+
buyBadgeWithERC20WithCustomSignature(signedRequest: {
|
|
151
|
+
to: string;
|
|
152
|
+
tokenId: string | number | bigint;
|
|
153
|
+
quantity: string | number | bigint;
|
|
154
|
+
price: string | number | bigint;
|
|
155
|
+
currency?: string;
|
|
156
|
+
validityEndTimestamp?: string | number | bigint;
|
|
157
|
+
validityStartTimestamp?: string | number | bigint;
|
|
158
|
+
uid: string;
|
|
159
|
+
signature: string;
|
|
160
|
+
chainId?: string;
|
|
161
|
+
projectHandle?: string;
|
|
162
|
+
}, receiptAddress: string, options?: PaymentOptions): Promise<TransactionReceipt | {
|
|
163
|
+
to: string;
|
|
164
|
+
data: string;
|
|
165
|
+
value: bigint;
|
|
166
|
+
}>;
|
|
167
|
+
/**
|
|
168
|
+
* 支付方法,使用 ETH 进行支付
|
|
169
|
+
* @deprecated 请使用 sendPayment 方法代替。sendPayment 提供了更灵活的支付选项和更好的类型支持。
|
|
170
|
+
* @param orderId 订单 ID
|
|
171
|
+
* @param amount 支付金额
|
|
172
|
+
* @param receiptAddress 接收地址,如果提供,将作为接收地址使用
|
|
173
|
+
* @param options 支付选项
|
|
174
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
175
|
+
*/
|
|
176
|
+
pay(orderId: string, amount: string | number | bigint, receiptAddress: string, options?: PaymentOptions): Promise<TransactionReceipt | {
|
|
177
|
+
to: string;
|
|
178
|
+
data: string;
|
|
179
|
+
value: bigint;
|
|
180
|
+
}>;
|
|
181
|
+
/**
|
|
182
|
+
* 支付方法,使用 ETH 进行支付
|
|
183
|
+
* @param params 支付参数
|
|
184
|
+
* @param params.callData 自定义数据
|
|
185
|
+
* @param params.amount 支付金额
|
|
186
|
+
* @param params.receiptAddress 接收地址
|
|
187
|
+
* @param params.contractName 合约名称(可选)
|
|
188
|
+
* @param params.options 支付选项(可选)
|
|
189
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
190
|
+
*/
|
|
191
|
+
sendPaymentWithNativeToken(params: {
|
|
192
|
+
callData: `0x${string}`;
|
|
193
|
+
amount: string | number | bigint;
|
|
194
|
+
receiptAddress: string;
|
|
195
|
+
contractName?: string;
|
|
196
|
+
options?: PaymentOptions;
|
|
197
|
+
}): Promise<TransactionReceipt | {
|
|
198
|
+
to: string;
|
|
199
|
+
data: string;
|
|
200
|
+
value: bigint;
|
|
201
|
+
}>;
|
|
202
|
+
/**
|
|
203
|
+
* 支付方法,使用 ERC20 代币进行支付
|
|
204
|
+
* @param params 支付参数
|
|
205
|
+
* @param params.callData 自定义数据
|
|
206
|
+
* @param params.amount 支付金额
|
|
207
|
+
* @param params.receiptAddress 接收地址
|
|
208
|
+
* @param params.tokenAddress ERC20 代币地址
|
|
209
|
+
* @param params.contractName 合约名称(可选)
|
|
210
|
+
* @param params.options 支付选项(可选)
|
|
211
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据数组
|
|
212
|
+
*/
|
|
213
|
+
sendPaymentWithERC20(params: {
|
|
214
|
+
callData: `0x${string}`;
|
|
215
|
+
amount: string | number | bigint;
|
|
216
|
+
receiptAddress: string;
|
|
217
|
+
tokenAddress: string;
|
|
218
|
+
contractName?: string;
|
|
219
|
+
options?: PaymentOptions;
|
|
220
|
+
}): Promise<TransactionReceipt | {
|
|
221
|
+
to: string;
|
|
222
|
+
data: string;
|
|
223
|
+
value: bigint;
|
|
224
|
+
}>;
|
|
225
|
+
/**
|
|
226
|
+
* 编码用户数据
|
|
227
|
+
* @param orderId 订单 ID
|
|
228
|
+
* @returns 编码后的数据
|
|
229
|
+
*/
|
|
230
|
+
private encodeUserData;
|
|
231
|
+
/**
|
|
232
|
+
* 铸造免费 Badge
|
|
233
|
+
* 从后端获取签名铸造请求,然后调用合约铸造
|
|
234
|
+
* @param customerAddress 客户地址
|
|
235
|
+
* @param contractAddress NFT 地址
|
|
236
|
+
* @param tokenIds badge 的 tokenId 数组
|
|
237
|
+
* @param options 选项,可以控制是否直接发送交易
|
|
238
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
239
|
+
*/
|
|
240
|
+
mintFreeBadge(customerAddress: string, contractAddress: string, tokenIds: string[], options?: {
|
|
241
|
+
sendTransaction?: boolean;
|
|
242
|
+
}): Promise<TransactionReceipt | {
|
|
243
|
+
to: string;
|
|
244
|
+
data: string;
|
|
245
|
+
value: bigint;
|
|
246
|
+
} | {
|
|
247
|
+
to: string;
|
|
248
|
+
data: string;
|
|
249
|
+
value: bigint;
|
|
250
|
+
}[]>;
|
|
251
|
+
/**
|
|
252
|
+
* 铸造免费 Badge(直接使用签名请求)
|
|
253
|
+
* @param signedRequest 签名铸造请求
|
|
254
|
+
* @param options 选项,可以控制是否直接发送交易
|
|
255
|
+
* @returns 如果直接发送交易,返回交易收据;否则返回交易数据
|
|
256
|
+
*/
|
|
257
|
+
mintFreeBadgeWithSignedRequest(signedRequest: SignedMintRequest, options?: {
|
|
258
|
+
sendTransaction?: boolean;
|
|
259
|
+
}): Promise<TransactionReceipt | {
|
|
260
|
+
to: string;
|
|
261
|
+
data: string;
|
|
262
|
+
value: bigint;
|
|
263
|
+
}>;
|
|
264
|
+
/**
|
|
265
|
+
* 获取 ERC20 代币批准的交易数据(用于 AA 模式)
|
|
266
|
+
* @param tokenAddress ERC20 代币地址
|
|
267
|
+
* @param amount 批准金额
|
|
268
|
+
* @param spender 花费者地址(默认为 AnchorPay 合约地址)
|
|
269
|
+
* @returns 交易数据对象,包含 to、data 和 value 字段
|
|
270
|
+
*/
|
|
271
|
+
getERC20ApprovalData(tokenAddress: Address, amount: bigint, spender?: Address): {
|
|
272
|
+
to: string;
|
|
273
|
+
data: string;
|
|
274
|
+
value: bigint;
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* 验证铸造请求
|
|
278
|
+
* @param request 铸造请求
|
|
279
|
+
*/
|
|
280
|
+
private validateMintRequest;
|
|
281
|
+
/**
|
|
282
|
+
* 处理交易哈希
|
|
283
|
+
* 在交易确认后调用该方法可加快交易处理
|
|
284
|
+
* @param txHash 交易哈希
|
|
285
|
+
* @returns 处理结果或 undefined(如果 API 客户端不可用)
|
|
286
|
+
*/
|
|
287
|
+
processTransactionHash(txHash: string): Promise<import("./generated/Api").WebResultTransactionHashProcess | undefined>;
|
|
288
|
+
/**
|
|
289
|
+
* 批量铸造徽章(V2)
|
|
290
|
+
* @param customerAddress 客户地址
|
|
291
|
+
* @param contractAddress NFT 合约地址
|
|
292
|
+
* @param tokenIds 代币 ID 列表
|
|
293
|
+
* @param options 选项,可以控制是否直接发送交易
|
|
294
|
+
* @returns 如果直接发送交易,返回最后一个交易收据;AA 模式返回所有交易数据数组
|
|
295
|
+
*/
|
|
296
|
+
batchMintBadge(customerAddress: string, contractAddress: string, tokenIds: string[], options?: {
|
|
297
|
+
sendTransaction?: boolean;
|
|
298
|
+
}): Promise<TransactionReceipt | {
|
|
299
|
+
to: string;
|
|
300
|
+
data: string;
|
|
301
|
+
value: bigint;
|
|
302
|
+
}[]>;
|
|
303
|
+
/**
|
|
304
|
+
* 批量铸造徽章(Multicall V2)
|
|
305
|
+
* @param customerAddress 客户地址
|
|
306
|
+
* @param contractAddress NFT 合约地址
|
|
307
|
+
* @param tokenIds 代币 ID 列表
|
|
308
|
+
* @param options 选项,可以控制是否直接发送交易
|
|
309
|
+
* @returns 如果直接发送交易,返回交易收据;AA 模式返回 multicall 交易数据
|
|
310
|
+
*/
|
|
311
|
+
batchMintBadgeWithMulticall(customerAddress: string, contractAddress: string, tokenIds: string[], options?: {
|
|
312
|
+
sendTransaction?: boolean;
|
|
313
|
+
}): Promise<TransactionReceipt | {
|
|
314
|
+
to: string;
|
|
315
|
+
data: string;
|
|
316
|
+
value: bigint;
|
|
317
|
+
}>;
|
|
318
|
+
/**
|
|
319
|
+
* 批量铸造免费徽章(Multicall)
|
|
320
|
+
* 从后端获取签名铸造请求,然后使用 multicall 批量铸造
|
|
321
|
+
* @param customerAddress 客户地址
|
|
322
|
+
* @param contractAddress NFT 合约地址
|
|
323
|
+
* @param tokenIds badge 的 tokenId 数组
|
|
324
|
+
* @param options 选项,可以控制是否直接发送交易
|
|
325
|
+
* @returns 如果直接发送交易,返回交易收据;AA 模式返回 multicall 交易数据
|
|
326
|
+
*/
|
|
327
|
+
mintFreeBadgeWithMulticall(customerAddress: string, contractAddress: string, tokenIds: string[], options?: {
|
|
328
|
+
sendTransaction?: boolean;
|
|
329
|
+
}): Promise<TransactionReceipt | {
|
|
330
|
+
to: string;
|
|
331
|
+
data: string;
|
|
332
|
+
value: bigint;
|
|
333
|
+
}>;
|
|
334
|
+
}
|
|
335
|
+
export * from "./types";
|
|
336
|
+
export * from "./constants";
|
|
337
|
+
export { AnchorPayClient } from "./AnchorPayClient";
|
|
338
|
+
export { AnchorApiClientV2 } from "./AnchorApiClientV2";
|
|
339
|
+
export { AnchorERC1155Client } from "./AnchorERC1155Client";
|
|
340
|
+
export * from "./react";
|
|
341
|
+
export * from "./generated/Api";
|