@ocap/client 1.25.3 → 1.25.5

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 (92) hide show
  1. package/README.md +76 -80
  2. package/dist/report.html +1 -1
  3. package/docs/_sidebar.md +22 -0
  4. package/docs/api-reference-client-methods.ja.md +229 -0
  5. package/docs/api-reference-client-methods.md +229 -0
  6. package/docs/api-reference-client-methods.zh-TW.md +229 -0
  7. package/docs/api-reference-client-methods.zh.md +229 -0
  8. package/docs/api-reference-data-types.ja.md +482 -0
  9. package/docs/api-reference-data-types.md +482 -0
  10. package/docs/api-reference-data-types.zh-TW.md +482 -0
  11. package/docs/api-reference-data-types.zh.md +482 -0
  12. package/docs/api-reference-low-level-api.ja.md +228 -0
  13. package/docs/api-reference-low-level-api.md +228 -0
  14. package/docs/api-reference-low-level-api.zh-TW.md +228 -0
  15. package/docs/api-reference-low-level-api.zh.md +228 -0
  16. package/docs/api-reference-query-mutation-methods.ja.md +814 -0
  17. package/docs/api-reference-query-mutation-methods.md +814 -0
  18. package/docs/api-reference-query-mutation-methods.zh-TW.md +814 -0
  19. package/docs/api-reference-query-mutation-methods.zh.md +814 -0
  20. package/docs/api-reference-transaction-helpers.ja.md +649 -0
  21. package/docs/api-reference-transaction-helpers.md +649 -0
  22. package/docs/api-reference-transaction-helpers.zh-TW.md +649 -0
  23. package/docs/api-reference-transaction-helpers.zh.md +649 -0
  24. package/docs/api-reference.ja.md +23 -0
  25. package/docs/api-reference.md +23 -0
  26. package/docs/api-reference.zh-TW.md +23 -0
  27. package/docs/api-reference.zh.md +23 -0
  28. package/docs/core-concepts-client-architecture.ja.md +102 -0
  29. package/docs/core-concepts-client-architecture.md +102 -0
  30. package/docs/core-concepts-client-architecture.zh-TW.md +102 -0
  31. package/docs/core-concepts-client-architecture.zh.md +102 -0
  32. package/docs/core-concepts-event-subscriptions.ja.md +123 -0
  33. package/docs/core-concepts-event-subscriptions.md +123 -0
  34. package/docs/core-concepts-event-subscriptions.zh-TW.md +123 -0
  35. package/docs/core-concepts-event-subscriptions.zh.md +123 -0
  36. package/docs/core-concepts-gas-payment.ja.md +111 -0
  37. package/docs/core-concepts-gas-payment.md +111 -0
  38. package/docs/core-concepts-gas-payment.zh-TW.md +111 -0
  39. package/docs/core-concepts-gas-payment.zh.md +111 -0
  40. package/docs/core-concepts-transaction-lifecycle.ja.md +183 -0
  41. package/docs/core-concepts-transaction-lifecycle.md +183 -0
  42. package/docs/core-concepts-transaction-lifecycle.zh-TW.md +183 -0
  43. package/docs/core-concepts-transaction-lifecycle.zh.md +183 -0
  44. package/docs/core-concepts.ja.md +22 -0
  45. package/docs/core-concepts.md +22 -0
  46. package/docs/core-concepts.zh-TW.md +22 -0
  47. package/docs/core-concepts.zh.md +22 -0
  48. package/docs/getting-started-basic-usage.ja.md +87 -0
  49. package/docs/getting-started-basic-usage.md +87 -0
  50. package/docs/getting-started-basic-usage.zh-TW.md +87 -0
  51. package/docs/getting-started-basic-usage.zh.md +87 -0
  52. package/docs/getting-started-installation.ja.md +60 -0
  53. package/docs/getting-started-installation.md +60 -0
  54. package/docs/getting-started-installation.zh-TW.md +60 -0
  55. package/docs/getting-started-installation.zh.md +60 -0
  56. package/docs/getting-started.ja.md +16 -0
  57. package/docs/getting-started.md +16 -0
  58. package/docs/getting-started.zh-TW.md +16 -0
  59. package/docs/getting-started.zh.md +17 -0
  60. package/docs/how-to-guides-delegate-permissions.ja.md +167 -0
  61. package/docs/how-to-guides-delegate-permissions.md +167 -0
  62. package/docs/how-to-guides-delegate-permissions.zh-TW.md +167 -0
  63. package/docs/how-to-guides-delegate-permissions.zh.md +166 -0
  64. package/docs/how-to-guides-manage-accounts.ja.md +73 -0
  65. package/docs/how-to-guides-manage-accounts.md +73 -0
  66. package/docs/how-to-guides-manage-accounts.zh-TW.md +73 -0
  67. package/docs/how-to-guides-manage-accounts.zh.md +73 -0
  68. package/docs/how-to-guides-manage-assets.ja.md +255 -0
  69. package/docs/how-to-guides-manage-assets.md +255 -0
  70. package/docs/how-to-guides-manage-assets.zh-TW.md +255 -0
  71. package/docs/how-to-guides-manage-assets.zh.md +255 -0
  72. package/docs/how-to-guides-manage-tokens.ja.md +179 -0
  73. package/docs/how-to-guides-manage-tokens.md +179 -0
  74. package/docs/how-to-guides-manage-tokens.zh-TW.md +179 -0
  75. package/docs/how-to-guides-manage-tokens.zh.md +179 -0
  76. package/docs/how-to-guides-stake-tokens-and-assets.ja.md +205 -0
  77. package/docs/how-to-guides-stake-tokens-and-assets.md +205 -0
  78. package/docs/how-to-guides-stake-tokens-and-assets.zh-TW.md +205 -0
  79. package/docs/how-to-guides-stake-tokens-and-assets.zh.md +205 -0
  80. package/docs/how-to-guides-transfer-tokens-and-nfts.ja.md +179 -0
  81. package/docs/how-to-guides-transfer-tokens-and-nfts.md +179 -0
  82. package/docs/how-to-guides-transfer-tokens-and-nfts.zh-TW.md +179 -0
  83. package/docs/how-to-guides-transfer-tokens-and-nfts.zh.md +179 -0
  84. package/docs/how-to-guides.ja.md +27 -0
  85. package/docs/how-to-guides.md +27 -0
  86. package/docs/how-to-guides.zh-TW.md +27 -0
  87. package/docs/how-to-guides.zh.md +27 -0
  88. package/docs/overview.ja.md +70 -0
  89. package/docs/overview.md +70 -0
  90. package/docs/overview.zh-TW.md +70 -0
  91. package/docs/overview.zh.md +70 -0
  92. package/package.json +14 -14
@@ -0,0 +1,179 @@
1
+ # Transfer Tokens and NFTs
2
+
3
+ This guide provides a step-by-step walkthrough for transferring fungible tokens (both native and custom) and non-fungible tokens (NFTs or assets) between accounts using the OCAP Client. The primary method for all transfers is `client.transfer()`.
4
+
5
+ One key feature to remember is that a new account is automatically created on-chain when it receives its first incoming transaction. This means you can transfer tokens or assets to a brand new address without any prior setup for the recipient.
6
+
7
+ ## The `transfer` Method
8
+
9
+ The `client.transfer()` method is a versatile helper function that simplifies the process of sending assets and tokens. It constructs, signs, and sends the appropriate transaction (`transferV2Tx`) to the blockchain in a single call.
10
+
11
+ ### Parameters
12
+
13
+ <x-field-group>
14
+ <x-field data-name="to" data-type="string" data-required="true">
15
+ <x-field-desc markdown>The recipient's account address. This must be a valid DID address.</x-field-desc>
16
+ </x-field>
17
+ <x-field data-name="wallet" data-type="WalletObject" data-required="true" data-desc="The sender's wallet object used to sign the transaction."></x-field>
18
+ <x-field data-name="token" data-type="number" data-default="0">
19
+ <x-field-desc markdown>The amount of the chain's native token to transfer. The client handles the conversion to the correct decimal units automatically.</x-field-desc>
20
+ </x-field>
21
+ <x-field data-name="assets" data-type="string[]" data-default="[]" data-desc="An array of asset addresses (NFTs) to transfer."></x-field>
22
+ <x-field data-name="tokens" data-type="object[]" data-default="[]">
23
+ <x-field-desc markdown>An array of custom fungible token objects to transfer.</x-field-desc>
24
+ <x-field data-name="address" data-type="string" data-required="true" data-desc="The address of the custom token contract."></x-field>
25
+ <x-field data-name="value" data-type="number" data-required="true" data-desc="The amount of the custom token to transfer."></x-field>
26
+ </x-field>
27
+ <x-field data-name="memo" data-type="string" data-required="false" data-desc="An optional message or note to include with the transaction."></x-field>
28
+ <x-field data-name="delegator" data-type="string" data-required="false">
29
+ <x-field-desc markdown>If the `wallet` is acting on behalf of another account, this should be the address of the delegating account. See the [Delegate Permissions](./how-to-guides-delegate-permissions.md) guide for more details.</x-field-desc>
30
+ </x-field>
31
+ </x-field-group>
32
+
33
+ ### Returns
34
+
35
+ <x-field data-name="Promise<string>" data-type="Promise">
36
+ <x-field-desc markdown>A Promise that resolves to the transaction hash upon successful submission to the blockchain.</x-field-desc>
37
+ </x-field>
38
+
39
+ ## Step-by-Step Examples
40
+
41
+ ### Prerequisites
42
+
43
+ Before you start, make sure you have:
44
+
45
+ 1. An initialized `GraphQLClient` connected to a chain host like `https://beta.abtnetwork.io`.
46
+ 2. A sender's wallet object (`senderWallet`) that is funded with enough tokens to cover the transfer and transaction fees.
47
+ 3. A recipient's wallet object (`recipientWallet`) to get their address. The recipient's account does not need to exist on-chain yet.
48
+
49
+ ```javascript Basic Setup icon=logos:javascript
50
+ import GraphQLClient from '@ocap/client';
51
+ import { fromRandom } from '@ocap/wallet';
52
+
53
+ // 1. Initialize the client
54
+ const client = new GraphQLClient({ endpoint: 'https://beta.abtnetwork.io/api' });
55
+
56
+ // 2. Create wallets for sender and recipient
57
+ // In a real application, the sender's wallet would be loaded, not created randomly.
58
+ const senderWallet = fromRandom(); // Assume this wallet is funded
59
+ const recipientWallet = fromRandom();
60
+
61
+ console.log(`Sender Address: ${senderWallet.address}`);
62
+ console.log(`Recipient Address: ${recipientWallet.address}`);
63
+
64
+ // To fund the sender's wallet for this example, use the faucet:
65
+ // https://faucet.abtnetwork.io/
66
+ ```
67
+
68
+ ### Example 1: Transferring Native Tokens
69
+
70
+ This example shows how to send 10 native tokens from the sender to the recipient.
71
+
72
+ ```javascript Transfer Native Tokens icon=logos:javascript
73
+ async function transferNativeTokens() {
74
+ try {
75
+ const hash = await client.transfer({
76
+ to: recipientWallet.address,
77
+ token: 10, // The amount of native tokens to send
78
+ wallet: senderWallet,
79
+ memo: 'Sending you 10 native tokens!'
80
+ });
81
+ console.log('Native token transfer successful. Tx Hash:', hash);
82
+ } catch (err) {
83
+ console.error('Error transferring tokens:', err);
84
+ }
85
+ }
86
+
87
+ transferNativeTokens();
88
+ ```
89
+
90
+ ### Example 2: Transferring an NFT (Asset)
91
+
92
+ To transfer an NFT, you need its unique asset address. First, you would create or acquire an asset (see [Manage Assets (NFTs)](./how-to-guides-manage-assets.md)). For this example, let's assume `senderWallet` already owns an NFT with the address `zNKj...`.
93
+
94
+ ```javascript Transfer an NFT icon=logos:javascript
95
+ async function transferNFT() {
96
+ // Assume this is the address of an NFT owned by senderWallet
97
+ const nftAddress = 'zNKjL4wTmxQPk5nN2ADDPCd58286b2de3f3e';
98
+
99
+ try {
100
+ const hash = await client.transfer({
101
+ to: recipientWallet.address,
102
+ assets: [nftAddress], // An array of asset addresses
103
+ wallet: senderWallet,
104
+ memo: 'Here is the NFT you wanted.'
105
+ });
106
+ console.log('NFT transfer successful. Tx Hash:', hash);
107
+ } catch (err) {
108
+ console.error('Error transferring NFT:', err);
109
+ }
110
+ }
111
+
112
+ transferNFT();
113
+ ```
114
+
115
+ ### Example 3: Transferring Custom Tokens
116
+
117
+ This example demonstrates how to transfer a custom fungible token. You need the token's contract address. See the [Manage Tokens](./how-to-guides-manage-tokens.md) guide for information on creating custom tokens.
118
+
119
+ ```javascript Transfer Custom Tokens icon=logos:javascript
120
+ async function transferCustomToken() {
121
+ // Assume this is the address of a custom token owned by senderWallet
122
+ const customTokenAddress = 'z37bA4x...';
123
+
124
+ try {
125
+ const hash = await client.transfer({
126
+ to: recipientWallet.address,
127
+ wallet: senderWallet,
128
+ tokens: [
129
+ { address: customTokenAddress, value: 50 } // 50 units of a custom token
130
+ ],
131
+ memo: 'Sending 50 custom tokens.'
132
+ });
133
+ console.log('Custom token transfer successful. Tx Hash:', hash);
134
+ } catch (err) {
135
+ console.error('Error transferring custom token:', err);
136
+ }
137
+ }
138
+
139
+ transferCustomToken();
140
+ ```
141
+
142
+ ### Example 4: A Combined Transfer
143
+
144
+ You can send native tokens, custom tokens, and multiple NFTs all in a single, atomic transaction. This is highly efficient.
145
+
146
+ ```javascript Combined Transfer icon=logos:javascript
147
+ async function combinedTransfer() {
148
+ // Assume these are addresses of assets and tokens owned by senderWallet
149
+ const nftAddress1 = 'zNKjL4wTmxQPk5nN2ADDPCd58286b2de3f3e';
150
+ const nftAddress2 = 'zNKiabcdeQPk5nN2ADDPCd58286b2defghj';
151
+ const customTokenAddress = 'z37bA4x...'; // Address of a custom fungible token
152
+
153
+ try {
154
+ const hash = await client.transfer({
155
+ to: recipientWallet.address,
156
+ wallet: senderWallet,
157
+ token: 5, // 5 native tokens
158
+ assets: [nftAddress1, nftAddress2], // An array of two NFTs
159
+ tokens: [
160
+ { address: customTokenAddress, value: 50 } // 50 units of a custom token
161
+ ],
162
+ memo: 'Sending a mix of tokens and NFTs.'
163
+ });
164
+ console.log('Combined transfer successful. Tx Hash:', hash);
165
+ } catch (err) {
166
+ console.error('Error with combined transfer:', err);
167
+ }
168
+ }
169
+
170
+ combinedTransfer();
171
+ ```
172
+
173
+ By following these examples, you can easily implement token and NFT transfers in your application. For more details on creating the items you wish to transfer, please see the related guides.
174
+
175
+ ### Further Reading
176
+
177
+ - [How to Manage Assets (NFTs)](./how-to-guides-manage-assets.md)
178
+ - [How to Manage Tokens](./how-to-guides-manage-tokens.md)
179
+ - [High-level API](./api-reference-transaction-helpers.md)
@@ -0,0 +1,179 @@
1
+ # 轉移代幣和 NFT
2
+
3
+ 本指南提供了使用 OCAP Client 在帳戶之間轉移可替代代幣(包括原生和自訂代幣)和不可替代代幣(NFT 或資產)的逐步演練。所有轉移的主要方法是 `client.transfer()`。
4
+
5
+ 一個需要記住的關鍵功能是,當新帳戶收到第一筆傳入交易時,它會自動在鏈上創建。這意味著您可以將代幣或資產轉移到一個全新的地址,而無需為接收者進行任何預先設定。
6
+
7
+ ## `transfer` 方法
8
+
9
+ `client.transfer()` 方法是一個多功能的輔助函數,可簡化發送資產和代幣的過程。它在單次呼叫中建構、簽署並將適當的交易(`transferV2Tx`)發送到區塊鏈。
10
+
11
+ ### 參數
12
+
13
+ <x-field-group>
14
+ <x-field data-name="to" data-type="string" data-required="true">
15
+ <x-field-desc markdown>接收者的帳戶地址。這必須是一個有效的 DID 地址。</x-field-desc>
16
+ </x-field>
17
+ <x-field data-name="wallet" data-type="WalletObject" data-required="true" data-desc="用於簽署交易的發送者錢包物件。"></x-field>
18
+ <x-field data-name="token" data-type="number" data-default="0">
19
+ <x-field-desc markdown>要轉移的鏈原生代幣數量。客戶端會自動處理轉換為正確的小數位數。</x-field-desc>
20
+ </x-field>
21
+ <x-field data-name="assets" data-type="string[]" data-default="[]" data-desc="要轉移的資產地址(NFT)陣列。"></x-field>
22
+ <x-field data-name="tokens" data-type="object[]" data-default="[]">
23
+ <x-field-desc markdown>要轉移的自訂可替代代幣物件陣列。</x-field-desc>
24
+ <x-field data-name="address" data-type="string" data-required="true" data-desc="自訂代幣合約的地址。"></x-field>
25
+ <x-field data-name="value" data-type="number" data-required="true" data-desc="要轉移的自訂代幣數量。"></x-field>
26
+ </x-field>
27
+ <x-field data-name="memo" data-type="string" data-required="false" data-desc="可隨交易包含的選用訊息或備註。"></x-field>
28
+ <x-field data-name="delegator" data-type="string" data-required="false">
29
+ <x-field-desc markdown>如果 `wallet` 代表另一個帳戶行事,這應該是委託帳戶的地址。更多詳細資訊請參閱 [委派權限](./how-to-guides-delegate-permissions.md) 指南。</x-field-desc>
30
+ </x-field>
31
+ </x-field-group>
32
+
33
+ ### 返回值
34
+
35
+ <x-field data-name="Promise<string>" data-type="Promise">
36
+ <x-field-desc markdown>一個 Promise,在成功提交到區塊鏈後,會解析為交易雜湊值。</x-field-desc>
37
+ </x-field>
38
+
39
+ ## 逐步範例
40
+
41
+ ### 先決條件
42
+
43
+ 在開始之前,請確保您具備:
44
+
45
+ 1. 一個已初始化並連接到鏈主機(如 `https://beta.abtnetwork.io`)的 `GraphQLClient`。
46
+ 2. 一個發送者的錢包物件(`senderWallet`),其中有足夠的代幣來支付轉帳和交易費用。
47
+ 3. 一個接收者的錢包物件(`recipientWallet`)以獲取其地址。接收者的帳戶尚無需存在於鏈上。
48
+
49
+ ```javascript Basic Setup icon=logos:javascript
50
+ import GraphQLClient from '@ocap/client';
51
+ import { fromRandom } from '@ocap/wallet';
52
+
53
+ // 1. 初始化客戶端
54
+ const client = new GraphQLClient({ endpoint: 'https://beta.abtnetwork.io/api' });
55
+
56
+ // 2. 為發送者和接收者創建錢包
57
+ // 在實際應用中,發送者的錢包將被載入,而不是隨機創建。
58
+ const senderWallet = fromRandom(); // 假設此錢包已有資金
59
+ const recipientWallet = fromRandom();
60
+
61
+ console.log(`Sender Address: ${senderWallet.address}`);
62
+ console.log(`Recipient Address: ${recipientWallet.address}`);
63
+
64
+ // 要為此範例的發送者錢包注資,請使用水龍頭:
65
+ // https://faucet.abtnetwork.io/
66
+ ```
67
+
68
+ ### 範例 1:轉移原生代幣
69
+
70
+ 此範例展示了如何從發送者向接收者發送 10 個原生代幣。
71
+
72
+ ```javascript Transfer Native Tokens icon=logos:javascript
73
+ async function transferNativeTokens() {
74
+ try {
75
+ const hash = await client.transfer({
76
+ to: recipientWallet.address,
77
+ token: 10, // 要發送的原生代幣數量
78
+ wallet: senderWallet,
79
+ memo: '發送 10 個原生代幣給您!'
80
+ });
81
+ console.log('原生代幣轉移成功。交易雜湊值:', hash);
82
+ } catch (err) {
83
+ console.error('轉移代幣時出錯:', err);
84
+ }
85
+ }
86
+
87
+ transferNativeTokens();
88
+ ```
89
+
90
+ ### 範例 2:轉移 NFT(資產)
91
+
92
+ 要轉移 NFT,您需要其唯一的資產地址。首先,您需要創建或獲取一個資產(請參閱 [管理資產 (NFT)](./how-to-guides-manage-assets.md))。在此範例中,我們假設 `senderWallet` 已經擁有一個地址為 `zNKj...` 的 NFT。
93
+
94
+ ```javascript Transfer an NFT icon=logos:javascript
95
+ async function transferNFT() {
96
+ // 假設這是 senderWallet 擁有的 NFT 地址
97
+ const nftAddress = 'zNKjL4wTmxQPk5nN2ADDPCd58286b2de3f3e';
98
+
99
+ try {
100
+ const hash = await client.transfer({
101
+ to: recipientWallet.address,
102
+ assets: [nftAddress], // 資產地址的陣列
103
+ wallet: senderWallet,
104
+ memo: '這是您想要的 NFT。'
105
+ });
106
+ console.log('NFT 轉移成功。交易雜湊值:', hash);
107
+ } catch (err) {
108
+ console.error('轉移 NFT 時出錯:', err);
109
+ }
110
+ }
111
+
112
+ transferNFT();
113
+ ```
114
+
115
+ ### 範例 3:轉移自訂代幣
116
+
117
+ 此範例演示了如何轉移自訂的可替代代幣。您需要該代幣的合約地址。有關創建自訂代幣的資訊,請參閱 [管理代幣](./how-to-guides-manage-tokens.md) 指南。
118
+
119
+ ```javascript Transfer Custom Tokens icon=logos:javascript
120
+ async function transferCustomToken() {
121
+ // 假設這是 senderWallet 擁有的自訂代幣地址
122
+ const customTokenAddress = 'z37bA4x...';
123
+
124
+ try {
125
+ const hash = await client.transfer({
126
+ to: recipientWallet.address,
127
+ wallet: senderWallet,
128
+ tokens: [
129
+ { address: customTokenAddress, value: 50 } // 50 單位的自訂代幣
130
+ ],
131
+ memo: '發送 50 個自訂代幣。'
132
+ });
133
+ console.log('自訂代幣轉移成功。交易雜湊值:', hash);
134
+ } catch (err) {
135
+ console.error('轉移自訂代幣時出錯:', err);
136
+ }
137
+ }
138
+
139
+ transferCustomToken();
140
+ ```
141
+
142
+ ### 範例 4:組合轉移
143
+
144
+ 您可以在單一的原子交易中發送原生代幣、自訂代幣和多個 NFT。這是非常高效的。
145
+
146
+ ```javascript Combined Transfer icon=logos:javascript
147
+ async function combinedTransfer() {
148
+ // 假設這些是 senderWallet 擁有的資產和代幣地址
149
+ const nftAddress1 = 'zNKjL4wTmxQPk5nN2ADDPCd58286b2de3f3e';
150
+ const nftAddress2 = 'zNKiabcdeQPk5nN2ADDPCd58286b2defghj';
151
+ const customTokenAddress = 'z37bA4x...'; // 自訂可替代代幣的地址
152
+
153
+ try {
154
+ const hash = await client.transfer({
155
+ to: recipientWallet.address,
156
+ wallet: senderWallet,
157
+ token: 5, // 5 個原生代幣
158
+ assets: [nftAddress1, nftAddress2], // 包含兩個 NFT 的陣列
159
+ tokens: [
160
+ { address: customTokenAddress, value: 50 } // 50 單位的自訂代幣
161
+ ],
162
+ memo: '發送混合的代幣和 NFT。'
163
+ });
164
+ console.log('組合轉移成功。交易雜湊值:', hash);
165
+ } catch (err) {
166
+ console.error('組合轉移時出錯:', err);
167
+ }
168
+ }
169
+
170
+ combinedTransfer();
171
+ ```
172
+
173
+ 通過遵循這些範例,您可以輕鬆地在您的應用程式中實現代幣和 NFT 的轉移。有關創建您希望轉移的項目的更多詳細資訊,請參閱相關指南。
174
+
175
+ ### 延伸閱讀
176
+
177
+ - [如何管理資產 (NFT)](./how-to-guides-manage-assets.md)
178
+ - [如何管理代幣](./how-to-guides-manage-tokens.md)
179
+ - [高階 API](./api-reference-transaction-helpers.md)
@@ -0,0 +1,179 @@
1
+ # 转移通证和 NFT
2
+
3
+ 本指南提供了使用 OCAP Client 在账户之间转移可替代通证(包括原生和自定义通证)和非可替代通证(NFT 或资产)的详细步骤。所有转移操作的主要方法是 `client.transfer()`。
4
+
5
+ 需要记住的一个关键特性是,当一个新账户首次接收到交易时,它会自动在链上创建。这意味着你可以将通证或资产转移到一个全新的地址,而无需接收方进行任何预先设置。
6
+
7
+ ## `transfer` 方法
8
+
9
+ `client.transfer()` 方法是一个多功能的辅助函数,它简化了发送资产和通证的过程。它通过一次调用即可构建、签名并将相应的交易(`transferV2Tx`)发送到区块链。
10
+
11
+ ### 参数
12
+
13
+ <x-field-group>
14
+ <x-field data-name="to" data-type="string" data-required="true">
15
+ <x-field-desc markdown>接收方的账户地址。这必须是一个有效的 DID 地址。</x-field-desc>
16
+ </x-field>
17
+ <x-field data-name="wallet" data-type="WalletObject" data-required="true" data-desc="用于签署交易的发送方钱包对象。"></x-field>
18
+ <x-field data-name="token" data-type="number" data-default="0">
19
+ <x-field-desc markdown>要转移的链上原生通证的数量。客户端会自动处理到正确小数单位的转换。</x-field-desc>
20
+ </x-field>
21
+ <x-field data-name="assets" data-type="string[]" data-default="[]" data-desc="要转移的资产地址(NFT)数组。"></x-field>
22
+ <x-field data-name="tokens" data-type="object[]" data-default="[]">
23
+ <x-field-desc markdown>要转移的自定义可替代通证对象数组。</x-field-desc>
24
+ <x-field data-name="address" data-type="string" data-required="true" data-desc="自定义通证合约的地址。"></x-field>
25
+ <x-field data-name="value" data-type="number" data-required="true" data-desc="要转移的自定义通证的数量。"></x-field>
26
+ </x-field>
27
+ <x-field data-name="memo" data-type="string" data-required="false" data-desc="交易中包含的可选消息或备注。"></x-field>
28
+ <x-field data-name="delegator" data-type="string" data-required="false">
29
+ <x-field-desc markdown>如果 `wallet` 代表另一个账户操作,则此项应为委托账户的地址。更多详情请参阅 [委托权限](./how-to-guides-delegate-permissions.md) 指南。</x-field-desc>
30
+ </x-field>
31
+ </x-field-group>
32
+
33
+ ### 返回值
34
+
35
+ <x-field data-name="Promise<string>" data-type="Promise">
36
+ <x-field-desc markdown>一个 Promise,在成功提交到区块链后解析为交易哈希值。</x-field-desc>
37
+ </x-field>
38
+
39
+ ## 分步示例
40
+
41
+ ### 先决条件
42
+
43
+ 在开始之前,请确保你已具备:
44
+
45
+ 1. 一个已初始化并连接到链主机(如 `https://beta.abtnetwork.io`)的 `GraphQLClient`。
46
+ 2. 一个发送方的钱包对象(`senderWallet`),其中有足够的通证用于支付转账和交易费用。
47
+ 3. 一个接收方的钱包对象(`recipientWallet`),用于获取其地址。接收方的账户无需事先在链上存在。
48
+
49
+ ```javascript Basic Setup icon=logos:javascript
50
+ import GraphQLClient from '@ocap/client';
51
+ import { fromRandom } from '@ocap/wallet';
52
+
53
+ // 1. 初始化客户端
54
+ const client = new GraphQLClient({ endpoint: 'https://beta.abtnetwork.io/api' });
55
+
56
+ // 2. 为发送方和接收方创建钱包
57
+ // 在实际应用中,发送方的钱包应是加载而来,而不是随机创建的。
58
+ const senderWallet = fromRandom(); // 假设此钱包已有资金
59
+ const recipientWallet = fromRandom();
60
+
61
+ console.log(`发送方地址: ${senderWallet.address}`);
62
+ console.log(`接收方地址: ${recipientWallet.address}`);
63
+
64
+ // 要为此示例的发送方钱包充值,请使用水龙头:
65
+ // https://faucet.abtnetwork.io/
66
+ ```
67
+
68
+ ### 示例 1:转移原生通证
69
+
70
+ 此示例展示了如何从发送方向接收方发送 10 个原生通证。
71
+
72
+ ```javascript Transfer Native Tokens icon=logos:javascript
73
+ async function transferNativeTokens() {
74
+ try {
75
+ const hash = await client.transfer({
76
+ to: recipientWallet.address,
77
+ token: 10, // 要发送的原生通证数量
78
+ wallet: senderWallet,
79
+ memo: '发送给你 10 个原生通证!'
80
+ });
81
+ console.log('原生通证转移成功。交易哈希:', hash);
82
+ } catch (err) {
83
+ console.error('转移通证时出错:', err);
84
+ }
85
+ }
86
+
87
+ transferNativeTokens();
88
+ ```
89
+
90
+ ### 示例 2:转移 NFT(资产)
91
+
92
+ 要转移一个 NFT,你需要其唯一的资产地址。首先,你需要创建或获取一个资产(参见 [管理资产 (NFTs)](./how-to-guides-manage-assets.md))。在本例中,我们假设 `senderWallet` 已经拥有一个地址为 `zNKj...` 的 NFT。
93
+
94
+ ```javascript Transfer an NFT icon=logos:javascript
95
+ async function transferNFT() {
96
+ // 假设这是 senderWallet 拥有的一个 NFT 的地址
97
+ const nftAddress = 'zNKjL4wTmxQPk5nN2ADDPCd58286b2de3f3e';
98
+
99
+ try {
100
+ const hash = await client.transfer({
101
+ to: recipientWallet.address,
102
+ assets: [nftAddress], // 一个资产地址数组
103
+ wallet: senderWallet,
104
+ memo: '这是你想要的 NFT。'
105
+ });
106
+ console.log('NFT 转移成功。交易哈希:', hash);
107
+ } catch (err) {
108
+ console.error('转移 NFT 时出错:', err);
109
+ }
110
+ }
111
+
112
+ transferNFT();
113
+ ```
114
+
115
+ ### 示例 3:转移自定义通证
116
+
117
+ 此示例演示了如何转移自定义可替代通证。你需要该通证的合约地址。有关创建自定义通证的信息,请参阅 [管理通证](./how-to-guides-manage-tokens.md) 指南。
118
+
119
+ ```javascript Transfer Custom Tokens icon=logos:javascript
120
+ async function transferCustomToken() {
121
+ // 假设这是 senderWallet 拥有的一个自定义通证的地址
122
+ const customTokenAddress = 'z37bA4x...';
123
+
124
+ try {
125
+ const hash = await client.transfer({
126
+ to: recipientWallet.address,
127
+ wallet: senderWallet,
128
+ tokens: [
129
+ { address: customTokenAddress, value: 50 } // 50 个单位的自定义通证
130
+ ],
131
+ memo: '发送 50 个自定义通证。'
132
+ });
133
+ console.log('自定义通证转移成功。交易哈希:', hash);
134
+ } catch (err) {
135
+ console.error('转移自定义通证时出错:', err);
136
+ }
137
+ }
138
+
139
+ transferCustomToken();
140
+ ```
141
+
142
+ ### 示例 4:组合转移
143
+
144
+ 你可以在一个单一的原子交易中同时发送原生通证、自定义通证和多个 NFT。这是非常高效的。
145
+
146
+ ```javascript Combined Transfer icon=logos:javascript
147
+ async function combinedTransfer() {
148
+ // 假设这些是 senderWallet 拥有的资产和通证的地址
149
+ const nftAddress1 = 'zNKjL4wTmxQPk5nN2ADDPCd58286b2de3f3e';
150
+ const nftAddress2 = 'zNKiabcdeQPk5nN2ADDPCd58286b2defghj';
151
+ const customTokenAddress = 'z37bA4x...'; // 自定义可替代通证的地址
152
+
153
+ try {
154
+ const hash = await client.transfer({
155
+ to: recipientWallet.address,
156
+ wallet: senderWallet,
157
+ token: 5, // 5 个原生通证
158
+ assets: [nftAddress1, nftAddress2], // 包含两个 NFT 的数组
159
+ tokens: [
160
+ { address: customTokenAddress, value: 50 } // 50 个单位的自定义通证
161
+ ],
162
+ memo: '发送混合的通证和 NFT。'
163
+ });
164
+ console.log('组合转移成功。交易哈希:', hash);
165
+ } catch (err) {
166
+ console.error('组合转移时出错:', err);
167
+ }
168
+ }
169
+
170
+ combinedTransfer();
171
+ ```
172
+
173
+ 通过遵循这些示例,你可以轻松地在你的应用程序中实现通证和 NFT 的转移。有关创建你希望转移的项目的更多详细信息,请参阅相关指南。
174
+
175
+ ### 拓展阅读
176
+
177
+ - [如何管理资产 (NFTs)](./how-to-guides-manage-assets.md)
178
+ - [如何管理通证](./how-to-guides-manage-tokens.md)
179
+ - [高级 API](./api-reference-transaction-helpers.md)
@@ -0,0 +1,27 @@
1
+ # ハウツーガイド
2
+
3
+ このセクションでは、OCAP Clientを使用して一般的なタスクを完了するための実践的でステップバイステップの手順を説明します。各ガイドは、アカウントの管理から複雑なアトミックスワップの実行まで、特定の目標を達成するのに役立つ自己完結型のレシピとして設計されています。
4
+
5
+ <x-cards data-columns="2">
6
+ <x-card data-title="アカウントの管理" data-href="/how-to-guides/manage-accounts" data-icon="lucide:user-cog">
7
+ アカウントを新しいキーに移行するなど、アカウント関連の操作について説明します。
8
+ </x-card>
9
+ <x-card data-title="権限の委任" data-href="/how-to-guides/delegate-permissions" data-icon="lucide:key-round">
10
+ あなたに代わってトランザクションを送信するために別のアカウントを承認する方法を示し、許可されるアクションを指定します。
11
+ </x-card>
12
+ <x-card data-title="トークンとNFTの転送" data-href="/how-to-guides/transfer-tokens-and-nfts" data-icon="lucide:arrow-right-left">
13
+ ファンジブルトークンとノンファンジブルトークン(アセット)をアカウント間で転送するためのステップバイステップガイドを提供します。
14
+ </x-card>
15
+ <x-card data-title="アセット(NFT)の管理" data-href="/how-to-guides/manage-assets" data-icon="lucide:gem">
16
+ ファクトリーからのアセットの作成、更新、取得など、ノンファンジブルトークンの完全なライフサイクルを解説します。
17
+ </x-card>
18
+ <x-card data-title="トークンの管理" data-href="/how-to-guides/manage-tokens" data-icon="lucide:coins">
19
+ トークンファクトリーからトークンをミントおよびバーンするなどのファンジブルトークン操作の実行方法を説明します。
20
+ </x-card>
21
+ <x-card data-title="トークンとアセットのステーク" data-href="/how-to-guides/stake-tokens-and-assets" data-icon="lucide:piggy-bank">
22
+ トークンやアセットをレシーバーにステークする方法、ステークの取り消しや請求を含むステップバイステップガイドです。
23
+ </x-card>
24
+ <x-card data-title="アトミックスワップの実行" data-href="/how-to-guides/perform-atomic-swaps" data-icon="lucide:repeat">
25
+ マルチシグネチャトランザクションを使用して、2つの当事者間でトークンとアセットを安全に交換する方法に関するガイドです。
26
+ </x-card>
27
+ </x-cards>
@@ -0,0 +1,27 @@
1
+ # How-to Guides
2
+
3
+ This section provides practical, step-by-step instructions for completing common tasks with the OCAP Client. Each guide is designed as a self-contained recipe to help you accomplish a specific goal, from managing accounts to performing complex atomic swaps.
4
+
5
+ <x-cards data-columns="2">
6
+ <x-card data-title="Manage Accounts" data-href="/how-to-guides/manage-accounts" data-icon="lucide:user-cog">
7
+ Covers account-related operations such as migrating an account to new keys.
8
+ </x-card>
9
+ <x-card data-title="Delegate Permissions" data-href="/how-to-guides/delegate-permissions" data-icon="lucide:key-round">
10
+ Shows how to authorize another account to send transactions on your behalf, specifying which actions are permitted.
11
+ </x-card>
12
+ <x-card data-title="Transfer Tokens and NFTs" data-href="/how-to-guides/transfer-tokens-and-nfts" data-icon="lucide:arrow-right-left">
13
+ Provides a step-by-step guide on transferring fungible tokens and non-fungible tokens (assets) between accounts.
14
+ </x-card>
15
+ <x-card data-title="Manage Assets (NFTs)" data-href="/how-to-guides/manage-assets" data-icon="lucide:gem">
16
+ Walks through the complete lifecycle of Non-Fungible Tokens, including creation, updating, and acquiring assets from a factory.
17
+ </x-card>
18
+ <x-card data-title="Manage Tokens" data-href="/how-to-guides/manage-tokens" data-icon="lucide:coins">
19
+ Explains how to perform fungible token operations like minting and burning tokens from a token factory.
20
+ </x-card>
21
+ <x-card data-title="Stake Tokens and Assets" data-href="/how-to-guides/stake-tokens-and-assets" data-icon="lucide:piggy-bank">
22
+ A step-by-step guide on how to stake tokens or assets to a receiver, including revoking and claiming stakes.
23
+ </x-card>
24
+ <x-card data-title="Perform Atomic Swaps" data-href="/how-to-guides/perform-atomic-swaps" data-icon="lucide:repeat">
25
+ A guide on how to securely exchange tokens and assets between two parties using a multi-signature transaction.
26
+ </x-card>
27
+ </x-cards>
@@ -0,0 +1,27 @@
1
+ # 操作指南
2
+
3
+ 本節提供使用 OCAP 用戶端完成常見任務的實用、逐步說明。每個指南都設計成一個獨立的方案,幫助您完成特定目標,從管理帳戶到執行複雜的原子交換。
4
+
5
+ <x-cards data-columns="2">
6
+ <x-card data-title="管理帳戶" data-href="/how-to-guides/manage-accounts" data-icon="lucide:user-cog">
7
+ 涵蓋與帳戶相關的操作,例如將帳戶遷移到新的金鑰。
8
+ </x-card>
9
+ <x-card data-title="委派權限" data-href="/how-to-guides/delegate-permissions" data-icon="lucide:key-round">
10
+ 展示如何授權另一個帳戶代表您發送交易,並指定允許的操作。
11
+ </x-card>
12
+ <x-card data-title="轉移代幣和 NFT" data-href="/how-to-guides/transfer-tokens-and-nfts" data-icon="lucide:arrow-right-left">
13
+ 提供在帳戶之間轉移同質化代幣和非同質化代幣(資產)的逐步指南。
14
+ </x-card>
15
+ <x-card data-title="管理資產(NFT)" data-href="/how-to-guides/manage-assets" data-icon="lucide:gem">
16
+ 詳細介紹非同質化代幣的完整生命週期,包括從工廠創建、更新和獲取資產。
17
+ </x-card>
18
+ <x-card data-title="管理代幣" data-href="/how-to-guides/manage-tokens" data-icon="lucide:coins">
19
+ 解釋如何執行同質化代幣操作,例如從代幣工廠鑄造和銷毀代幣。
20
+ </x-card>
21
+ <x-card data-title="質押代幣和資產" data-href="/how-to-guides/stake-tokens-and-assets" data-icon="lucide:piggy-bank">
22
+ 關於如何將代幣或資產質押給接收者的逐步指南,包括撤銷和領取質押。
23
+ </x-card>
24
+ <x-card data-title="執行原子交換" data-href="/how-to-guides/perform-atomic-swaps" data-icon="lucide:repeat">
25
+ 關於如何使用多重簽名交易在兩方之間安全交換代幣和資產的指南。
26
+ </x-card>
27
+ </x-cards>
@@ -0,0 +1,27 @@
1
+ # 操作指南
2
+
3
+ 本节提供了使用 OCAP Client 完成常见任务的实用、分步说明。每个指南都设计成一个独立的方案,帮助您完成特定目标,从管理账户到执行复杂的原子交换。
4
+
5
+ <x-cards data-columns="2">
6
+ <x-card data-title="管理账户" data-href="/how-to-guides/manage-accounts" data-icon="lucide:user-cog">
7
+ 涵盖与账户相关的操作,例如将账户迁移到新密钥。
8
+ </x-card>
9
+ <x-card data-title="委托权限" data-href="/how-to-guides/delegate-permissions" data-icon="lucide:key-round">
10
+ 展示了如何授权另一个账户代表您发送交易,并指定允许的操作。
11
+ </x-card>
12
+ <x-card data-title="转移通证和 NFT" data-href="/how-to-guides/transfer-tokens-and-nfts" data-icon="lucide:arrow-right-left">
13
+ 提供了在账户之间转移同质化通证和非同质化通证(资产)的分步指南。
14
+ </x-card>
15
+ <x-card data-title="管理资产 (NFT)" data-href="/how-to-guides/manage-assets" data-icon="lucide:gem">
16
+ 逐步介绍非同质化通证的完整生命周期,包括创建、更新以及从工厂获取资产。
17
+ </x-card>
18
+ <x-card data-title="管理通证" data-href="/how-to-guides/manage-tokens" data-icon="lucide:coins">
19
+ 解释了如何执行同质化通证操作,例如从通证工厂铸造和销毁通证。
20
+ </x-card>
21
+ <x-card data-title="质押通证和资产" data-href="/how-to-guides/stake-tokens-and-assets" data-icon="lucide:piggy-bank">
22
+ 关于如何将通证或资产质押给接收者的分步指南,包括撤销和领取质押。
23
+ </x-card>
24
+ <x-card data-title="执行原子交换" data-href="/how-to-guides/perform-atomic-swaps" data-icon="lucide:repeat">
25
+ 关于如何使用多重签名交易在两方之间安全交换通证和资产的指南。
26
+ </x-card>
27
+ </x-cards>