@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.
Files changed (108) hide show
  1. package/README.md +24 -0
  2. package/dist/bcs/index.md +358 -0
  3. package/dist/bcs/llms-index.md +4 -0
  4. package/dist/codegen/index.md +441 -0
  5. package/dist/codegen/llms-index.md +4 -0
  6. package/dist/dapp-kit/actions/connect-wallet.md +69 -0
  7. package/dist/dapp-kit/actions/disconnect-wallet.md +38 -0
  8. package/dist/dapp-kit/actions/sign-and-execute-transaction.md +96 -0
  9. package/dist/dapp-kit/actions/sign-personal-message.md +58 -0
  10. package/dist/dapp-kit/actions/sign-transaction.md +65 -0
  11. package/dist/dapp-kit/actions/switch-account.md +37 -0
  12. package/dist/dapp-kit/actions/switch-network.md +37 -0
  13. package/dist/dapp-kit/dapp-kit-instance.md +162 -0
  14. package/dist/dapp-kit/getting-started/create-dapp.md +151 -0
  15. package/dist/dapp-kit/getting-started/next-js.md +162 -0
  16. package/dist/dapp-kit/getting-started/react.md +172 -0
  17. package/dist/dapp-kit/getting-started/vue.md +193 -0
  18. package/dist/dapp-kit/index.md +70 -0
  19. package/dist/dapp-kit/llms-index.md +26 -0
  20. package/dist/dapp-kit/react/components/connect-button.md +42 -0
  21. package/dist/dapp-kit/react/components/connect-modal.md +51 -0
  22. package/dist/dapp-kit/react/components/index.md +13 -0
  23. package/dist/dapp-kit/react/dapp-kit-provider.md +86 -0
  24. package/dist/dapp-kit/react/hooks/index.md +25 -0
  25. package/dist/dapp-kit/react/hooks/use-current-account.md +33 -0
  26. package/dist/dapp-kit/react/hooks/use-current-client.md +36 -0
  27. package/dist/dapp-kit/react/hooks/use-current-network.md +28 -0
  28. package/dist/dapp-kit/react/hooks/use-current-wallet.md +36 -0
  29. package/dist/dapp-kit/react/hooks/use-dapp-kit.md +100 -0
  30. package/dist/dapp-kit/react/hooks/use-wallet-connection.md +48 -0
  31. package/dist/dapp-kit/react/hooks/use-wallets.md +33 -0
  32. package/dist/dapp-kit/state.md +169 -0
  33. package/dist/dapp-kit/theming.md +196 -0
  34. package/dist/dapp-kit/web-components/connect-button.md +89 -0
  35. package/dist/dapp-kit/web-components/connect-modal.md +177 -0
  36. package/dist/kiosk/advanced-examples.md +101 -0
  37. package/dist/kiosk/from-v1.md +320 -0
  38. package/dist/kiosk/index.md +22 -0
  39. package/dist/kiosk/kiosk-client/introduction.md +52 -0
  40. package/dist/kiosk/kiosk-client/kiosk-transaction/examples.md +119 -0
  41. package/dist/kiosk/kiosk-client/kiosk-transaction/kiosk-transaction.md +103 -0
  42. package/dist/kiosk/kiosk-client/kiosk-transaction/managing.md +235 -0
  43. package/dist/kiosk/kiosk-client/kiosk-transaction/purchasing.md +110 -0
  44. package/dist/kiosk/kiosk-client/querying.md +237 -0
  45. package/dist/kiosk/kiosk-client/transfer-policy-transaction/introduction.md +79 -0
  46. package/dist/kiosk/kiosk-client/transfer-policy-transaction/using-the-manager.md +115 -0
  47. package/dist/kiosk/llms-index.md +8 -0
  48. package/dist/llms-index.md +125 -0
  49. package/dist/payment-kit/getting-started.md +256 -0
  50. package/dist/payment-kit/index.md +132 -0
  51. package/dist/payment-kit/llms-index.md +8 -0
  52. package/dist/payment-kit/payment-kit-sdk.md +747 -0
  53. package/dist/payment-kit/payment-processing.md +372 -0
  54. package/dist/payment-kit/registry-management.md +529 -0
  55. package/dist/seal/index.md +85 -0
  56. package/dist/seal/llms-index.md +4 -0
  57. package/dist/slush-wallet/dapp.md +95 -0
  58. package/dist/slush-wallet/deep-linking.md +465 -0
  59. package/dist/slush-wallet/index.md +7 -0
  60. package/dist/slush-wallet/llms-index.md +6 -0
  61. package/dist/sui/bcs.md +134 -0
  62. package/dist/sui/clients/core.md +606 -0
  63. package/dist/sui/clients/graphql.md +101 -0
  64. package/dist/sui/clients/grpc.md +155 -0
  65. package/dist/sui/clients/index.md +95 -0
  66. package/dist/sui/clients/json-rpc.md +239 -0
  67. package/dist/sui/cryptography/keypairs.md +267 -0
  68. package/dist/sui/cryptography/multisig.md +194 -0
  69. package/dist/sui/cryptography/passkey.md +111 -0
  70. package/dist/sui/cryptography/webcrypto-signer.md +81 -0
  71. package/dist/sui/executors.md +148 -0
  72. package/dist/sui/faucet.md +26 -0
  73. package/dist/sui/hello-sui.md +115 -0
  74. package/dist/sui/index.md +53 -0
  75. package/dist/sui/install.md +61 -0
  76. package/dist/sui/llm-docs.md +32 -0
  77. package/dist/sui/llms-index.md +44 -0
  78. package/dist/sui/migrations/0.38.md +58 -0
  79. package/dist/sui/migrations/sui-1.0.md +455 -0
  80. package/dist/sui/migrations/sui-2.0/agent-prompt.md +42 -0
  81. package/dist/sui/migrations/sui-2.0/dapp-kit.md +350 -0
  82. package/dist/sui/migrations/sui-2.0/deepbook-v3.md +33 -0
  83. package/dist/sui/migrations/sui-2.0/index.md +158 -0
  84. package/dist/sui/migrations/sui-2.0/json-rpc-migration.md +386 -0
  85. package/dist/sui/migrations/sui-2.0/kiosk.md +120 -0
  86. package/dist/sui/migrations/sui-2.0/sdk-maintainers.md +90 -0
  87. package/dist/sui/migrations/sui-2.0/seal.md +14 -0
  88. package/dist/sui/migrations/sui-2.0/sui.md +341 -0
  89. package/dist/sui/migrations/sui-2.0/suins.md +43 -0
  90. package/dist/sui/migrations/sui-2.0/wallet-builders.md +66 -0
  91. package/dist/sui/migrations/sui-2.0/walrus.md +41 -0
  92. package/dist/sui/migrations/sui-2.0/zksend.md +95 -0
  93. package/dist/sui/plugins.md +258 -0
  94. package/dist/sui/sdk-building.md +344 -0
  95. package/dist/sui/transaction-building/basics.md +299 -0
  96. package/dist/sui/transaction-building/gas.md +62 -0
  97. package/dist/sui/transaction-building/intents.md +62 -0
  98. package/dist/sui/transaction-building/offline.md +73 -0
  99. package/dist/sui/transaction-building/sponsored-transactions.md +22 -0
  100. package/dist/sui/utils/derived_objects.md +59 -0
  101. package/dist/sui/utils/index.md +52 -0
  102. package/dist/sui/zklogin.md +83 -0
  103. package/dist/walrus/index.md +527 -0
  104. package/dist/walrus/llms-index.md +4 -0
  105. package/dist/zksend/index.md +27 -0
  106. package/dist/zksend/link-builder.md +192 -0
  107. package/dist/zksend/llms-index.md +5 -0
  108. package/package.json +66 -0
@@ -0,0 +1,372 @@
1
+ # Payment Processing
2
+
3
+ > Process payments and handle transaction results
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
+ Payment Kit provides two distinct payment processing models, each designed for different use cases.
10
+ This guide explains how each model works and when to use them.
11
+
12
+ ## Payment Models Overview
13
+
14
+ ### Registry-Based Payments
15
+
16
+ Registry-based payments create a persistent `PaymentRecord` stored on-chain in a `PaymentRegistry`.
17
+ This model provides:
18
+
19
+ - **Duplicate Prevention**: A payment with the same parameters can only be processed once
20
+ - **Verifiable Proof**: On-chain proof that a payment was made
21
+ - **Expiration Management**: Records can be deleted after a configurable period
22
+ - **Centralized Tracking**: All payments are indexed under a specific registry
23
+
24
+ **When to Use:**
25
+
26
+ - E-commerce checkouts
27
+ - Subscription payments
28
+ - Invoice payments
29
+ - Any scenario requiring duplicate prevention
30
+
31
+ ### Ephemeral Payments
32
+
33
+ Ephemeral payments process transfers without creating persistent on-chain records. This model
34
+ provides:
35
+
36
+ - **Lower Gas Costs**: No on-chain storage means cheaper transactions
37
+ - **Flexibility**: No registry configuration required
38
+
39
+ **When to Use:**
40
+
41
+ - Tipping/donations
42
+ - Recurring payments with external tracking
43
+ - High-frequency microtransactions
44
+ - Scenarios where duplicate prevention is handled off-chain
45
+
46
+ ## How Payment Keys Work
47
+
48
+ Payment Kit uses a composite key system to uniquely identify payments. Understanding this is crucial
49
+ for using the SDK effectively.
50
+
51
+ ### Payment Key Components
52
+
53
+ A payment key is derived from four parameters:
54
+
55
+ ```ts
56
+ type PaymentKeyArgs = {
57
+ nonce: string; // Unique identifier you provide
58
+ amount: number; // Payment amount in smallest unit
59
+ receiver: string; // Recipient address
60
+ coinType: string; // Coin type being transferred
61
+ };
62
+ ```
63
+
64
+ ### Key Generation
65
+
66
+ When you process a registry payment, Payment Kit hashes these parameters to create a unique key:
67
+
68
+ ```ts
69
+ // These parameters create a unique payment key
70
+ const paymentParams = {
71
+ nonce: 'b5e88aec-d88e-4961-9204-6c84e0e1de4e',
72
+ amount: 1000000000,
73
+ receiver,
74
+ coinType: '0x2::sui::SUI',
75
+ };
76
+
77
+ // If you try to process the same payment twice, it will fail
78
+ const tx1 = client.paymentKit.tx.processRegistryPayment({
79
+ ...paymentParams,
80
+ sender: senderAddress,
81
+ registryName: 'my-registry',
82
+ });
83
+
84
+ // This will fail - same payment key
85
+ const tx2 = client.paymentKit.tx.processRegistryPayment({
86
+ ...paymentParams,
87
+ sender: senderAddress,
88
+ registryName: 'my-registry',
89
+ });
90
+ ```
91
+
92
+ ### Changing Any Component Creates a New Key
93
+
94
+ Each component affects the payment key. Changing any parameter creates a different payment. This
95
+ means, as an example, that a `nonce` can be reused for a different payment, if the `coinType` or
96
+ `receiver` differ.
97
+
98
+ ```ts
99
+ // Original payment
100
+ const originalNonce = crypto.randomUUID();
101
+
102
+ const payment1 = {
103
+ nonce: originalNonce,
104
+ amount: 1000000000,
105
+ receiver,
106
+ coinType: '0x2::sui::SUI',
107
+ };
108
+
109
+ // Different nonce = different payment
110
+ const payment2 = {
111
+ nonce: crypto.randomUUID(), // Changed
112
+ amount: 1000000000,
113
+ receiver,
114
+ coinType: '0x2::sui::SUI',
115
+ };
116
+
117
+ // Different amount = different payment
118
+ const payment3 = {
119
+ nonce: originalNonce,
120
+ amount: 2000000000, // Changed
121
+ receiver,
122
+ coinType: '0x2::sui::SUI',
123
+ };
124
+
125
+ // All three are unique payments that can be processed separately
126
+ ```
127
+
128
+ ## Processing Registry-Based Payments
129
+
130
+ Let's walk through a complete registry payment workflow:
131
+
132
+ ### Step 1: Create the Transaction
133
+
134
+ ```ts
135
+ // Define your payment parameters
136
+ const paymentParams = {
137
+ nonce: crypto.randomUUID(), // Your unique payment ID
138
+ coinType: '0x2::sui::SUI', // SUI token
139
+ amount: 1000000000, // 1 SUI (in MIST)
140
+ receiver,
141
+ sender: senderAddress, // Must match signer
142
+ };
143
+
144
+ // Create the transaction
145
+ const tx = client.paymentKit.tx.processRegistryPayment(paymentParams);
146
+ ```
147
+
148
+ ### What Happens On-Chain
149
+
150
+ When this transaction executes, Payment Kit:
151
+
152
+ 1. **Validates** the payment parameters
153
+ 2. **Checks** if a payment with this key already exists in the registry
154
+ 3. **Transfers** the coins from sender to receiver
155
+ 4. **Creates** a `PaymentRecord` dynamic field on the registry
156
+ 5. **Emits** a `PaymentReceipt` event
157
+
158
+ ### Step 2: Execute the Transaction
159
+
160
+ ```ts
161
+ const result = await client.signAndExecuteTransaction({
162
+ transaction: tx,
163
+ signer: keypair,
164
+ options: {
165
+ showEffects: true,
166
+ showEvents: true,
167
+ showObjectChanges: true,
168
+ },
169
+ });
170
+
171
+ // Check transaction status
172
+ if (result.$kind === 'FailedTransaction') {
173
+ throw new Error(`Payment failed: ${result.FailedTransaction.status.error?.message}`);
174
+ }
175
+
176
+ console.log('Transaction digest:', result.Transaction.digest);
177
+ ```
178
+
179
+ ### Step 3: Extract the Receipt
180
+
181
+ ```ts
182
+ // Find the PaymentReceipt event
183
+ const receiptEvent = result.Transaction.events?.find((event) =>
184
+ event.type.includes('PaymentReceipt'),
185
+ );
186
+
187
+ if (receiptEvent) {
188
+ const receipt = receiptEvent.parsedJson;
189
+
190
+ console.log('Payment Receipt:');
191
+ console.log(' Type:', receipt.payment_type); // 'Registry'
192
+ console.log(' Nonce:', receipt.nonce); // 'crypto.randomUUID()'
193
+ console.log(' Amount:', receipt.amount); // 1n * MIST_PER_SUI
194
+ console.log(' Receiver:', receipt.receiver); //
195
+ console.log(' Coin Type:', receipt.coin_type); // '0x2::sui::SUI'
196
+ console.log(' Timestamp:', receipt.timestamp_ms); // Unix timestamp
197
+ }
198
+ ```
199
+
200
+ ### Step 4: Verify the Payment Record
201
+
202
+ ```ts
203
+ // Query the payment record to confirm it exists
204
+ const record = await client.paymentKit.getPaymentRecord({
205
+ nonce: crypto.randomUUID(),
206
+ coinType: '0x2::sui::SUI',
207
+ amount: 1000000000,
208
+ receiver,
209
+ });
210
+
211
+ if (record) {
212
+ console.log('Payment verified!');
213
+ console.log('Record ID:', record.key);
214
+ console.log('Transaction:', record.paymentTransactionDigest);
215
+ console.log('Epoch:', record.epochAtTimeOfRecord);
216
+ }
217
+ ```
218
+
219
+ ## Processing Ephemeral Payments
220
+
221
+ Ephemeral payments follow a simpler flow without creating persistent records:
222
+
223
+ ### Creating an Ephemeral Payment
224
+
225
+ ```ts
226
+ // No registry needed for ephemeral payments
227
+ const tx = client.paymentKit.tx.processEphemeralPayment({
228
+ nonce: crypto.randomUUID(),
229
+ coinType: '0x2::sui::SUI',
230
+ amount: 500000000, // 0.5 SUI
231
+ receiver,
232
+ sender: senderAddress,
233
+ });
234
+
235
+ const result = await client.signAndExecuteTransaction({
236
+ transaction: tx,
237
+ signer: keypair,
238
+ options: {
239
+ showEvents: true,
240
+ },
241
+ });
242
+
243
+ // Check transaction status
244
+ if (result.$kind === 'FailedTransaction') {
245
+ throw new Error(`Ephemeral payment failed: ${result.FailedTransaction.status.error?.message}`);
246
+ }
247
+ ```
248
+
249
+ ### What Happens On-Chain
250
+
251
+ For ephemeral payments, Payment Kit:
252
+
253
+ 1. **Validates** the payment parameters
254
+ 2. **Transfers** the coins from sender to receiver
255
+ 3. **Emits** a `PaymentReceipt` event
256
+
257
+ **Note:** No `PaymentRecord` is created, so duplicate payments are not prevented.
258
+
259
+ ### Extracting the Receipt
260
+
261
+ ```ts
262
+ const receiptEvent = result.Transaction.events?.find((event) =>
263
+ event.type.includes('PaymentReceipt'),
264
+ );
265
+
266
+ if (receiptEvent) {
267
+ const receipt = receiptEvent.parsedJson;
268
+ console.log('Payment Type:', receipt.payment_type); // 'Ephemeral'
269
+ }
270
+ ```
271
+
272
+ ## Advanced Payment Scenarios
273
+
274
+ ### Processing Multiple Payments in One Transaction
275
+
276
+ You can combine multiple payment operations in a single transaction:
277
+
278
+ ```ts
279
+
280
+ const tx = new Transaction();
281
+
282
+ // Add multiple registry payments
283
+ tx.add(
284
+ client.paymentKit.calls.processRegistryPayment({
285
+ nonce: crypto.randomUUID(),
286
+ coinType: '0x2::sui::SUI',
287
+ amount: 1000000000,
288
+ receiver,
289
+ sender: senderAddress,
290
+ }),
291
+ );
292
+
293
+ tx.add(
294
+ client.paymentKit.calls.processRegistryPayment({
295
+ nonce: crypto.randomUUID(),
296
+ coinType: '0x2::sui::SUI',
297
+ amount: 2000000000,
298
+ receiver,
299
+ sender: senderAddress,
300
+ }),
301
+ );
302
+
303
+ // Execute all payments in one transaction
304
+ const result = await client.signAndExecuteTransaction({
305
+ transaction: tx,
306
+ signer: keypair,
307
+ });
308
+ ```
309
+
310
+ ### Working with Custom Coin Types
311
+
312
+ Payment Kit works with any Sui coin type:
313
+
314
+ ```ts
315
+ // Example with a custom token
316
+ const CUSTOM_COIN = '0xabc123::my_token::MY_TOKEN';
317
+
318
+ const tx = client.paymentKit.tx.processRegistryPayment({
319
+ nonce: crypto.randomUUID(),
320
+ coinType: CUSTOM_COIN,
321
+ amount: 1000, // Amount in the coin's smallest unit
322
+ receiver,
323
+ sender: senderAddress,
324
+ });
325
+
326
+ // Make sure the sender has enough of the custom coin
327
+ const result = await client.signAndExecuteTransaction({
328
+ transaction: tx,
329
+ signer: keypair,
330
+ });
331
+ ```
332
+
333
+ ## Gas Considerations
334
+
335
+ ### Registry Payments
336
+
337
+ Registry payments have higher gas costs because they:
338
+
339
+ - Create a new dynamic field (first payment with unique key)
340
+ - Write data to the registry object
341
+ - Perform duplicate checking
342
+
343
+ ### Ephemeral Payments
344
+
345
+ Ephemeral payments have lower gas costs because they:
346
+
347
+ - Only transfer coins
348
+ - Don't create persistent storage
349
+ - Skip duplicate checking
350
+
351
+ ## Best Practices
352
+
353
+ 1. **Use Meaningful Nonces**: Choose nonces that help you track payments (e.g., `order-123`,
354
+ `invoice-456`)
355
+
356
+ 2. **Store Receipts Off-Chain**: Save `PaymentReceipt` events in your database for quick lookup
357
+
358
+ 3. **Handle Duplicate Attempts**: Gracefully handle duplicate payment attempts with proper error
359
+ messages
360
+
361
+ 4. **Verify Before Delivery**: Always verify payment records before delivering goods/services
362
+
363
+ 5. **Choose the Right Model**:
364
+ - Use registry payments for critical transactions requiring duplicate prevention
365
+ - Use ephemeral payments for high-frequency, low-value transactions
366
+
367
+ 6. **Monitor Expiration**: If using registry payments, be aware of the expiration policy and query
368
+ records before they expire
369
+
370
+ ## Next Steps
371
+
372
+ - [Registry Management](./registry-management) - Learn how to create and configure custom registries