@mysten/payment-kit 0.1.7 → 0.1.9
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/dist/contracts/utils/index.mjs +6 -5
- package/dist/contracts/utils/index.mjs.map +1 -1
- package/docs/getting-started.md +13 -13
- package/docs/index.md +13 -13
- package/docs/llms-index.md +9 -5
- package/docs/payment-kit-sdk.md +18 -18
- package/docs/payment-processing.md +34 -34
- package/docs/registry-management.md +35 -35
- package/package.json +2 -2
|
@@ -24,7 +24,8 @@ function getPureBcsSchema(typeTag) {
|
|
|
24
24
|
if (pkg === MOVE_STDLIB_ADDRESS) {
|
|
25
25
|
if ((structTag.module === "ascii" || structTag.module === "string") && structTag.name === "String") return bcs.String;
|
|
26
26
|
if (structTag.module === "option" && structTag.name === "Option") {
|
|
27
|
-
const
|
|
27
|
+
const inner = structTag.typeParams[0];
|
|
28
|
+
const type = inner ? getPureBcsSchema(inner) : null;
|
|
28
29
|
return type ? bcs.option(type) : null;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -37,7 +38,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
37
38
|
if (parameterNames && argLen !== parameterNames.length) throw new Error(`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`);
|
|
38
39
|
const normalizedArgs = [];
|
|
39
40
|
let index = 0;
|
|
40
|
-
for (const
|
|
41
|
+
for (const argType of argTypes) {
|
|
41
42
|
if (argType === "0x2::clock::Clock") {
|
|
42
43
|
normalizedArgs.push((tx) => tx.object.clock());
|
|
43
44
|
continue;
|
|
@@ -69,8 +70,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
69
70
|
normalizedArgs.push(arg);
|
|
70
71
|
continue;
|
|
71
72
|
}
|
|
72
|
-
const
|
|
73
|
-
const bcsType = type === null ? null : getPureBcsSchema(type);
|
|
73
|
+
const bcsType = argType === null ? null : getPureBcsSchema(argType);
|
|
74
74
|
if (bcsType) {
|
|
75
75
|
const bytes = bcsType.serialize(arg);
|
|
76
76
|
normalizedArgs.push((tx) => tx.pure(bytes));
|
|
@@ -80,7 +80,7 @@ function normalizeMoveArguments(args, argTypes, parameterNames) {
|
|
|
80
80
|
normalizedArgs.push((tx) => tx.object(arg));
|
|
81
81
|
continue;
|
|
82
82
|
}
|
|
83
|
-
throw new Error(`Invalid argument ${stringify(arg)} for type ${
|
|
83
|
+
throw new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);
|
|
84
84
|
}
|
|
85
85
|
return normalizedArgs;
|
|
86
86
|
}
|
|
@@ -90,6 +90,7 @@ var MoveStruct = class extends BcsStruct {
|
|
|
90
90
|
...options,
|
|
91
91
|
objectIds: [objectId]
|
|
92
92
|
});
|
|
93
|
+
if (!res) throw new Error(`No object found for id ${objectId}`);
|
|
93
94
|
return res;
|
|
94
95
|
}
|
|
95
96
|
async getMany({ client, ...options }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["val"],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\ttype BcsType,\n\ttype TypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@mysten/sui/bcs';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\nimport { type TransactionArgument, isArgument } from '@mysten/sui/transactions';\nimport { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["val"],"sources":["../../../src/contracts/utils/index.ts"],"sourcesContent":["import {\n\tbcs,\n\ttype BcsType,\n\ttype TypeTag,\n\tTypeTagSerializer,\n\tBcsStruct,\n\tBcsEnum,\n\tBcsTuple,\n} from '@mysten/sui/bcs';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\nimport { type TransactionArgument, isArgument } from '@mysten/sui/transactions';\nimport { type ClientWithCoreApi, type SuiClientTypes } from '@mysten/sui/client';\n\nconst MOVE_STDLIB_ADDRESS = normalizeSuiAddress('0x1');\nconst SUI_FRAMEWORK_ADDRESS = normalizeSuiAddress('0x2');\n\nexport type RawTransactionArgument<T> = T | TransactionArgument;\n\nexport type GetOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectOptions<Include> & { client: ClientWithCoreApi };\n\nexport type GetManyOptions<Include extends Omit<SuiClientTypes.ObjectInclude, 'content'> = {}> =\n\tSuiClientTypes.GetObjectsOptions<Include> & { client: ClientWithCoreApi };\n\nexport function getPureBcsSchema(typeTag: string | TypeTag): BcsType<any> | null {\n\tconst parsedTag = typeof typeTag === 'string' ? TypeTagSerializer.parseFromStr(typeTag) : typeTag;\n\n\tif ('u8' in parsedTag) {\n\t\treturn bcs.U8;\n\t} else if ('u16' in parsedTag) {\n\t\treturn bcs.U16;\n\t} else if ('u32' in parsedTag) {\n\t\treturn bcs.U32;\n\t} else if ('u64' in parsedTag) {\n\t\treturn bcs.U64;\n\t} else if ('u128' in parsedTag) {\n\t\treturn bcs.U128;\n\t} else if ('u256' in parsedTag) {\n\t\treturn bcs.U256;\n\t} else if ('address' in parsedTag) {\n\t\treturn bcs.Address;\n\t} else if ('bool' in parsedTag) {\n\t\treturn bcs.Bool;\n\t} else if ('vector' in parsedTag) {\n\t\tconst type = getPureBcsSchema(parsedTag.vector);\n\t\treturn type ? bcs.vector(type) : null;\n\t} else if ('struct' in parsedTag) {\n\t\tconst structTag = parsedTag.struct;\n\t\tconst pkg = normalizeSuiAddress(structTag.address);\n\n\t\tif (pkg === MOVE_STDLIB_ADDRESS) {\n\t\t\tif (\n\t\t\t\t(structTag.module === 'ascii' || structTag.module === 'string') &&\n\t\t\t\tstructTag.name === 'String'\n\t\t\t) {\n\t\t\t\treturn bcs.String;\n\t\t\t}\n\n\t\t\tif (structTag.module === 'option' && structTag.name === 'Option') {\n\t\t\t\tconst inner = structTag.typeParams[0];\n\t\t\t\tconst type = inner ? getPureBcsSchema(inner) : null;\n\t\t\t\treturn type ? bcs.option(type) : null;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tpkg === SUI_FRAMEWORK_ADDRESS &&\n\t\t\tstructTag.module === 'object' &&\n\t\t\t(structTag.name === 'ID' || structTag.name === 'UID')\n\t\t) {\n\t\t\treturn bcs.Address;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function normalizeMoveArguments(\n\targs: unknown[] | object,\n\targTypes: readonly (string | null)[],\n\tparameterNames?: string[],\n) {\n\tconst argLen = Array.isArray(args) ? args.length : Object.keys(args).length;\n\tif (parameterNames && argLen !== parameterNames.length) {\n\t\tthrow new Error(\n\t\t\t`Invalid number of arguments, expected ${parameterNames.length}, got ${argLen}`,\n\t\t);\n\t}\n\n\tconst normalizedArgs: TransactionArgument[] = [];\n\n\tlet index = 0;\n\tfor (const argType of argTypes) {\n\t\tif (argType === '0x2::clock::Clock') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.clock());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::random::Random') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.random());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x2::deny_list::DenyList') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.denyList());\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (argType === '0x3::sui_system::SuiSystemState') {\n\t\t\tnormalizedArgs.push((tx) => tx.object.system());\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet arg;\n\t\tif (Array.isArray(args)) {\n\t\t\tif (index >= args.length) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid number of arguments, expected at least ${index + 1}, got ${args.length}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\targ = args[index];\n\t\t} else {\n\t\t\tif (!parameterNames) {\n\t\t\t\tthrow new Error(`Expected arguments to be passed as an array`);\n\t\t\t}\n\t\t\tconst name = parameterNames[index];\n\t\t\targ = args[name as keyof typeof args];\n\n\t\t\tif (arg === undefined) {\n\t\t\t\tthrow new Error(`Parameter ${name} is required`);\n\t\t\t}\n\t\t}\n\n\t\tindex += 1;\n\n\t\tif (typeof arg === 'function' || isArgument(arg)) {\n\t\t\tnormalizedArgs.push(arg as TransactionArgument);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst bcsType = argType === null ? null : getPureBcsSchema(argType);\n\n\t\tif (bcsType) {\n\t\t\tconst bytes = bcsType.serialize(arg as never);\n\t\t\tnormalizedArgs.push((tx) => tx.pure(bytes));\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (typeof arg === 'string') {\n\t\t\tnormalizedArgs.push((tx) => tx.object(arg));\n\t\t\tcontinue;\n\t\t}\n\n\t\tthrow new Error(`Invalid argument ${stringify(arg)} for type ${argType}`);\n\t}\n\n\treturn normalizedArgs;\n}\n\nexport class MoveStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsStruct<T, Name> {\n\tasync get<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tobjectId,\n\t\t...options\n\t}: GetOptions<Include>): Promise<\n\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t}\n\t> {\n\t\tconst [res] = await this.getMany<Include>({\n\t\t\t...options,\n\t\t\tobjectIds: [objectId],\n\t\t});\n\n\t\tif (!res) {\n\t\t\tthrow new Error(`No object found for id ${objectId}`);\n\t\t}\n\n\t\treturn res;\n\t}\n\n\tasync getMany<Include extends Omit<SuiClientTypes.ObjectInclude, 'content' | 'json'> = {}>({\n\t\tclient,\n\t\t...options\n\t}: GetManyOptions<Include>): Promise<\n\t\tArray<\n\t\t\tSuiClientTypes.Object<Include & { content: true; json: true }> & {\n\t\t\t\tjson: BcsStruct<T>['$inferType'];\n\t\t\t}\n\t\t>\n\t> {\n\t\tconst response = (await client.core.getObjects({\n\t\t\t...options,\n\t\t\tinclude: {\n\t\t\t\t...options.include,\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t})) as SuiClientTypes.GetObjectsResponse<Include & { content: true }>;\n\n\t\treturn response.objects.map((obj) => {\n\t\t\tif (obj instanceof Error) {\n\t\t\t\tthrow obj;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...obj,\n\t\t\t\tjson: this.parse(obj.content),\n\t\t\t};\n\t\t});\n\t}\n}\n\nexport class MoveEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string,\n> extends BcsEnum<T, Name> {}\n\nexport class MoveTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string,\n> extends BcsTuple<T, Name> {}\n\nfunction stringify(val: unknown) {\n\tif (typeof val === 'object') {\n\t\treturn JSON.stringify(val, (val: unknown) => val);\n\t}\n\tif (typeof val === 'bigint') {\n\t\treturn val.toString();\n\t}\n\n\treturn val;\n}\n"],"mappings":"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"}
|
package/docs/getting-started.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Getting Started
|
|
2
2
|
|
|
3
|
-
> Install and set up Payment Kit for your Sui
|
|
3
|
+
> Install and set up Payment Kit for your Sui application.
|
|
4
4
|
|
|
5
5
|
> **Note:** This package is in active development and should be used with caution. APIs are
|
|
6
6
|
> experimental and subject to breaking changes without notice. We recommend thoroughly testing any
|
|
@@ -12,7 +12,7 @@ This guide will help you set up and start using the Payment Kit SDK in your Sui
|
|
|
12
12
|
|
|
13
13
|
Before you begin, ensure you have:
|
|
14
14
|
|
|
15
|
-
- A Sui wallet with
|
|
15
|
+
- A Sui wallet with Testnet or Mainnet SUI tokens
|
|
16
16
|
- Basic understanding of TypeScript and the Sui blockchain
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
@@ -23,7 +23,7 @@ Install the Payment Kit SDK and the Sui TypeScript SDK:
|
|
|
23
23
|
npm install --save @mysten/payment-kit @mysten/sui
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## Setting
|
|
26
|
+
## Setting up the client
|
|
27
27
|
|
|
28
28
|
The Payment Kit SDK extends the standard `SuiGrpcClient` to provide payment functionality. Here's
|
|
29
29
|
how to set it up:
|
|
@@ -37,11 +37,11 @@ const client = new SuiGrpcClient({
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
The client will automatically configure the correct package IDs for the network you're using
|
|
40
|
-
(
|
|
40
|
+
(Testnet or Mainnet).
|
|
41
41
|
|
|
42
|
-
## Your
|
|
42
|
+
## Your first payment
|
|
43
43
|
|
|
44
|
-
Let's process a
|
|
44
|
+
Let's process a basic registry-based payment using the default payment registry:
|
|
45
45
|
|
|
46
46
|
```ts
|
|
47
47
|
// Create or load your keypair
|
|
@@ -75,7 +75,7 @@ if (result.$kind === 'FailedTransaction') {
|
|
|
75
75
|
console.log('Payment processed:', result.Transaction.digest);
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
## Understanding the
|
|
78
|
+
## Understanding the payment
|
|
79
79
|
|
|
80
80
|
In this example:
|
|
81
81
|
|
|
@@ -86,7 +86,7 @@ In this example:
|
|
|
86
86
|
5. **Sender**: The address sending the payment (must match the transaction signer)
|
|
87
87
|
6. **Registry Name**: The payment registry to use (defaults to `DEFAULT_REGISTRY_NAME`)
|
|
88
88
|
|
|
89
|
-
## Verifying the
|
|
89
|
+
## Verifying the payment
|
|
90
90
|
|
|
91
91
|
After processing a payment, you can query the payment record to verify it exists:
|
|
92
92
|
|
|
@@ -108,7 +108,7 @@ if (paymentRecord) {
|
|
|
108
108
|
}
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
## Processing an
|
|
111
|
+
## Processing an ephemeral payment
|
|
112
112
|
|
|
113
113
|
If you don't need duplicate prevention or persistent storage, use ephemeral payments:
|
|
114
114
|
|
|
@@ -141,7 +141,7 @@ Ephemeral payments:
|
|
|
141
141
|
- Still emit a `PaymentReceipt` event
|
|
142
142
|
- Have lower gas costs
|
|
143
143
|
|
|
144
|
-
## Working with
|
|
144
|
+
## Working with different coin types
|
|
145
145
|
|
|
146
146
|
Payment Kit supports any Sui coin type. Here's how to process payments with custom coins:
|
|
147
147
|
|
|
@@ -164,7 +164,7 @@ const result = await client.signAndExecuteTransaction({
|
|
|
164
164
|
});
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
-
## Error
|
|
167
|
+
## Error handling
|
|
168
168
|
|
|
169
169
|
Always wrap payment operations in try-catch blocks:
|
|
170
170
|
|
|
@@ -192,7 +192,7 @@ try {
|
|
|
192
192
|
}
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
## Creating
|
|
195
|
+
## Creating payment URIs
|
|
196
196
|
|
|
197
197
|
Payment Kit provides helper functions to create and parse Payment Kit transaction URIs. These URIs
|
|
198
198
|
are useful for generating payment links, QR codes, or deep links in your application:
|
|
@@ -243,7 +243,7 @@ const tx = client.paymentKit.tx.processRegistryPayment({
|
|
|
243
243
|
});
|
|
244
244
|
```
|
|
245
245
|
|
|
246
|
-
## Next
|
|
246
|
+
## Next steps
|
|
247
247
|
|
|
248
248
|
Now that you understand the basics, explore more advanced features:
|
|
249
249
|
|
package/docs/index.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# Payment Kit
|
|
2
2
|
|
|
3
|
-
> Accept payments in any coin type on Sui
|
|
3
|
+
> Accept payments in any coin type on the Sui blockchain with built-in duplicate prevention.
|
|
4
4
|
|
|
5
5
|
> **Note:** This package is in active development and should be used with caution. APIs are
|
|
6
6
|
> experimental and subject to breaking changes without notice. We recommend thoroughly testing any
|
|
7
7
|
> implementation before using in production environments.
|
|
8
8
|
|
|
9
|
-
The Sui Payment Kit SDK is a TypeScript library that provides a
|
|
10
|
-
blockchain payments on the Sui network. It offers flexible payment processing with built-in
|
|
9
|
+
The Sui Payment Kit SDK is a TypeScript library that provides a straightforward and secure way to
|
|
10
|
+
process blockchain payments on the Sui network. It offers flexible payment processing with built-in
|
|
11
11
|
duplicate prevention, configurable payment registries, and comprehensive receipt management.
|
|
12
12
|
|
|
13
13
|
## Overview
|
|
@@ -19,10 +19,10 @@ with minimal setup. The SDK provides two payment models:
|
|
|
19
19
|
expiration
|
|
20
20
|
- **Ephemeral payments**: Lightweight payment processing without persistent storage
|
|
21
21
|
|
|
22
|
-
All payments emit a `PaymentReceipt` that can be stored
|
|
22
|
+
All payments emit a `PaymentReceipt` that can be stored offchain for verification and
|
|
23
23
|
record-keeping.
|
|
24
24
|
|
|
25
|
-
## Key
|
|
25
|
+
## Key features
|
|
26
26
|
|
|
27
27
|
- **Duplicate Prevention**: Registry-based payments automatically prevent duplicate transactions
|
|
28
28
|
- **Flexible Payment Models**: Choose between registry-based or ephemeral payment processing
|
|
@@ -38,7 +38,7 @@ record-keeping.
|
|
|
38
38
|
npm install --save @mysten/payment-kit @mysten/sui
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
## Quick
|
|
41
|
+
## Quick start
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
44
|
// Create a Sui client with a Payment Kit extension
|
|
@@ -68,7 +68,7 @@ if (result.$kind === 'FailedTransaction') {
|
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
## Network
|
|
71
|
+
## Network support
|
|
72
72
|
|
|
73
73
|
Payment Kit supports the following Sui networks:
|
|
74
74
|
|
|
@@ -78,9 +78,9 @@ Payment Kit supports the following Sui networks:
|
|
|
78
78
|
The SDK automatically configures the correct package and object IDs based on the network specified
|
|
79
79
|
in your `SuiGrpcClient` configuration.
|
|
80
80
|
|
|
81
|
-
## Core
|
|
81
|
+
## Core concepts
|
|
82
82
|
|
|
83
|
-
### Payment
|
|
83
|
+
### Payment processing
|
|
84
84
|
|
|
85
85
|
Payment Kit offers two distinct payment processing models to suit different application needs:
|
|
86
86
|
|
|
@@ -89,7 +89,7 @@ Payment Kit offers two distinct payment processing models to suit different appl
|
|
|
89
89
|
2. **Ephemeral Payments**: Processes payments without persistent storage, suitable for scenarios
|
|
90
90
|
where duplicate prevention is handled externally
|
|
91
91
|
|
|
92
|
-
### Payment
|
|
92
|
+
### Payment registries
|
|
93
93
|
|
|
94
94
|
A `PaymentRegistry` manages payment records and configurations. Benefits include:
|
|
95
95
|
|
|
@@ -98,7 +98,7 @@ A `PaymentRegistry` manages payment records and configurations. Benefits include
|
|
|
98
98
|
- Optional fund management
|
|
99
99
|
- Custom naming for easy identification and indexing
|
|
100
100
|
|
|
101
|
-
### Payment
|
|
101
|
+
### Payment records
|
|
102
102
|
|
|
103
103
|
When using registry-based payments, a `PaymentRecord` is created as a Dynamic Field on the registry.
|
|
104
104
|
Records are identified by a composite key derived from:
|
|
@@ -108,7 +108,7 @@ Records are identified by a composite key derived from:
|
|
|
108
108
|
- Coin type
|
|
109
109
|
- Receiver address
|
|
110
110
|
|
|
111
|
-
### Payment
|
|
111
|
+
### Payment receipts
|
|
112
112
|
|
|
113
113
|
Every payment (registry-based or ephemeral) emits a `PaymentReceipt` event containing:
|
|
114
114
|
|
|
@@ -123,7 +123,7 @@ type PaymentReceipt = {
|
|
|
123
123
|
};
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
## Next
|
|
126
|
+
## Next steps
|
|
127
127
|
|
|
128
128
|
- [Getting Started Guide](/payment-kit/getting-started) - Detailed setup and usage instructions
|
|
129
129
|
- [Payment Processing](/payment-kit/payment-processing) - Learn about different payment models
|
package/docs/llms-index.md
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
> Accept payments in any coin type on Sui
|
|
4
4
|
|
|
5
|
-
- [Payment Kit](..md): Accept payments in any coin type on Sui
|
|
6
|
-
|
|
7
|
-
- [
|
|
8
|
-
- [Payment
|
|
9
|
-
|
|
5
|
+
- [Payment Kit](..md): Accept payments in any coin type on the Sui blockchain with built-in
|
|
6
|
+
duplicate prevention.
|
|
7
|
+
- [Getting Started](./getting-started.md): Install and set up Payment Kit for your Sui application.
|
|
8
|
+
- [Payment Kit SDK](./payment-kit-sdk.md): Payment Kit SDK API reference and configuration for the
|
|
9
|
+
PaymentKitClient.
|
|
10
|
+
- [Payment Processing](./payment-processing.md): Process registry-based and ephemeral payments and
|
|
11
|
+
handle transaction results on Sui.
|
|
12
|
+
- [Registry Management](./registry-management.md): Create, configure, and manage payment registries
|
|
13
|
+
and accepted coin types on Sui.
|
package/docs/payment-kit-sdk.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Payment Kit SDK
|
|
2
2
|
|
|
3
|
-
> Payment Kit SDK API reference and configuration
|
|
3
|
+
> Payment Kit SDK API reference and configuration for the PaymentKitClient.
|
|
4
4
|
|
|
5
5
|
> **Note:** This package is in active development and should be used with caution. APIs are
|
|
6
6
|
> experimental and subject to breaking changes without notice. We recommend thoroughly testing any
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
Complete API reference for the Payment Kit SDK.
|
|
10
10
|
|
|
11
|
-
## Client
|
|
11
|
+
## Client setup
|
|
12
12
|
|
|
13
13
|
### PaymentKitClient
|
|
14
14
|
|
|
@@ -45,7 +45,7 @@ client.paymentKit.tx.processRegistryPayment(/* ... */);
|
|
|
45
45
|
|
|
46
46
|
- `PaymentKitClientError` if network is unsupported
|
|
47
47
|
|
|
48
|
-
## Transaction
|
|
48
|
+
## Transaction methods
|
|
49
49
|
|
|
50
50
|
Transaction methods create complete, ready-to-sign transactions.
|
|
51
51
|
|
|
@@ -73,7 +73,7 @@ type ProcessRegistryPaymentOptions = {
|
|
|
73
73
|
|
|
74
74
|
**Returns:** `Transaction` - Ready-to-sign transaction
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
If you prefer to provide the `registryId`, you can do so instead of the `registryName`.
|
|
77
77
|
|
|
78
78
|
**Example:**
|
|
79
79
|
|
|
@@ -403,7 +403,7 @@ const result = await client.signAndExecuteTransaction({
|
|
|
403
403
|
- Removes the payment record from the registry
|
|
404
404
|
- Sender receives storage rebate
|
|
405
405
|
|
|
406
|
-
## Query
|
|
406
|
+
## Query methods
|
|
407
407
|
|
|
408
408
|
### `client.paymentKit.getPaymentRecord()`
|
|
409
409
|
|
|
@@ -461,7 +461,7 @@ if (record) {
|
|
|
461
461
|
- Check for duplicate payments before processing
|
|
462
462
|
- Retrieve payment details for reconciliation
|
|
463
463
|
|
|
464
|
-
## Call
|
|
464
|
+
## Call methods
|
|
465
465
|
|
|
466
466
|
Call methods return transaction commands that can be composed in custom transactions. Use these when
|
|
467
467
|
you need fine-grained control over transaction construction.
|
|
@@ -514,7 +514,7 @@ await client.signAndExecuteTransaction({
|
|
|
514
514
|
});
|
|
515
515
|
```
|
|
516
516
|
|
|
517
|
-
### Other
|
|
517
|
+
### Other call methods
|
|
518
518
|
|
|
519
519
|
All transaction methods have corresponding call methods:
|
|
520
520
|
|
|
@@ -527,7 +527,7 @@ All transaction methods have corresponding call methods:
|
|
|
527
527
|
|
|
528
528
|
## Types
|
|
529
529
|
|
|
530
|
-
### PaymentReceipt
|
|
530
|
+
### PaymentReceipt event
|
|
531
531
|
|
|
532
532
|
Emitted when a payment is processed (registry or ephemeral).
|
|
533
533
|
|
|
@@ -565,7 +565,7 @@ if (receiptEvent) {
|
|
|
565
565
|
}
|
|
566
566
|
```
|
|
567
567
|
|
|
568
|
-
## Error
|
|
568
|
+
## Error handling
|
|
569
569
|
|
|
570
570
|
### PaymentKitClientError
|
|
571
571
|
|
|
@@ -577,13 +577,13 @@ class PaymentKitClientError extends Error {
|
|
|
577
577
|
}
|
|
578
578
|
```
|
|
579
579
|
|
|
580
|
-
## URI
|
|
580
|
+
## URI utilities
|
|
581
581
|
|
|
582
582
|
Payment Kit provides utility functions for creating and parsing payment transaction URIs. These URIs
|
|
583
583
|
follow the `sui:pay` protocol and can be used to encode payment parameters for QR codes, deep links,
|
|
584
584
|
or other sharing mechanisms.
|
|
585
585
|
|
|
586
|
-
### URI
|
|
586
|
+
### URI format
|
|
587
587
|
|
|
588
588
|
Payment URIs follow the `sui:pay` protocol:
|
|
589
589
|
|
|
@@ -601,12 +601,12 @@ sui:pay?
|
|
|
601
601
|
|
|
602
602
|
**Required Parameters:**
|
|
603
603
|
|
|
604
|
-
| Parameter | Description
|
|
605
|
-
| ---------- |
|
|
606
|
-
| `receiver` | Recipient Sui address
|
|
607
|
-
| `amount` | Payment amount in smallest unit (
|
|
608
|
-
| `coinType` | Coin type (
|
|
609
|
-
| `nonce` | Unique payment identifier (max 36 chars)
|
|
604
|
+
| Parameter | Description |
|
|
605
|
+
| ---------- | --------------------------------------------------- |
|
|
606
|
+
| `receiver` | Recipient Sui address |
|
|
607
|
+
| `amount` | Payment amount in smallest unit (for example, MIST) |
|
|
608
|
+
| `coinType` | Coin type (for example, `0x2::sui::SUI`) |
|
|
609
|
+
| `nonce` | Unique payment identifier (max 36 chars) |
|
|
610
610
|
|
|
611
611
|
**Optional Parameters:**
|
|
612
612
|
|
|
@@ -736,7 +736,7 @@ const tx = client.paymentKit.tx.processRegistryPayment({
|
|
|
736
736
|
- `PaymentKitUriError` if nonce exceeds 36 characters
|
|
737
737
|
- `PaymentKitUriError` if amount is not a positive number
|
|
738
738
|
|
|
739
|
-
### Future
|
|
739
|
+
### Future versions
|
|
740
740
|
|
|
741
741
|
Check the
|
|
742
742
|
[CHANGELOG](https://github.com/MystenLabs/ts-sdks/blob/main/packages/payment-kit/CHANGELOG.md) for
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Payment Processing
|
|
2
2
|
|
|
3
|
-
> Process payments and handle transaction results
|
|
3
|
+
> Process registry-based and ephemeral payments and handle transaction results on Sui.
|
|
4
4
|
|
|
5
5
|
> **Note:** This package is in active development and should be used with caution. APIs are
|
|
6
6
|
> experimental and subject to breaking changes without notice. We recommend thoroughly testing any
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
Payment Kit provides two distinct payment processing models, each designed for different use cases.
|
|
10
10
|
This guide explains how each model works and when to use them.
|
|
11
11
|
|
|
12
|
-
## Payment
|
|
12
|
+
## Payment models overview
|
|
13
13
|
|
|
14
|
-
### Registry-
|
|
14
|
+
### Registry-based payments
|
|
15
15
|
|
|
16
|
-
Registry-based payments create a persistent `PaymentRecord` stored
|
|
16
|
+
Registry-based payments create a persistent `PaymentRecord` stored onchain in a `PaymentRegistry`.
|
|
17
17
|
This model provides:
|
|
18
18
|
|
|
19
19
|
- **Duplicate Prevention**: A payment with the same parameters can only be processed once
|
|
20
|
-
- **Verifiable Proof**:
|
|
20
|
+
- **Verifiable Proof**: Onchain proof that a payment was made
|
|
21
21
|
- **Expiration Management**: Records can be deleted after a configurable period
|
|
22
22
|
- **Centralized Tracking**: All payments are indexed under a specific registry
|
|
23
23
|
|
|
@@ -28,12 +28,12 @@ This model provides:
|
|
|
28
28
|
- Invoice payments
|
|
29
29
|
- Any scenario requiring duplicate prevention
|
|
30
30
|
|
|
31
|
-
### Ephemeral
|
|
31
|
+
### Ephemeral payments
|
|
32
32
|
|
|
33
|
-
Ephemeral payments process transfers without creating persistent
|
|
33
|
+
Ephemeral payments process transfers without creating persistent onchain records. This model
|
|
34
34
|
provides:
|
|
35
35
|
|
|
36
|
-
- **Lower Gas Costs**: No
|
|
36
|
+
- **Lower Gas Costs**: No onchain storage means cheaper transactions
|
|
37
37
|
- **Flexibility**: No registry configuration required
|
|
38
38
|
|
|
39
39
|
**When to Use:**
|
|
@@ -41,14 +41,14 @@ provides:
|
|
|
41
41
|
- Tipping/donations
|
|
42
42
|
- Recurring payments with external tracking
|
|
43
43
|
- High-frequency microtransactions
|
|
44
|
-
- Scenarios where duplicate prevention is handled
|
|
44
|
+
- Scenarios where duplicate prevention is handled offchain
|
|
45
45
|
|
|
46
|
-
## How
|
|
46
|
+
## How payment keys work
|
|
47
47
|
|
|
48
48
|
Payment Kit uses a composite key system to uniquely identify payments. Understanding this is crucial
|
|
49
49
|
for using the SDK effectively.
|
|
50
50
|
|
|
51
|
-
### Payment
|
|
51
|
+
### Payment key components
|
|
52
52
|
|
|
53
53
|
A payment key is derived from four parameters:
|
|
54
54
|
|
|
@@ -61,7 +61,7 @@ type PaymentKeyArgs = {
|
|
|
61
61
|
};
|
|
62
62
|
```
|
|
63
63
|
|
|
64
|
-
### Key
|
|
64
|
+
### Key generation
|
|
65
65
|
|
|
66
66
|
When you process a registry payment, Payment Kit hashes these parameters to create a unique key:
|
|
67
67
|
|
|
@@ -89,7 +89,7 @@ const tx2 = client.paymentKit.tx.processRegistryPayment({
|
|
|
89
89
|
});
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
### Changing
|
|
92
|
+
### Changing any component creates a new key
|
|
93
93
|
|
|
94
94
|
Each component affects the payment key. Changing any parameter creates a different payment. This
|
|
95
95
|
means, as an example, that a `nonce` can be reused for a different payment, if the `coinType` or
|
|
@@ -125,11 +125,11 @@ const payment3 = {
|
|
|
125
125
|
// All three are unique payments that can be processed separately
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
## Processing
|
|
128
|
+
## Processing registry-based payments
|
|
129
129
|
|
|
130
130
|
Let's walk through a complete registry payment workflow:
|
|
131
131
|
|
|
132
|
-
### Step 1: Create the
|
|
132
|
+
### Step 1: Create the transaction
|
|
133
133
|
|
|
134
134
|
```ts
|
|
135
135
|
// Define your payment parameters
|
|
@@ -145,7 +145,7 @@ const paymentParams = {
|
|
|
145
145
|
const tx = client.paymentKit.tx.processRegistryPayment(paymentParams);
|
|
146
146
|
```
|
|
147
147
|
|
|
148
|
-
### What
|
|
148
|
+
### What happens onchain
|
|
149
149
|
|
|
150
150
|
When this transaction executes, Payment Kit:
|
|
151
151
|
|
|
@@ -155,7 +155,7 @@ When this transaction executes, Payment Kit:
|
|
|
155
155
|
4. **Creates** a `PaymentRecord` dynamic field on the registry
|
|
156
156
|
5. **Emits** a `PaymentReceipt` event
|
|
157
157
|
|
|
158
|
-
### Step 2: Execute the
|
|
158
|
+
### Step 2: Execute the transaction
|
|
159
159
|
|
|
160
160
|
```ts
|
|
161
161
|
const result = await client.signAndExecuteTransaction({
|
|
@@ -176,7 +176,7 @@ if (result.$kind === 'FailedTransaction') {
|
|
|
176
176
|
console.log('Transaction digest:', result.Transaction.digest);
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
### Step 3: Extract the
|
|
179
|
+
### Step 3: Extract the receipt
|
|
180
180
|
|
|
181
181
|
```ts
|
|
182
182
|
// Find the PaymentReceipt event
|
|
@@ -197,7 +197,7 @@ if (receiptEvent) {
|
|
|
197
197
|
}
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
### Step 4: Verify the
|
|
200
|
+
### Step 4: Verify the payment record
|
|
201
201
|
|
|
202
202
|
```ts
|
|
203
203
|
// Query the payment record to confirm it exists
|
|
@@ -216,11 +216,11 @@ if (record) {
|
|
|
216
216
|
}
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
-
## Processing
|
|
219
|
+
## Processing ephemeral payments
|
|
220
220
|
|
|
221
221
|
Ephemeral payments follow a simpler flow without creating persistent records:
|
|
222
222
|
|
|
223
|
-
### Creating an
|
|
223
|
+
### Creating an ephemeral payment
|
|
224
224
|
|
|
225
225
|
```ts
|
|
226
226
|
// No registry needed for ephemeral payments
|
|
@@ -246,7 +246,7 @@ if (result.$kind === 'FailedTransaction') {
|
|
|
246
246
|
}
|
|
247
247
|
```
|
|
248
248
|
|
|
249
|
-
### What
|
|
249
|
+
### What happens onchain
|
|
250
250
|
|
|
251
251
|
For ephemeral payments, Payment Kit:
|
|
252
252
|
|
|
@@ -254,9 +254,9 @@ For ephemeral payments, Payment Kit:
|
|
|
254
254
|
2. **Transfers** the coins from sender to receiver
|
|
255
255
|
3. **Emits** a `PaymentReceipt` event
|
|
256
256
|
|
|
257
|
-
|
|
257
|
+
No `PaymentRecord` is created, so duplicate payments are not prevented.
|
|
258
258
|
|
|
259
|
-
### Extracting the
|
|
259
|
+
### Extracting the receipt
|
|
260
260
|
|
|
261
261
|
```ts
|
|
262
262
|
const receiptEvent = result.Transaction.events?.find((event) =>
|
|
@@ -269,9 +269,9 @@ if (receiptEvent) {
|
|
|
269
269
|
}
|
|
270
270
|
```
|
|
271
271
|
|
|
272
|
-
## Advanced
|
|
272
|
+
## Advanced payment scenarios
|
|
273
273
|
|
|
274
|
-
### Processing
|
|
274
|
+
### Processing multiple payments in one transaction
|
|
275
275
|
|
|
276
276
|
You can combine multiple payment operations in a single transaction:
|
|
277
277
|
|
|
@@ -306,7 +306,7 @@ const result = await client.signAndExecuteTransaction({
|
|
|
306
306
|
});
|
|
307
307
|
```
|
|
308
308
|
|
|
309
|
-
### Working with
|
|
309
|
+
### Working with custom coin types
|
|
310
310
|
|
|
311
311
|
Payment Kit works with any Sui coin type:
|
|
312
312
|
|
|
@@ -329,9 +329,9 @@ const result = await client.signAndExecuteTransaction({
|
|
|
329
329
|
});
|
|
330
330
|
```
|
|
331
331
|
|
|
332
|
-
## Gas
|
|
332
|
+
## Gas considerations
|
|
333
333
|
|
|
334
|
-
### Registry
|
|
334
|
+
### Registry payments
|
|
335
335
|
|
|
336
336
|
Registry payments have higher gas costs because they:
|
|
337
337
|
|
|
@@ -339,7 +339,7 @@ Registry payments have higher gas costs because they:
|
|
|
339
339
|
- Write data to the registry object
|
|
340
340
|
- Perform duplicate checking
|
|
341
341
|
|
|
342
|
-
### Ephemeral
|
|
342
|
+
### Ephemeral payments
|
|
343
343
|
|
|
344
344
|
Ephemeral payments have lower gas costs because they:
|
|
345
345
|
|
|
@@ -347,9 +347,9 @@ Ephemeral payments have lower gas costs because they:
|
|
|
347
347
|
- Don't create persistent storage
|
|
348
348
|
- Skip duplicate checking
|
|
349
349
|
|
|
350
|
-
## Best
|
|
350
|
+
## Best practices
|
|
351
351
|
|
|
352
|
-
1. **Use Meaningful Nonces**: Choose nonces that help you track payments (
|
|
352
|
+
1. **Use Meaningful Nonces**: Choose nonces that help you track payments (for example, `order-123`,
|
|
353
353
|
`invoice-456`)
|
|
354
354
|
|
|
355
355
|
2. **Store Receipts Off-Chain**: Save `PaymentReceipt` events in your database for quick lookup
|
|
@@ -357,7 +357,7 @@ Ephemeral payments have lower gas costs because they:
|
|
|
357
357
|
3. **Handle Duplicate Attempts**: Gracefully handle duplicate payment attempts with proper error
|
|
358
358
|
messages
|
|
359
359
|
|
|
360
|
-
4. **Verify Before Delivery**: Always verify payment records before delivering goods
|
|
360
|
+
4. **Verify Before Delivery**: Always verify payment records before delivering goods or services
|
|
361
361
|
|
|
362
362
|
5. **Choose the Right Model**:
|
|
363
363
|
- Use registry payments for critical transactions requiring duplicate prevention
|
|
@@ -366,6 +366,6 @@ Ephemeral payments have lower gas costs because they:
|
|
|
366
366
|
6. **Monitor Expiration**: If using registry payments, be aware of the expiration policy and query
|
|
367
367
|
records before they expire
|
|
368
368
|
|
|
369
|
-
## Next
|
|
369
|
+
## Next steps
|
|
370
370
|
|
|
371
371
|
- [Registry Management](./registry-management) - Learn how to create and configure custom registries
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Registry Management
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Create, configure, and manage payment registries and accepted coin types on Sui.
|
|
4
4
|
|
|
5
5
|
> **Note:** This package is in active development and should be used with caution. APIs are
|
|
6
6
|
> experimental and subject to breaking changes without notice. We recommend thoroughly testing any
|
|
@@ -9,16 +9,16 @@
|
|
|
9
9
|
Payment registries are the core of Payment Kit's duplicate prevention and payment tracking system.
|
|
10
10
|
This guide covers creating, configuring, and managing payment registries.
|
|
11
11
|
|
|
12
|
-
## Understanding
|
|
12
|
+
## Understanding payment registries
|
|
13
13
|
|
|
14
|
-
A `PaymentRegistry` is an
|
|
14
|
+
A `PaymentRegistry` is an onchain object that:
|
|
15
15
|
|
|
16
16
|
- Stores `PaymentRecord` dynamic fields for each unique payment
|
|
17
17
|
- Manages configuration settings (expiration, fund management)
|
|
18
18
|
- Can be owned and administered by a specific account
|
|
19
19
|
- Provides namespaced payment tracking
|
|
20
20
|
|
|
21
|
-
### Default
|
|
21
|
+
### Default registry
|
|
22
22
|
|
|
23
23
|
Payment Kit provides a default registry that's ready to use:
|
|
24
24
|
|
|
@@ -33,7 +33,7 @@ const tx = client.paymentKit.tx.processRegistryPayment({
|
|
|
33
33
|
});
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
### When to
|
|
36
|
+
### When to create a custom registry
|
|
37
37
|
|
|
38
38
|
Consider creating your own registry when:
|
|
39
39
|
|
|
@@ -43,11 +43,11 @@ Consider creating your own registry when:
|
|
|
43
43
|
- You need better indexing of your payments
|
|
44
44
|
- You want to avoid potential congestion on the default registry
|
|
45
45
|
|
|
46
|
-
## Creating a
|
|
46
|
+
## Creating a registry
|
|
47
47
|
|
|
48
|
-
### Basic
|
|
48
|
+
### Basic registry creation
|
|
49
49
|
|
|
50
|
-
Creating a registry is
|
|
50
|
+
Creating a registry is straightforward. You only need to provide a unique name:
|
|
51
51
|
|
|
52
52
|
```ts
|
|
53
53
|
// Create a new registry
|
|
@@ -73,14 +73,14 @@ console.log('Registry created!');
|
|
|
73
73
|
console.log('Transaction:', result.Transaction.digest);
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
### What
|
|
76
|
+
### What gets created
|
|
77
77
|
|
|
78
78
|
When you create a registry, two objects are created:
|
|
79
79
|
|
|
80
80
|
1. **PaymentRegistry**: The registry object that stores payment records
|
|
81
81
|
2. **RegistryAdminCap**: A capability object that grants admin permissions
|
|
82
82
|
|
|
83
|
-
### Extracting the
|
|
83
|
+
### Extracting the admin capability
|
|
84
84
|
|
|
85
85
|
The `RegistryAdminCap` is crucial for configuring your registry:
|
|
86
86
|
|
|
@@ -104,7 +104,7 @@ if (adminCapObject && 'objectId' in adminCapObject) {
|
|
|
104
104
|
}
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
### Deriving the
|
|
107
|
+
### Deriving the registry ID
|
|
108
108
|
|
|
109
109
|
Payment Kit derives registry IDs deterministically from the registry name:
|
|
110
110
|
|
|
@@ -118,15 +118,15 @@ console.log('Registry ID:', registryId);
|
|
|
118
118
|
|
|
119
119
|
This allows you to reference registries by name throughout your application.
|
|
120
120
|
|
|
121
|
-
## Registry
|
|
121
|
+
## Registry configuration
|
|
122
122
|
|
|
123
123
|
Registries have two main configuration options:
|
|
124
124
|
|
|
125
|
-
### 1
|
|
125
|
+
### Step 1: Epoch expiration duration
|
|
126
126
|
|
|
127
127
|
Controls how long payment records persist before they can be deleted.
|
|
128
128
|
|
|
129
|
-
**Default**: 30 epochs (~30 days on
|
|
129
|
+
**Default**: 30 epochs (~30 days on Mainnet)
|
|
130
130
|
|
|
131
131
|
```ts
|
|
132
132
|
// Set expiration to 60 epochs
|
|
@@ -167,7 +167,7 @@ anyone can delete the record to reclaim storage fees:
|
|
|
167
167
|
- **Medium expiration (30-60 epochs)**: Standard e-commerce transactions
|
|
168
168
|
- **Long expiration (180+ epochs)**: Important financial records requiring long-term verification
|
|
169
169
|
|
|
170
|
-
### 2
|
|
170
|
+
### Step 2: Registry managed funds
|
|
171
171
|
|
|
172
172
|
Controls whether payments must be sent to the registry itself for later withdrawal.
|
|
173
173
|
|
|
@@ -189,7 +189,7 @@ await client.signAndExecuteTransaction({
|
|
|
189
189
|
console.log('Registry now manages funds');
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
-
**How
|
|
192
|
+
**How it works:**
|
|
193
193
|
|
|
194
194
|
When enabled:
|
|
195
195
|
|
|
@@ -219,7 +219,7 @@ const tx = client.paymentKit.tx.processRegistryPayment({
|
|
|
219
219
|
- Scenarios with very high transaction volumes
|
|
220
220
|
- Simplified accounting and reconciliation
|
|
221
221
|
|
|
222
|
-
### Configuring
|
|
222
|
+
### Configuring both settings
|
|
223
223
|
|
|
224
224
|
You can configure both settings independently:
|
|
225
225
|
|
|
@@ -251,7 +251,7 @@ await client.signAndExecuteTransaction({
|
|
|
251
251
|
});
|
|
252
252
|
```
|
|
253
253
|
|
|
254
|
-
## Withdrawing
|
|
254
|
+
## Withdrawing funds from a registry
|
|
255
255
|
|
|
256
256
|
If you've enabled registry-managed funds, you can withdraw accumulated coins:
|
|
257
257
|
|
|
@@ -274,14 +274,14 @@ const result = await client.signAndExecuteTransaction({
|
|
|
274
274
|
console.log('Funds withdrawn!');
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
-
**Important
|
|
277
|
+
**Important notes:**
|
|
278
278
|
|
|
279
279
|
- Only the admin cap owner can withdraw funds
|
|
280
280
|
- You must specify the coin type to withdraw
|
|
281
281
|
- All coins of that type are withdrawn in one operation
|
|
282
282
|
- The withdrawn coins are sent to the transaction sender
|
|
283
283
|
|
|
284
|
-
### Withdrawing
|
|
284
|
+
### Withdrawing multiple coin types
|
|
285
285
|
|
|
286
286
|
If your registry accumulates different coin types:
|
|
287
287
|
|
|
@@ -312,7 +312,7 @@ await client.signAndExecuteTransaction({
|
|
|
312
312
|
});
|
|
313
313
|
```
|
|
314
314
|
|
|
315
|
-
## Deleting
|
|
315
|
+
## Deleting expired payment records
|
|
316
316
|
|
|
317
317
|
After the expiration period, payment records can be deleted to reclaim storage fees:
|
|
318
318
|
|
|
@@ -334,14 +334,14 @@ const result = await client.signAndExecuteTransaction({
|
|
|
334
334
|
console.log('Record deleted, storage rebate received');
|
|
335
335
|
```
|
|
336
336
|
|
|
337
|
-
**Key
|
|
337
|
+
**Key points:**
|
|
338
338
|
|
|
339
339
|
- Records can only be deleted after expiration
|
|
340
340
|
- Anyone can delete expired records (permissionless cleanup)
|
|
341
341
|
- The deleter receives a small storage rebate
|
|
342
342
|
- This incentivizes automatic cleanup of old records
|
|
343
343
|
|
|
344
|
-
### Checking
|
|
344
|
+
### Checking if a record can be deleted
|
|
345
345
|
|
|
346
346
|
```ts
|
|
347
347
|
// Get the payment record
|
|
@@ -368,7 +368,7 @@ if (record) {
|
|
|
368
368
|
}
|
|
369
369
|
```
|
|
370
370
|
|
|
371
|
-
## Using
|
|
371
|
+
## Using registry ID directly
|
|
372
372
|
|
|
373
373
|
If you know the registry ID, you can use it instead of the name:
|
|
374
374
|
|
|
@@ -395,7 +395,7 @@ const record = await client.paymentKit.getPaymentRecord({
|
|
|
395
395
|
});
|
|
396
396
|
```
|
|
397
397
|
|
|
398
|
-
## Complete
|
|
398
|
+
## Complete registry setup example
|
|
399
399
|
|
|
400
400
|
Here's a complete workflow for setting up a custom registry:
|
|
401
401
|
|
|
@@ -500,28 +500,28 @@ if (paymentResult.$kind === 'FailedTransaction') {
|
|
|
500
500
|
console.log('First payment processed:', paymentResult.Transaction.digest);
|
|
501
501
|
```
|
|
502
502
|
|
|
503
|
-
## Best
|
|
503
|
+
## Best practices
|
|
504
504
|
|
|
505
|
-
1. **Store
|
|
505
|
+
1. **Store admin caps securely**: Treat your admin capability like private keys - they control your
|
|
506
506
|
registry
|
|
507
507
|
|
|
508
|
-
2. **Use
|
|
509
|
-
`acme-subscriptions`, `store-123-payments`)
|
|
508
|
+
2. **Use descriptive names**: Choose registry names that clearly identify their purpose (for
|
|
509
|
+
example, `acme-subscriptions`, `store-123-payments`)
|
|
510
510
|
|
|
511
|
-
3. **Set
|
|
511
|
+
3. **Set appropriate expiration**: Balance storage costs with verification needs
|
|
512
512
|
- Short expiration = lower storage costs
|
|
513
513
|
- Long expiration = longer verification period
|
|
514
514
|
|
|
515
|
-
4. **Monitor
|
|
515
|
+
4. **Monitor registry growth**: Track the number of payment records to anticipate storage costs
|
|
516
516
|
|
|
517
|
-
5. **Plan
|
|
517
|
+
5. **Plan fund management**: Decide upfront whether to use registry-managed funds based on your
|
|
518
518
|
withdrawal patterns
|
|
519
519
|
|
|
520
|
-
6. **Document
|
|
520
|
+
6. **Document your configuration**: Keep records of your registry settings for operational
|
|
521
521
|
consistency
|
|
522
522
|
|
|
523
|
-
7. **Test
|
|
523
|
+
7. **Test thoroughly**: Always test registry operations on Testnet before Mainnet deployment
|
|
524
524
|
|
|
525
|
-
## Next
|
|
525
|
+
## Next steps
|
|
526
526
|
|
|
527
527
|
- [SDK API Reference](./payment-kit-sdk) - Complete SDK API documentation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mysten/payment-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sui Payment Kit",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
32
|
"vitest": "^4.0.17",
|
|
33
|
-
"@mysten/codegen": "^0.
|
|
33
|
+
"@mysten/codegen": "^0.10.3",
|
|
34
34
|
"@mysten/sui": "^2.16.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|