@mysten/payment-kit 0.2.38 → 0.3.0
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/docs/getting-started.md +0 -4
- package/docs/payment-kit-sdk.md +11 -13
- package/docs/payment-processing.md +10 -16
- package/docs/registry-management.md +18 -26
- package/package.json +2 -2
package/docs/getting-started.md
CHANGED
|
@@ -63,10 +63,6 @@ const tx = client.paymentKit.tx.processRegistryPayment({
|
|
|
63
63
|
const result = await client.signAndExecuteTransaction({
|
|
64
64
|
transaction: tx,
|
|
65
65
|
signer: keypair,
|
|
66
|
-
options: {
|
|
67
|
-
showEffects: true,
|
|
68
|
-
showEvents: true,
|
|
69
|
-
},
|
|
70
66
|
});
|
|
71
67
|
|
|
72
68
|
// Check transaction status
|
package/docs/payment-kit-sdk.md
CHANGED
|
@@ -193,15 +193,15 @@ const tx = client.paymentKit.tx.createRegistry({
|
|
|
193
193
|
const result = await client.signAndExecuteTransaction({
|
|
194
194
|
transaction: tx,
|
|
195
195
|
signer: keypair,
|
|
196
|
-
|
|
197
|
-
showObjectChanges: true,
|
|
198
|
-
},
|
|
196
|
+
include: { effects: true, objectTypes: true },
|
|
199
197
|
});
|
|
200
198
|
|
|
201
|
-
//
|
|
202
|
-
const
|
|
203
|
-
(change) =>
|
|
204
|
-
|
|
199
|
+
// Find the created RegistryAdminCap
|
|
200
|
+
const adminCapId = result.Transaction?.effects.changedObjects.find(
|
|
201
|
+
(change) =>
|
|
202
|
+
change.idOperation === 'Created' &&
|
|
203
|
+
result.Transaction?.objectTypes[change.objectId]?.includes('RegistryAdminCap'),
|
|
204
|
+
)?.objectId;
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
**On-Chain Effects:**
|
|
@@ -546,17 +546,15 @@ type PaymentReceipt = {
|
|
|
546
546
|
const result = await client.signAndExecuteTransaction({
|
|
547
547
|
transaction: tx,
|
|
548
548
|
signer: keypair,
|
|
549
|
-
|
|
550
|
-
showEvents: true,
|
|
551
|
-
},
|
|
549
|
+
include: { events: true },
|
|
552
550
|
});
|
|
553
551
|
|
|
554
|
-
const receiptEvent = result.Transaction.
|
|
555
|
-
event.
|
|
552
|
+
const receiptEvent = result.Transaction?.events.find((event) =>
|
|
553
|
+
event.eventType.includes('PaymentReceipt'),
|
|
556
554
|
);
|
|
557
555
|
|
|
558
556
|
if (receiptEvent) {
|
|
559
|
-
const receipt = receiptEvent.
|
|
557
|
+
const receipt = receiptEvent.json as PaymentReceipt;
|
|
560
558
|
console.log('Payment Type:', receipt.payment_type);
|
|
561
559
|
console.log('Nonce:', receipt.nonce);
|
|
562
560
|
console.log('Amount:', receipt.amount);
|
|
@@ -161,11 +161,7 @@ When this transaction executes, Payment Kit:
|
|
|
161
161
|
const result = await client.signAndExecuteTransaction({
|
|
162
162
|
transaction: tx,
|
|
163
163
|
signer: keypair,
|
|
164
|
-
|
|
165
|
-
showEffects: true,
|
|
166
|
-
showEvents: true,
|
|
167
|
-
showObjectChanges: true,
|
|
168
|
-
},
|
|
164
|
+
include: { events: true },
|
|
169
165
|
});
|
|
170
166
|
|
|
171
167
|
// Check transaction status
|
|
@@ -180,12 +176,12 @@ console.log('Transaction digest:', result.Transaction.digest);
|
|
|
180
176
|
|
|
181
177
|
```ts
|
|
182
178
|
// Find the PaymentReceipt event
|
|
183
|
-
const receiptEvent = result.Transaction.
|
|
184
|
-
event.
|
|
179
|
+
const receiptEvent = result.Transaction?.events.find((event) =>
|
|
180
|
+
event.eventType.includes('PaymentReceipt'),
|
|
185
181
|
);
|
|
186
182
|
|
|
187
|
-
if (receiptEvent) {
|
|
188
|
-
const receipt = receiptEvent.
|
|
183
|
+
if (receiptEvent?.json) {
|
|
184
|
+
const receipt = receiptEvent.json;
|
|
189
185
|
|
|
190
186
|
console.log('Payment Receipt:');
|
|
191
187
|
console.log(' Type:', receipt.payment_type); // 'Registry'
|
|
@@ -235,9 +231,7 @@ const tx = client.paymentKit.tx.processEphemeralPayment({
|
|
|
235
231
|
const result = await client.signAndExecuteTransaction({
|
|
236
232
|
transaction: tx,
|
|
237
233
|
signer: keypair,
|
|
238
|
-
|
|
239
|
-
showEvents: true,
|
|
240
|
-
},
|
|
234
|
+
include: { events: true },
|
|
241
235
|
});
|
|
242
236
|
|
|
243
237
|
// Check transaction status
|
|
@@ -259,12 +253,12 @@ No `PaymentRecord` is created, so duplicate payments are not prevented.
|
|
|
259
253
|
### Extracting the receipt
|
|
260
254
|
|
|
261
255
|
```ts
|
|
262
|
-
const receiptEvent = result.Transaction.
|
|
263
|
-
event.
|
|
256
|
+
const receiptEvent = result.Transaction?.events.find((event) =>
|
|
257
|
+
event.eventType.includes('PaymentReceipt'),
|
|
264
258
|
);
|
|
265
259
|
|
|
266
|
-
if (receiptEvent) {
|
|
267
|
-
const receipt = receiptEvent.
|
|
260
|
+
if (receiptEvent?.json) {
|
|
261
|
+
const receipt = receiptEvent.json;
|
|
268
262
|
console.log('Payment Type:', receipt.payment_type); // 'Ephemeral'
|
|
269
263
|
}
|
|
270
264
|
```
|
|
@@ -58,10 +58,7 @@ const tx = client.paymentKit.tx.createRegistry({
|
|
|
58
58
|
const result = await client.signAndExecuteTransaction({
|
|
59
59
|
transaction: tx,
|
|
60
60
|
signer: keypair,
|
|
61
|
-
|
|
62
|
-
showEffects: true,
|
|
63
|
-
showObjectChanges: true,
|
|
64
|
-
},
|
|
61
|
+
include: { effects: true, objectTypes: true },
|
|
65
62
|
});
|
|
66
63
|
|
|
67
64
|
// Check transaction status
|
|
@@ -85,14 +82,14 @@ When you create a registry, two objects are created:
|
|
|
85
82
|
The `RegistryAdminCap` is crucial for configuring your registry:
|
|
86
83
|
|
|
87
84
|
```ts
|
|
88
|
-
// Find the admin cap
|
|
89
|
-
const
|
|
90
|
-
(change) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
85
|
+
// Find the admin cap among the objects the transaction created
|
|
86
|
+
const adminCapId = result.Transaction.effects.changedObjects.find(
|
|
87
|
+
(change) =>
|
|
88
|
+
change.idOperation === 'Created' &&
|
|
89
|
+
result.Transaction.objectTypes[change.objectId]?.includes('RegistryAdminCap'),
|
|
90
|
+
)?.objectId;
|
|
91
|
+
|
|
92
|
+
if (adminCapId) {
|
|
96
93
|
console.log('Admin Capability ID:', adminCapId);
|
|
97
94
|
|
|
98
95
|
// Store this ID - you'll need it to configure the registry
|
|
@@ -267,9 +264,6 @@ const tx = client.paymentKit.tx.withdrawFromRegistry({
|
|
|
267
264
|
const result = await client.signAndExecuteTransaction({
|
|
268
265
|
transaction: tx,
|
|
269
266
|
signer: keypair,
|
|
270
|
-
options: {
|
|
271
|
-
showEffects: true,
|
|
272
|
-
},
|
|
273
267
|
});
|
|
274
268
|
|
|
275
269
|
console.log('Funds withdrawn!');
|
|
@@ -357,8 +351,8 @@ const record = await client.paymentKit.getPaymentRecord({
|
|
|
357
351
|
if (record) {
|
|
358
352
|
const recordEpoch = parseInt(record.epochAtTimeOfRecord);
|
|
359
353
|
const currentEpoch = await client.core
|
|
360
|
-
.
|
|
361
|
-
.then((
|
|
354
|
+
.getCurrentSystemState()
|
|
355
|
+
.then(({ systemState }) => Number(systemState.epoch));
|
|
362
356
|
|
|
363
357
|
const expirationDuration = 30; // Your registry's setting
|
|
364
358
|
const canDelete = currentEpoch >= recordEpoch + expirationDuration;
|
|
@@ -419,10 +413,7 @@ const createTx = client.paymentKit.tx.createRegistry({
|
|
|
419
413
|
const createResult = await client.signAndExecuteTransaction({
|
|
420
414
|
transaction: createTx,
|
|
421
415
|
signer: keypair,
|
|
422
|
-
|
|
423
|
-
showEffects: true,
|
|
424
|
-
showObjectChanges: true,
|
|
425
|
-
},
|
|
416
|
+
include: { effects: true, objectTypes: true },
|
|
426
417
|
});
|
|
427
418
|
|
|
428
419
|
// Check transaction status
|
|
@@ -433,11 +424,12 @@ if (createResult.$kind === 'FailedTransaction') {
|
|
|
433
424
|
}
|
|
434
425
|
|
|
435
426
|
// Step 2: Extract the admin cap
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
)
|
|
439
|
-
|
|
440
|
-
|
|
427
|
+
const adminCapId =
|
|
428
|
+
createResult.Transaction.effects.changedObjects.find(
|
|
429
|
+
(change) =>
|
|
430
|
+
change.idOperation === 'Created' &&
|
|
431
|
+
createResult.Transaction.objectTypes[change.objectId]?.includes('RegistryAdminCap'),
|
|
432
|
+
)?.objectId ?? '';
|
|
441
433
|
|
|
442
434
|
console.log('Registry created!');
|
|
443
435
|
console.log('Admin Cap ID:', adminCapId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mysten/payment-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sui Payment Kit",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@mysten/bcs": "^2.1.4"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@mysten/sui": "^
|
|
38
|
+
"@mysten/sui": "^3.0.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"clean": "rm -rf tsconfig.tsbuildinfo ./dist",
|