@mysten/docs 0.1.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 +24 -0
- package/dist/bcs/index.md +358 -0
- package/dist/bcs/llms-index.md +4 -0
- package/dist/codegen/index.md +441 -0
- package/dist/codegen/llms-index.md +4 -0
- package/dist/dapp-kit/actions/connect-wallet.md +69 -0
- package/dist/dapp-kit/actions/disconnect-wallet.md +38 -0
- package/dist/dapp-kit/actions/sign-and-execute-transaction.md +96 -0
- package/dist/dapp-kit/actions/sign-personal-message.md +58 -0
- package/dist/dapp-kit/actions/sign-transaction.md +65 -0
- package/dist/dapp-kit/actions/switch-account.md +37 -0
- package/dist/dapp-kit/actions/switch-network.md +37 -0
- package/dist/dapp-kit/dapp-kit-instance.md +162 -0
- package/dist/dapp-kit/getting-started/create-dapp.md +151 -0
- package/dist/dapp-kit/getting-started/next-js.md +162 -0
- package/dist/dapp-kit/getting-started/react.md +172 -0
- package/dist/dapp-kit/getting-started/vue.md +193 -0
- package/dist/dapp-kit/index.md +70 -0
- package/dist/dapp-kit/llms-index.md +26 -0
- package/dist/dapp-kit/react/components/connect-button.md +42 -0
- package/dist/dapp-kit/react/components/connect-modal.md +51 -0
- package/dist/dapp-kit/react/components/index.md +13 -0
- package/dist/dapp-kit/react/dapp-kit-provider.md +86 -0
- package/dist/dapp-kit/react/hooks/index.md +25 -0
- package/dist/dapp-kit/react/hooks/use-current-account.md +33 -0
- package/dist/dapp-kit/react/hooks/use-current-client.md +36 -0
- package/dist/dapp-kit/react/hooks/use-current-network.md +28 -0
- package/dist/dapp-kit/react/hooks/use-current-wallet.md +36 -0
- package/dist/dapp-kit/react/hooks/use-dapp-kit.md +100 -0
- package/dist/dapp-kit/react/hooks/use-wallet-connection.md +48 -0
- package/dist/dapp-kit/react/hooks/use-wallets.md +33 -0
- package/dist/dapp-kit/state.md +169 -0
- package/dist/dapp-kit/theming.md +196 -0
- package/dist/dapp-kit/web-components/connect-button.md +89 -0
- package/dist/dapp-kit/web-components/connect-modal.md +177 -0
- package/dist/kiosk/advanced-examples.md +101 -0
- package/dist/kiosk/from-v1.md +320 -0
- package/dist/kiosk/index.md +22 -0
- package/dist/kiosk/kiosk-client/introduction.md +52 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/examples.md +119 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/kiosk-transaction.md +103 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/managing.md +235 -0
- package/dist/kiosk/kiosk-client/kiosk-transaction/purchasing.md +110 -0
- package/dist/kiosk/kiosk-client/querying.md +237 -0
- package/dist/kiosk/kiosk-client/transfer-policy-transaction/introduction.md +79 -0
- package/dist/kiosk/kiosk-client/transfer-policy-transaction/using-the-manager.md +115 -0
- package/dist/kiosk/llms-index.md +8 -0
- package/dist/llms-index.md +125 -0
- package/dist/payment-kit/getting-started.md +256 -0
- package/dist/payment-kit/index.md +132 -0
- package/dist/payment-kit/llms-index.md +8 -0
- package/dist/payment-kit/payment-kit-sdk.md +747 -0
- package/dist/payment-kit/payment-processing.md +372 -0
- package/dist/payment-kit/registry-management.md +529 -0
- package/dist/seal/index.md +85 -0
- package/dist/seal/llms-index.md +4 -0
- package/dist/slush-wallet/dapp.md +95 -0
- package/dist/slush-wallet/deep-linking.md +465 -0
- package/dist/slush-wallet/index.md +7 -0
- package/dist/slush-wallet/llms-index.md +6 -0
- package/dist/sui/bcs.md +134 -0
- package/dist/sui/clients/core.md +606 -0
- package/dist/sui/clients/graphql.md +101 -0
- package/dist/sui/clients/grpc.md +155 -0
- package/dist/sui/clients/index.md +95 -0
- package/dist/sui/clients/json-rpc.md +239 -0
- package/dist/sui/cryptography/keypairs.md +267 -0
- package/dist/sui/cryptography/multisig.md +194 -0
- package/dist/sui/cryptography/passkey.md +111 -0
- package/dist/sui/cryptography/webcrypto-signer.md +81 -0
- package/dist/sui/executors.md +148 -0
- package/dist/sui/faucet.md +26 -0
- package/dist/sui/hello-sui.md +115 -0
- package/dist/sui/index.md +53 -0
- package/dist/sui/install.md +61 -0
- package/dist/sui/llm-docs.md +32 -0
- package/dist/sui/llms-index.md +44 -0
- package/dist/sui/migrations/0.38.md +58 -0
- package/dist/sui/migrations/sui-1.0.md +455 -0
- package/dist/sui/migrations/sui-2.0/agent-prompt.md +42 -0
- package/dist/sui/migrations/sui-2.0/dapp-kit.md +350 -0
- package/dist/sui/migrations/sui-2.0/deepbook-v3.md +33 -0
- package/dist/sui/migrations/sui-2.0/index.md +158 -0
- package/dist/sui/migrations/sui-2.0/json-rpc-migration.md +386 -0
- package/dist/sui/migrations/sui-2.0/kiosk.md +120 -0
- package/dist/sui/migrations/sui-2.0/sdk-maintainers.md +90 -0
- package/dist/sui/migrations/sui-2.0/seal.md +14 -0
- package/dist/sui/migrations/sui-2.0/sui.md +341 -0
- package/dist/sui/migrations/sui-2.0/suins.md +43 -0
- package/dist/sui/migrations/sui-2.0/wallet-builders.md +66 -0
- package/dist/sui/migrations/sui-2.0/walrus.md +41 -0
- package/dist/sui/migrations/sui-2.0/zksend.md +95 -0
- package/dist/sui/plugins.md +258 -0
- package/dist/sui/sdk-building.md +344 -0
- package/dist/sui/transaction-building/basics.md +299 -0
- package/dist/sui/transaction-building/gas.md +62 -0
- package/dist/sui/transaction-building/intents.md +62 -0
- package/dist/sui/transaction-building/offline.md +73 -0
- package/dist/sui/transaction-building/sponsored-transactions.md +22 -0
- package/dist/sui/utils/derived_objects.md +59 -0
- package/dist/sui/utils/index.md +52 -0
- package/dist/sui/zklogin.md +83 -0
- package/dist/walrus/index.md +527 -0
- package/dist/walrus/llms-index.md +4 -0
- package/dist/zksend/index.md +27 -0
- package/dist/zksend/link-builder.md +192 -0
- package/dist/zksend/llms-index.md +5 -0
- package/package.json +66 -0
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
# Payment Kit SDK
|
|
2
|
+
|
|
3
|
+
> Payment Kit SDK API reference and configuration
|
|
4
|
+
|
|
5
|
+
> **Note:** This package is in active development and should be used with caution. APIs are experimental and
|
|
6
|
+
> subject to breaking changes without notice. We recommend thoroughly testing any implementation
|
|
7
|
+
> before using in production environments.
|
|
8
|
+
|
|
9
|
+
Complete API reference for the Payment Kit SDK.
|
|
10
|
+
|
|
11
|
+
## Client Setup
|
|
12
|
+
|
|
13
|
+
### PaymentKitClient
|
|
14
|
+
|
|
15
|
+
The main client class that provides access to Payment Kit functionality.
|
|
16
|
+
|
|
17
|
+
#### `paymentKit()`
|
|
18
|
+
|
|
19
|
+
Function to create a Payment Kit client extension for `SuiGrpcClient`.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
paymentKit<Name extends string = 'paymentKit'>({
|
|
23
|
+
name = 'paymentKit' as Name,
|
|
24
|
+
}): SuiClientRegistration<PaymentKitCompatibleClient, Name, PaymentKitClient>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Example:**
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
|
|
31
|
+
const client = new SuiGrpcClient({
|
|
32
|
+
network: 'testnet',
|
|
33
|
+
baseUrl: 'https://fullnode.testnet.sui.io:443',
|
|
34
|
+
}).$extend(paymentKit());
|
|
35
|
+
|
|
36
|
+
// Access Payment Kit functionality
|
|
37
|
+
client.paymentKit.tx.processRegistryPayment(/* ... */);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Supported Networks:**
|
|
41
|
+
|
|
42
|
+
- `testnet`
|
|
43
|
+
- `mainnet`
|
|
44
|
+
|
|
45
|
+
**Throws:**
|
|
46
|
+
|
|
47
|
+
- `PaymentKitClientError` if network is unsupported
|
|
48
|
+
|
|
49
|
+
## Transaction Methods
|
|
50
|
+
|
|
51
|
+
Transaction methods create complete, ready-to-sign transactions.
|
|
52
|
+
|
|
53
|
+
### `client.paymentKit.tx.processRegistryPayment()`
|
|
54
|
+
|
|
55
|
+
Create a transaction to process a registry-based payment.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
processRegistryPayment(
|
|
59
|
+
options: ProcessRegistryPaymentOptions
|
|
60
|
+
): Transaction
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Parameters:**
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
type ProcessRegistryPaymentOptions = {
|
|
67
|
+
nonce: string; // Unique payment identifier
|
|
68
|
+
coinType: string; // Coin type (e.g., '0x2::sui::SUI')
|
|
69
|
+
amount: number | bigint; // Amount in smallest unit
|
|
70
|
+
receiver: string; // Recipient address
|
|
71
|
+
sender: string; // Sender address (must match signer)
|
|
72
|
+
} & Partial<Registry>;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Returns:** `Transaction` - Ready-to-sign transaction
|
|
76
|
+
|
|
77
|
+
**Note:** If you rather provide the `registryId` you can do so instead of the `registryName`.
|
|
78
|
+
|
|
79
|
+
**Example:**
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const tx = client.paymentKit.tx.processRegistryPayment({
|
|
83
|
+
nonce: crypto.randomUUID(),
|
|
84
|
+
coinType: '0x2::sui::SUI',
|
|
85
|
+
amount: 1000000000,
|
|
86
|
+
receiver,
|
|
87
|
+
sender: senderAddress,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const result = await client.signAndExecuteTransaction({
|
|
91
|
+
transaction: tx,
|
|
92
|
+
signer: keypair,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Check transaction status
|
|
96
|
+
if (result.$kind === 'FailedTransaction') {
|
|
97
|
+
throw new Error(`Payment failed: ${result.FailedTransaction.status.error?.message}`);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**On-Chain Effects:**
|
|
102
|
+
|
|
103
|
+
- Transfers coins from sender to receiver
|
|
104
|
+
- Creates a `PaymentRecord` dynamic field on the registry
|
|
105
|
+
- Emits a `PaymentReceipt` event
|
|
106
|
+
|
|
107
|
+
**Throws:**
|
|
108
|
+
|
|
109
|
+
- Error if payment with same key already exists
|
|
110
|
+
- Error if sender has insufficient balance
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
### `client.paymentKit.tx.processEphemeralPayment()`
|
|
115
|
+
|
|
116
|
+
Create a transaction to process an ephemeral payment (no registry storage).
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
processEphemeralPayment(
|
|
120
|
+
options: ProcessEphemeralPaymentOptions
|
|
121
|
+
): Transaction
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Parameters:**
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
type ProcessEphemeralPaymentOptions = {
|
|
128
|
+
nonce: string; // Payment identifier (not enforced for uniqueness)
|
|
129
|
+
coinType: string; // Coin type
|
|
130
|
+
amount: number | bigint; // Amount in smallest unit
|
|
131
|
+
receiver: string; // Recipient address
|
|
132
|
+
sender: string; // Sender address (must match signer)
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Returns:** `Transaction` - Ready-to-sign transaction
|
|
137
|
+
|
|
138
|
+
**Example:**
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const tx = client.paymentKit.tx.processEphemeralPayment({
|
|
142
|
+
nonce: crypto.randomUUID(),
|
|
143
|
+
coinType: '0x2::sui::SUI',
|
|
144
|
+
amount: 500000000,
|
|
145
|
+
receiver,
|
|
146
|
+
sender: senderAddress,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const result = await client.signAndExecuteTransaction({
|
|
150
|
+
transaction: tx,
|
|
151
|
+
signer: keypair,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Check transaction status
|
|
155
|
+
if (result.$kind === 'FailedTransaction') {
|
|
156
|
+
throw new Error(`Ephemeral payment failed: ${result.FailedTransaction.status.error?.message}`);
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**On-Chain Effects:**
|
|
161
|
+
|
|
162
|
+
- Transfers coins from sender to receiver
|
|
163
|
+
- Emits a `PaymentReceipt` event
|
|
164
|
+
- No `PaymentRecord` created (no duplicate prevention)
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### `client.paymentKit.tx.createRegistry()`
|
|
169
|
+
|
|
170
|
+
Create a transaction to create a new payment registry.
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
createRegistry(options: CreateRegistryOptions): Transaction
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Parameters:**
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
type CreateRegistryOptions = {
|
|
180
|
+
registryName: string; // Unique name for the registry
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Returns:** `Transaction` - Ready-to-sign transaction
|
|
185
|
+
|
|
186
|
+
**Example:**
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
const tx = client.paymentKit.tx.createRegistry({
|
|
190
|
+
registryName: 'my-payment-registry',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const result = await client.signAndExecuteTransaction({
|
|
194
|
+
transaction: tx,
|
|
195
|
+
signer: keypair,
|
|
196
|
+
options: {
|
|
197
|
+
showObjectChanges: true,
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Extract the RegistryAdminCap from result.Transaction.objectChanges
|
|
202
|
+
const adminCap = result.Transaction.objectChanges?.find(
|
|
203
|
+
(change) => change.type === 'created' && change.objectType.includes('RegistryAdminCap'),
|
|
204
|
+
);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**On-Chain Effects:**
|
|
208
|
+
|
|
209
|
+
- Creates a `PaymentRegistry` object
|
|
210
|
+
- Creates a `RegistryAdminCap` owned by sender
|
|
211
|
+
- Registry ID is deterministically derived from name
|
|
212
|
+
|
|
213
|
+
**Important:**
|
|
214
|
+
|
|
215
|
+
- Registry names must be unique globally
|
|
216
|
+
- Save the `RegistryAdminCap` object ID for configuration operations
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
### `client.paymentKit.tx.setConfigEpochExpirationDuration()`
|
|
221
|
+
|
|
222
|
+
Create a transaction to set the epoch expiration duration for payment records.
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
setConfigEpochExpirationDuration(
|
|
226
|
+
options: SetEpochExpirationDurationOptions
|
|
227
|
+
): Transaction
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**Parameters:**
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
type SetEpochExpirationDurationOptions = {
|
|
234
|
+
epochExpirationDuration: number | bigint; // Number of epochs before records expire
|
|
235
|
+
adminCapId: string; // Admin capability object ID
|
|
236
|
+
} & Partial<Registry>;
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
**Returns:** `Transaction` - Ready-to-sign transaction
|
|
240
|
+
|
|
241
|
+
**Example:**
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
const tx = client.paymentKit.tx.setConfigEpochExpirationDuration({
|
|
245
|
+
registryName: 'my-registry',
|
|
246
|
+
epochExpirationDuration: 60,
|
|
247
|
+
adminCapId: adminCapId,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
await client.signAndExecuteTransaction({
|
|
251
|
+
transaction: tx,
|
|
252
|
+
signer: keypair,
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
**Requires:**
|
|
257
|
+
|
|
258
|
+
- Transaction signer must own the admin capability
|
|
259
|
+
|
|
260
|
+
**Default:** 30 epochs
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
### `client.paymentKit.tx.setConfigRegistryManagedFunds()`
|
|
265
|
+
|
|
266
|
+
Create a transaction to enable/disable registry-managed funds.
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
setConfigRegistryManagedFunds(
|
|
270
|
+
options: SetRegistryManagedFundsOptions
|
|
271
|
+
): Transaction
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**Parameters:**
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
type SetRegistryManagedFundsOptions = {
|
|
278
|
+
registryManagedFunds: boolean; // Enable (true) or disable (false)
|
|
279
|
+
adminCapId: string; // Admin capability object ID
|
|
280
|
+
} & Partial<Registry>;
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**Returns:** `Transaction` - Ready-to-sign transaction
|
|
284
|
+
|
|
285
|
+
**Example:**
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
const tx = client.paymentKit.tx.setConfigRegistryManagedFunds({
|
|
289
|
+
registryName: 'my-registry',
|
|
290
|
+
registryManagedFunds: true,
|
|
291
|
+
adminCapId: adminCapId,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
await client.signAndExecuteTransaction({
|
|
295
|
+
transaction: tx,
|
|
296
|
+
signer: keypair,
|
|
297
|
+
});
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**When Enabled:**
|
|
301
|
+
|
|
302
|
+
- Payment receiver must be the registry itself
|
|
303
|
+
- Funds accumulate in the registry
|
|
304
|
+
- Admin can withdraw funds later
|
|
305
|
+
|
|
306
|
+
**Default:** Disabled (funds go directly to receivers)
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
### `client.paymentKit.tx.withdrawFromRegistry()`
|
|
311
|
+
|
|
312
|
+
Create a transaction to withdraw accumulated funds from a registry.
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
withdrawFromRegistry(
|
|
316
|
+
options: WithdrawFromRegistryOptions
|
|
317
|
+
): Transaction
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Parameters:**
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
type WithdrawFromRegistryOptions = {
|
|
324
|
+
coinType: string; // Coin type to withdraw
|
|
325
|
+
adminCapId: string; // Admin capability object ID
|
|
326
|
+
} & Partial<Registry>;
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**Returns:** `Transaction` - Ready-to-sign transaction
|
|
330
|
+
|
|
331
|
+
**Example:**
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
const tx = client.paymentKit.tx.withdrawFromRegistry({
|
|
335
|
+
coinType: '0x2::sui::SUI',
|
|
336
|
+
registryName: 'my-registry',
|
|
337
|
+
adminCapId: adminCapId,
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const result = await client.signAndExecuteTransaction({
|
|
341
|
+
transaction: tx,
|
|
342
|
+
signer: keypair,
|
|
343
|
+
});
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**Requires:**
|
|
347
|
+
|
|
348
|
+
- Registry must have `registryManagedFunds` enabled
|
|
349
|
+
- Transaction signer must own the admin capability
|
|
350
|
+
|
|
351
|
+
**Effect:**
|
|
352
|
+
|
|
353
|
+
- Withdraws all coins of specified type to the sender
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
### `client.paymentKit.tx.deletePaymentRecord()`
|
|
358
|
+
|
|
359
|
+
Create a transaction to delete an expired payment record.
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
deletePaymentRecord(
|
|
363
|
+
options: DeletePaymentRecordOptions
|
|
364
|
+
): Transaction
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Parameters:**
|
|
368
|
+
|
|
369
|
+
```ts
|
|
370
|
+
type DeletePaymentRecordOptions = {
|
|
371
|
+
nonce: string; // Payment nonce
|
|
372
|
+
coinType: string; // Coin type of the payment
|
|
373
|
+
amount: number | bigint; // Payment amount
|
|
374
|
+
receiver: string; // Payment receiver
|
|
375
|
+
} & Partial<Registry>;
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
**Returns:** `Transaction` - Ready-to-sign transaction
|
|
379
|
+
|
|
380
|
+
**Example:**
|
|
381
|
+
|
|
382
|
+
```ts
|
|
383
|
+
const tx = client.paymentKit.tx.deletePaymentRecord({
|
|
384
|
+
nonce: crypto.randomUUID(),
|
|
385
|
+
coinType: '0x2::sui::SUI',
|
|
386
|
+
amount: 1000000000,
|
|
387
|
+
receiver,
|
|
388
|
+
registryName: 'my-registry',
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
const result = await client.signAndExecuteTransaction({
|
|
392
|
+
transaction: tx,
|
|
393
|
+
signer: keypair,
|
|
394
|
+
});
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
**Requires:**
|
|
398
|
+
|
|
399
|
+
- Payment record must be expired (current epoch >= record epoch + expiration duration)
|
|
400
|
+
- Anyone can delete expired records (permissionless)
|
|
401
|
+
|
|
402
|
+
**Effect:**
|
|
403
|
+
|
|
404
|
+
- Removes the payment record from the registry
|
|
405
|
+
- Sender receives storage rebate
|
|
406
|
+
|
|
407
|
+
## Query Methods
|
|
408
|
+
|
|
409
|
+
### `client.paymentKit.getPaymentRecord()`
|
|
410
|
+
|
|
411
|
+
Query the blockchain for a payment record.
|
|
412
|
+
|
|
413
|
+
```ts
|
|
414
|
+
async getPaymentRecord(
|
|
415
|
+
options: GetPaymentRecordOptions
|
|
416
|
+
): Promise<GetPaymentRecordResponse | null>
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**Parameters:**
|
|
420
|
+
|
|
421
|
+
```ts
|
|
422
|
+
type GetPaymentRecordOptions = {
|
|
423
|
+
nonce: string; // Payment nonce
|
|
424
|
+
coinType: string; // Coin type
|
|
425
|
+
amount: number | bigint; // Payment amount
|
|
426
|
+
receiver: string; // Payment receiver
|
|
427
|
+
} & Partial<Registry>;
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
**Returns:**
|
|
431
|
+
|
|
432
|
+
```ts
|
|
433
|
+
type GetPaymentRecordResponse = {
|
|
434
|
+
key: string; // Dynamic field object ID
|
|
435
|
+
paymentTransactionDigest: string | null; // Transaction that created the record
|
|
436
|
+
epochAtTimeOfRecord: string; // Epoch when record was created
|
|
437
|
+
} | null; // null if record doesn't exist
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
**Example:**
|
|
441
|
+
|
|
442
|
+
```ts
|
|
443
|
+
const record = await client.paymentKit.getPaymentRecord({
|
|
444
|
+
nonce: crypto.randomUUID(),
|
|
445
|
+
coinType: '0x2::sui::SUI',
|
|
446
|
+
amount: 1000000000,
|
|
447
|
+
receiver,
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
if (record) {
|
|
451
|
+
console.log('Payment exists!');
|
|
452
|
+
console.log('Transaction:', record.paymentTransactionDigest);
|
|
453
|
+
console.log('Created at epoch:', record.epochAtTimeOfRecord);
|
|
454
|
+
} else {
|
|
455
|
+
console.log('Payment not found');
|
|
456
|
+
}
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
**Use Cases:**
|
|
460
|
+
|
|
461
|
+
- Verify a payment was completed
|
|
462
|
+
- Check for duplicate payments before processing
|
|
463
|
+
- Retrieve payment details for reconciliation
|
|
464
|
+
|
|
465
|
+
## Call Methods
|
|
466
|
+
|
|
467
|
+
Call methods return transaction commands that can be composed in custom transactions. Use these when
|
|
468
|
+
you need fine-grained control over transaction construction.
|
|
469
|
+
|
|
470
|
+
### `client.paymentKit.calls.processRegistryPayment()`
|
|
471
|
+
|
|
472
|
+
Returns a transaction command for registry-based payment.
|
|
473
|
+
|
|
474
|
+
```ts
|
|
475
|
+
processRegistryPayment(
|
|
476
|
+
options: ProcessRegistryPaymentOptions
|
|
477
|
+
): TransactionObjectArgument
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
**Example:**
|
|
481
|
+
|
|
482
|
+
```ts
|
|
483
|
+
|
|
484
|
+
const tx = new Transaction();
|
|
485
|
+
|
|
486
|
+
// Add custom logic before payment
|
|
487
|
+
tx.moveCall({
|
|
488
|
+
target: '0xMyPackage::my_module::pre_payment_check',
|
|
489
|
+
arguments: [
|
|
490
|
+
/* ... */
|
|
491
|
+
],
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// Add payment command
|
|
495
|
+
tx.add(
|
|
496
|
+
client.paymentKit.calls.processRegistryPayment({
|
|
497
|
+
nonce: crypto.randomUUID(),
|
|
498
|
+
coinType: '0x2::sui::SUI',
|
|
499
|
+
amount: 1000000000,
|
|
500
|
+
receiver,
|
|
501
|
+
sender: senderAddress,
|
|
502
|
+
}),
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
// Add custom logic after payment
|
|
506
|
+
tx.moveCall({
|
|
507
|
+
target: '0xMyPackage::my_module::post_payment_action',
|
|
508
|
+
arguments: [
|
|
509
|
+
/* ... */
|
|
510
|
+
],
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
await client.signAndExecuteTransaction({
|
|
514
|
+
transaction: tx,
|
|
515
|
+
signer: keypair,
|
|
516
|
+
});
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Other Call Methods
|
|
520
|
+
|
|
521
|
+
All transaction methods have corresponding call methods:
|
|
522
|
+
|
|
523
|
+
- `client.paymentKit.calls.processEphemeralPayment()`
|
|
524
|
+
- `client.paymentKit.calls.createRegistry()`
|
|
525
|
+
- `client.paymentKit.calls.setConfigEpochExpirationDuration()`
|
|
526
|
+
- `client.paymentKit.calls.setConfigRegistryManagedFunds()`
|
|
527
|
+
- `client.paymentKit.calls.withdrawFromRegistry()`
|
|
528
|
+
- `client.paymentKit.calls.deletePaymentRecord()`
|
|
529
|
+
|
|
530
|
+
## Types
|
|
531
|
+
|
|
532
|
+
### PaymentReceipt Event
|
|
533
|
+
|
|
534
|
+
Emitted when a payment is processed (registry or ephemeral).
|
|
535
|
+
|
|
536
|
+
```ts
|
|
537
|
+
type PaymentReceipt = {
|
|
538
|
+
payment_type: 'Registry' | 'Ephemeral'; // Payment model used
|
|
539
|
+
nonce: string; // Payment identifier
|
|
540
|
+
amount: string; // Amount (as string)
|
|
541
|
+
receiver: string; // Recipient address
|
|
542
|
+
coin_type: string; // Coin type
|
|
543
|
+
timestamp_ms: string; // Unix timestamp in ms
|
|
544
|
+
};
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
**Extracting from Transaction Result:**
|
|
548
|
+
|
|
549
|
+
```ts
|
|
550
|
+
const result = await client.signAndExecuteTransaction({
|
|
551
|
+
transaction: tx,
|
|
552
|
+
signer: keypair,
|
|
553
|
+
options: {
|
|
554
|
+
showEvents: true,
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
const receiptEvent = result.Transaction.events?.find((event) =>
|
|
559
|
+
event.type.includes('PaymentReceipt'),
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
if (receiptEvent) {
|
|
563
|
+
const receipt = receiptEvent.parsedJson as PaymentReceipt;
|
|
564
|
+
console.log('Payment Type:', receipt.payment_type);
|
|
565
|
+
console.log('Nonce:', receipt.nonce);
|
|
566
|
+
console.log('Amount:', receipt.amount);
|
|
567
|
+
}
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
## Error Handling
|
|
571
|
+
|
|
572
|
+
### PaymentKitClientError
|
|
573
|
+
|
|
574
|
+
Custom error class for Payment Kit errors.
|
|
575
|
+
|
|
576
|
+
```ts
|
|
577
|
+
class PaymentKitClientError extends Error {
|
|
578
|
+
constructor(message: string);
|
|
579
|
+
}
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
## URI Utilities
|
|
583
|
+
|
|
584
|
+
Payment Kit provides utility functions for creating and parsing payment transaction URIs. These URIs
|
|
585
|
+
follow the `sui:pay` protocol and can be used to encode payment parameters for QR codes, deep links,
|
|
586
|
+
or other sharing mechanisms.
|
|
587
|
+
|
|
588
|
+
### URI Format
|
|
589
|
+
|
|
590
|
+
Payment URIs follow the `sui:pay` protocol:
|
|
591
|
+
|
|
592
|
+
```
|
|
593
|
+
sui:pay?
|
|
594
|
+
receiver=<address>
|
|
595
|
+
&amount=<amount>
|
|
596
|
+
&coinType=<coinType>
|
|
597
|
+
&nonce=<nonce>
|
|
598
|
+
®istry=<registryIdOrName>
|
|
599
|
+
&label=<label>
|
|
600
|
+
&message=<message>
|
|
601
|
+
&iconUrl=<url>
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
**Required Parameters:**
|
|
605
|
+
|
|
606
|
+
| Parameter | Description |
|
|
607
|
+
| ---------- | -------------------------------------------- |
|
|
608
|
+
| `receiver` | Recipient Sui address |
|
|
609
|
+
| `amount` | Payment amount in smallest unit (e.g., MIST) |
|
|
610
|
+
| `coinType` | Coin type (e.g., `0x2::sui::SUI`) |
|
|
611
|
+
| `nonce` | Unique payment identifier (max 36 chars) |
|
|
612
|
+
|
|
613
|
+
**Optional Parameters:**
|
|
614
|
+
|
|
615
|
+
| Parameter | Description |
|
|
616
|
+
| ---------- | ----------------------------------------------- |
|
|
617
|
+
| `registry` | Registry ID or name for registry-based payments |
|
|
618
|
+
| `label` | Human-readable label for the payment |
|
|
619
|
+
| `message` | Message or memo for the payment |
|
|
620
|
+
| `iconUrl` | URL to an icon image for display purposes |
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
### `createPaymentTransactionUri()`
|
|
625
|
+
|
|
626
|
+
Creates a payment transaction URI from the given parameters.
|
|
627
|
+
|
|
628
|
+
```ts
|
|
629
|
+
createPaymentTransactionUri(params: PaymentUriParams): string
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
**Parameters:**
|
|
633
|
+
|
|
634
|
+
```ts
|
|
635
|
+
type PaymentUriParams = {
|
|
636
|
+
receiverAddress: string; // Recipient Sui address
|
|
637
|
+
amount: bigint; // Amount in smallest unit
|
|
638
|
+
coinType: string; // Coin type (e.g., '0x2::sui::SUI')
|
|
639
|
+
nonce: string; // Unique identifier (max 36 chars)
|
|
640
|
+
label?: string; // Optional human-readable label
|
|
641
|
+
message?: string; // Optional message/memo
|
|
642
|
+
iconUrl?: string; // Optional icon URL
|
|
643
|
+
} & Partial<Registry>;
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
**Returns:** `string` - The constructed payment URI
|
|
647
|
+
|
|
648
|
+
**Example:**
|
|
649
|
+
|
|
650
|
+
```ts
|
|
651
|
+
|
|
652
|
+
// Create a URI for a registry-based payment
|
|
653
|
+
const uri = createPaymentTransactionUri({
|
|
654
|
+
receiverAddress: '0x1234...abcd',
|
|
655
|
+
amount: 1000000000n, // 1 SUI
|
|
656
|
+
coinType: '0x2::sui::SUI',
|
|
657
|
+
nonce: crypto.randomUUID(),
|
|
658
|
+
registryName: 'my-payment-registry',
|
|
659
|
+
label: 'Coffee Purchase',
|
|
660
|
+
message: 'Thanks for your order!',
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
// Result:
|
|
664
|
+
// sui:pay?
|
|
665
|
+
// receiver=0x1234...
|
|
666
|
+
// &amount=1000000000
|
|
667
|
+
// &coinType=0x2::sui::SUI
|
|
668
|
+
// &nonce=abc-123-def
|
|
669
|
+
// ®istry=my-payment-registry
|
|
670
|
+
// &label=Coffee+Purchase
|
|
671
|
+
// &message=Thanks+for+your+order!
|
|
672
|
+
|
|
673
|
+
// Create a URI for an ephemeral payment (no registry)
|
|
674
|
+
const ephemeralUri = createPaymentTransactionUri({
|
|
675
|
+
receiverAddress: '0x1234...abcd',
|
|
676
|
+
amount: 500000000n, // 0.5 SUI
|
|
677
|
+
coinType: '0x2::sui::SUI',
|
|
678
|
+
nonce: crypto.randomUUID(),
|
|
679
|
+
});
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
**Throws:**
|
|
683
|
+
|
|
684
|
+
- `PaymentKitUriError` if receiver address is invalid
|
|
685
|
+
- `PaymentKitUriError` if amount is not positive
|
|
686
|
+
- `PaymentKitUriError` if coin type is invalid
|
|
687
|
+
- `PaymentKitUriError` if nonce is missing or exceeds 36 characters
|
|
688
|
+
- `PaymentKitUriError` if registry ID is not a valid Sui object ID
|
|
689
|
+
|
|
690
|
+
---
|
|
691
|
+
|
|
692
|
+
### `parsePaymentTransactionUri()`
|
|
693
|
+
|
|
694
|
+
Parses a payment transaction URI into its component parameters.
|
|
695
|
+
|
|
696
|
+
```ts
|
|
697
|
+
parsePaymentTransactionUri(uri: string): PaymentUriParams
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
**Parameters:**
|
|
701
|
+
|
|
702
|
+
| Parameter | Type | Description |
|
|
703
|
+
| --------- | -------- | ------------------------ |
|
|
704
|
+
| `uri` | `string` | The payment URI to parse |
|
|
705
|
+
|
|
706
|
+
**Returns:** `PaymentUriParams` - The parsed payment parameters
|
|
707
|
+
|
|
708
|
+
**Example:**
|
|
709
|
+
|
|
710
|
+
```ts
|
|
711
|
+
|
|
712
|
+
const uri =
|
|
713
|
+
'sui:pay?receiver=0x1234...&amount=1000000000&coinType=0x2::sui::SUI&nonce=abc123®istry=my-registry';
|
|
714
|
+
|
|
715
|
+
const params = parsePaymentTransactionUri(uri);
|
|
716
|
+
|
|
717
|
+
console.log(params.receiverAddress); // '0x1234...'
|
|
718
|
+
console.log(params.amount); // 1000000000n (bigint)
|
|
719
|
+
console.log(params.coinType); // '0x2::sui::SUI'
|
|
720
|
+
console.log(params.nonce); // 'abc123'
|
|
721
|
+
console.log(params.registryName); // 'my-registry'
|
|
722
|
+
|
|
723
|
+
// Use parsed params to process a payment
|
|
724
|
+
const tx = client.paymentKit.tx.processRegistryPayment({
|
|
725
|
+
receiver: params.receiverAddress,
|
|
726
|
+
amount: params.amount,
|
|
727
|
+
coinType: params.coinType,
|
|
728
|
+
nonce: params.nonce,
|
|
729
|
+
registryName: params.registryName!,
|
|
730
|
+
sender: senderAddress,
|
|
731
|
+
});
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
**Throws:**
|
|
735
|
+
|
|
736
|
+
- `PaymentKitUriError` if URI doesn't start with `sui:pay?`
|
|
737
|
+
- `PaymentKitUriError` if required parameters are missing
|
|
738
|
+
- `PaymentKitUriError` if receiver address is invalid
|
|
739
|
+
- `PaymentKitUriError` if coin type is invalid
|
|
740
|
+
- `PaymentKitUriError` if nonce exceeds 36 characters
|
|
741
|
+
- `PaymentKitUriError` if amount is not a positive number
|
|
742
|
+
|
|
743
|
+
### Future Versions
|
|
744
|
+
|
|
745
|
+
Check the
|
|
746
|
+
[CHANGELOG](https://github.com/MystenLabs/ts-sdks/blob/main/packages/payment-kit/CHANGELOG.md) for
|
|
747
|
+
updates.
|