@ton/ton 16.1.0 → 16.2.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 (131) hide show
  1. package/README.md +47 -11
  2. package/dist/client/TonClient.d.ts +6 -6
  3. package/dist/client/TonClient.js +105 -80
  4. package/dist/client/TonClient4.d.ts +1 -1
  5. package/dist/client/TonClient4.js +227 -138
  6. package/dist/client/api/HttpApi.d.ts +122 -122
  7. package/dist/client/api/HttpApi.js +103 -72
  8. package/dist/client/api/TonCache.js +3 -3
  9. package/dist/config/ConfigParser.js +133 -112
  10. package/dist/elector/ElectorContract.js +46 -20
  11. package/dist/index.d.ts +22 -22
  12. package/dist/jetton/JettonMaster.js +5 -3
  13. package/dist/jetton/JettonWallet.js +2 -2
  14. package/dist/multisig/MultisigOrder.d.ts +2 -2
  15. package/dist/multisig/MultisigOrder.js +1 -1
  16. package/dist/multisig/MultisigOrderBuilder.d.ts +2 -2
  17. package/dist/multisig/MultisigOrderBuilder.js +1 -1
  18. package/dist/multisig/MultisigWallet.d.ts +3 -3
  19. package/dist/multisig/MultisigWallet.js +8 -8
  20. package/dist/utils/createTestClient.d.ts +1 -1
  21. package/dist/utils/createTestClient.js +6 -2
  22. package/dist/utils/createTestClient4.d.ts +1 -1
  23. package/dist/utils/createTestClient4.js +5 -1
  24. package/dist/utils/fees.d.ts +2 -2
  25. package/dist/utils/fees.js +21 -6
  26. package/dist/utils/{randomTestKey.d.ts → testUtils.d.ts} +2 -0
  27. package/dist/utils/testUtils.js +21 -0
  28. package/dist/utils/testWallets.d.ts +10 -10
  29. package/dist/utils/time.js +5 -3
  30. package/dist/utils/toUrlSafe.js +6 -6
  31. package/dist/wallets/WalletContractV1R1.d.ts +1 -57
  32. package/dist/wallets/WalletContractV1R1.js +15 -99
  33. package/dist/wallets/WalletContractV1R2.d.ts +1 -57
  34. package/dist/wallets/WalletContractV1R2.js +15 -100
  35. package/dist/wallets/WalletContractV1R3.d.ts +1 -57
  36. package/dist/wallets/WalletContractV1R3.js +15 -99
  37. package/dist/wallets/WalletContractV2R1.d.ts +1 -59
  38. package/dist/wallets/WalletContractV2R1.js +15 -101
  39. package/dist/wallets/WalletContractV2R2.d.ts +1 -59
  40. package/dist/wallets/WalletContractV2R2.js +15 -101
  41. package/dist/wallets/WalletContractV3R1.d.ts +1 -56
  42. package/dist/wallets/WalletContractV3R1.js +15 -103
  43. package/dist/wallets/WalletContractV3R2.d.ts +1 -56
  44. package/dist/wallets/WalletContractV3R2.js +15 -103
  45. package/dist/wallets/WalletContractV4.d.ts +2 -2
  46. package/dist/wallets/WalletContractV5Beta.d.ts +3 -3
  47. package/dist/wallets/WalletContractV5R1.d.ts +3 -3
  48. package/dist/wallets/signing/createWalletTransfer.d.ts +11 -3
  49. package/dist/wallets/signing/createWalletTransfer.js +18 -15
  50. package/dist/wallets/signing/singer.d.ts +2 -1
  51. package/dist/wallets/signing/singer.js +11 -5
  52. package/dist/wallets/v1/r1.d.ts +59 -0
  53. package/dist/wallets/v1/r1.js +103 -0
  54. package/dist/wallets/v1/r2.d.ts +59 -0
  55. package/dist/wallets/v1/r2.js +104 -0
  56. package/dist/wallets/v1/r3.d.ts +59 -0
  57. package/dist/wallets/v1/r3.js +103 -0
  58. package/dist/wallets/v2/r1.d.ts +61 -0
  59. package/dist/wallets/v2/r1.js +107 -0
  60. package/dist/wallets/v2/r2.d.ts +61 -0
  61. package/dist/wallets/v2/r2.js +107 -0
  62. package/dist/wallets/v3/r1.d.ts +58 -0
  63. package/dist/wallets/v3/r1.js +109 -0
  64. package/dist/wallets/v3/r2.d.ts +58 -0
  65. package/dist/wallets/v3/r2.js +109 -0
  66. package/dist/wallets/v4/WalletContractV4.d.ts +4 -2
  67. package/dist/wallets/v4/WalletContractV4.js +36 -32
  68. package/dist/wallets/v4/WalletContractV4Actions.d.ts +4 -4
  69. package/dist/wallets/v4/WalletContractV4Actions.js +10 -10
  70. package/dist/wallets/v5beta/WalletContractV5Beta.d.ts +7 -5
  71. package/dist/wallets/v5beta/WalletContractV5Beta.js +44 -28
  72. package/dist/wallets/v5beta/WalletV5BetaActions.d.ts +1 -1
  73. package/dist/wallets/v5beta/WalletV5BetaActions.js +25 -18
  74. package/dist/wallets/v5beta/WalletV5BetaWalletId.d.ts +2 -2
  75. package/dist/wallets/v5beta/WalletV5BetaWalletId.js +6 -4
  76. package/dist/wallets/v5beta/WalletV5OutActions.d.ts +4 -4
  77. package/dist/wallets/v5beta/WalletV5OutActions.js +3 -1
  78. package/dist/wallets/v5r1/WalletContractV5R1.d.ts +10 -6
  79. package/dist/wallets/v5r1/WalletContractV5R1.js +55 -36
  80. package/dist/wallets/v5r1/WalletV5R1Actions.d.ts +3 -3
  81. package/dist/wallets/v5r1/WalletV5R1Actions.js +32 -25
  82. package/dist/wallets/v5r1/WalletV5R1WalletId.d.ts +2 -2
  83. package/dist/wallets/v5r1/WalletV5R1WalletId.js +16 -10
  84. package/package.json +62 -65
  85. package/dist/client/TonClient.spec.d.ts +0 -1
  86. package/dist/client/TonClient.spec.js +0 -59
  87. package/dist/client/TonClient4.spec.d.ts +0 -1
  88. package/dist/client/TonClient4.spec.js +0 -67
  89. package/dist/config/ConfigParser.spec.d.ts +0 -8
  90. package/dist/config/ConfigParser.spec.js +0 -247
  91. package/dist/elector/ElectorContract.spec.d.ts +0 -8
  92. package/dist/elector/ElectorContract.spec.js +0 -104
  93. package/dist/jetton/JettonMaster.spec.d.ts +0 -8
  94. package/dist/jetton/JettonMaster.spec.js +0 -27
  95. package/dist/multisig/MultisigOrder.spec.d.ts +0 -1
  96. package/dist/multisig/MultisigOrder.spec.js +0 -139
  97. package/dist/multisig/MultisigWallet.spec.d.ts +0 -1
  98. package/dist/multisig/MultisigWallet.spec.js +0 -248
  99. package/dist/utils/fees.spec.d.ts +0 -1
  100. package/dist/utils/fees.spec.js +0 -83
  101. package/dist/utils/randomTestKey.js +0 -23
  102. package/dist/wallets/WalletContractV1R1.spec.d.ts +0 -8
  103. package/dist/wallets/WalletContractV1R1.spec.js +0 -67
  104. package/dist/wallets/WalletContractV1R2.spec.d.ts +0 -8
  105. package/dist/wallets/WalletContractV1R2.spec.js +0 -67
  106. package/dist/wallets/WalletContractV1R3.spec.d.ts +0 -8
  107. package/dist/wallets/WalletContractV1R3.spec.js +0 -44
  108. package/dist/wallets/WalletContractV2R1.spec.d.ts +0 -8
  109. package/dist/wallets/WalletContractV2R1.spec.js +0 -67
  110. package/dist/wallets/WalletContractV2R2.spec.d.ts +0 -8
  111. package/dist/wallets/WalletContractV2R2.spec.js +0 -67
  112. package/dist/wallets/WalletContractV3R1.spec.d.ts +0 -8
  113. package/dist/wallets/WalletContractV3R1.spec.js +0 -67
  114. package/dist/wallets/WalletContractV3R2.spec.d.ts +0 -8
  115. package/dist/wallets/WalletContractV3R2.spec.js +0 -67
  116. package/dist/wallets/v4/WalletContractV4.spec.d.ts +0 -8
  117. package/dist/wallets/v4/WalletContractV4.spec.js +0 -157
  118. package/dist/wallets/v4/WalletContractV4Actions.spec.d.ts +0 -1
  119. package/dist/wallets/v4/WalletContractV4Actions.spec.js +0 -74
  120. package/dist/wallets/v5beta/WalletContractV5Beta.spec.d.ts +0 -8
  121. package/dist/wallets/v5beta/WalletContractV5Beta.spec.js +0 -317
  122. package/dist/wallets/v5beta/WalletV5BetaActions.spec.d.ts +0 -1
  123. package/dist/wallets/v5beta/WalletV5BetaActions.spec.js +0 -166
  124. package/dist/wallets/v5beta/WalletV5BetaWalletId.spec.d.ts +0 -1
  125. package/dist/wallets/v5beta/WalletV5BetaWalletId.spec.js +0 -68
  126. package/dist/wallets/v5r1/WalletContractV5R1.spec.d.ts +0 -8
  127. package/dist/wallets/v5r1/WalletContractV5R1.spec.js +0 -340
  128. package/dist/wallets/v5r1/WalletV5R1Actions.spec.d.ts +0 -1
  129. package/dist/wallets/v5r1/WalletV5R1Actions.spec.js +0 -262
  130. package/dist/wallets/v5r1/WalletV5R1WalletId.spec.d.ts +0 -1
  131. package/dist/wallets/v5r1/WalletV5R1WalletId.spec.js +0 -103
package/README.md CHANGED
@@ -30,7 +30,7 @@ To use this library you need HTTP API endpoint, you can use one of the public en
30
30
  - Mainnet: https://toncenter.com/api/v2/jsonRPC
31
31
  - Testnet: https://testnet.toncenter.com/api/v2/jsonRPC
32
32
 
33
- ```js
33
+ ```ts
34
34
  import { TonClient, WalletContractV4, internal } from "@ton/ton";
35
35
  import { mnemonicNew, mnemonicToPrivateKey } from "@ton/crypto";
36
36
 
@@ -40,20 +40,22 @@ const client = new TonClient({
40
40
  });
41
41
 
42
42
  // Generate new key
43
- let mnemonics = await mnemonicNew();
44
- let keyPair = await mnemonicToPrivateKey(mnemonics);
43
+ const mnemonic = await mnemonicNew();
44
+ const keyPair = await mnemonicToPrivateKey(mnemonic);
45
45
 
46
46
  // Create wallet contract
47
- let workchain = 0; // Usually you need a workchain 0
48
- let wallet = WalletContractV4.create({ workchain, publicKey: keyPair.publicKey });
49
- let contract = client.open(wallet);
47
+ const wallet = WalletContractV4.create({
48
+ workchain: 0, // basechain
49
+ publicKey: keyPair.publicKey,
50
+ });
51
+ const contract = client.open(wallet);
50
52
 
51
53
  // Get balance
52
- let balance: bigint = await contract.getBalance();
54
+ const balance = await contract.getBalance();
53
55
 
54
56
  // Create a transfer
55
- let seqno: number = await contract.getSeqno();
56
- let transfer = await contract.createTransfer({
57
+ const seqno = await contract.getSeqno();
58
+ const transfer = await contract.createTransfer({
57
59
  seqno,
58
60
  secretKey: keyPair.secretKey,
59
61
  messages: [internal({
@@ -62,12 +64,46 @@ let transfer = await contract.createTransfer({
62
64
  body: 'Hello world',
63
65
  })]
64
66
  });
67
+ ```
68
+
69
+ ## Formatting
70
+
71
+ We use `biome` as our formatter. It's prettier compatible and fast
72
+
73
+ IDE Setup: [VSCode](https://marketplace.visualstudio.com/items?itemName=biomejs.biome), [Zed](https://biomejs.dev/reference/zed/)
74
+
75
+ ```sh
76
+ yarn run format
77
+ ```
78
+
79
+ ## Testing
80
+
81
+ ### Debugging in tests
82
+
83
+ By default tests are running using multiple worker threads. It's faster, but
84
+ undesirable during debugging. `SINGLETHREADED` env variable covers this case
85
+
86
+ ```sh
87
+ SINGLETHREADED=1 yarn run test
88
+ ```
89
+
90
+ ### Coverage report
91
+
92
+ We use test coverage to eliminate blind spots in our tests.
93
+
94
+ #### How to?
95
+
96
+ The goal is to make all functions runned at least once
97
+
98
+ 1. Build a coverage report
65
99
 
100
+ ```sh
101
+ yarn run coverage
66
102
  ```
67
103
 
68
- ## Docs
104
+ 2. Coverage report is build to the `/coverage` directory
69
105
 
70
- [Documentation](https://ton-community.github.io/ton/)
106
+ 3. Open `/coverage/index.html` to check the report
71
107
 
72
108
  ## Acknowledgements
73
109
 
@@ -6,8 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  import { HttpApi } from "./api/HttpApi";
9
- import { AxiosAdapter } from 'axios';
10
- import { Address, Cell, Contract, ContractProvider, Message, Transaction, TupleItem, TupleReader, StateInit, OpenedContract } from '@ton/core';
9
+ import { AxiosAdapter } from "axios";
10
+ import { Address, Cell, Contract, ContractProvider, Message, Transaction, TupleItem, TupleReader, StateInit, OpenedContract } from "@ton/core";
11
11
  export type TonClientParameters = {
12
12
  /**
13
13
  * API Endpoint
@@ -65,7 +65,7 @@ export declare class TonClient {
65
65
  * @param name name of method
66
66
  * @param params optional parameters
67
67
  * @returns stack and gas_used field
68
- */
68
+ */
69
69
  runMethodWithError(address: Address, name: string, params?: any[]): Promise<{
70
70
  gas_used: number;
71
71
  stack: TupleReader;
@@ -170,9 +170,9 @@ export declare class TonClient {
170
170
  initData: Cell | null;
171
171
  ignoreSignature: boolean;
172
172
  }): Promise<{
173
- '@type': "query.fees";
173
+ "@type": "query.fees";
174
174
  source_fees: {
175
- '@type': "fees";
175
+ "@type": "fees";
176
176
  in_fwd_fee: number;
177
177
  storage_fee: number;
178
178
  gas_fee: number;
@@ -198,7 +198,7 @@ export declare class TonClient {
198
198
  getContractState(address: Address): Promise<{
199
199
  balance: bigint;
200
200
  extra_currencies: {
201
- '@type': "extraCurrency";
201
+ "@type": "extraCurrency";
202
202
  id: number;
203
203
  amount: string;
204
204
  }[] | undefined;
@@ -13,12 +13,12 @@ const core_1 = require("@ton/core");
13
13
  class TonClient {
14
14
  constructor(parameters) {
15
15
  this.parameters = {
16
- endpoint: parameters.endpoint
16
+ endpoint: parameters.endpoint,
17
17
  };
18
18
  this.api = new HttpApi_1.HttpApi(this.parameters.endpoint, {
19
19
  timeout: parameters.timeout,
20
20
  apiKey: parameters.apiKey,
21
- adapter: parameters.httpAdapter
21
+ adapter: parameters.httpAdapter,
22
22
  });
23
23
  }
24
24
  /**
@@ -39,7 +39,7 @@ class TonClient {
39
39
  async runMethod(address, name, stack = []) {
40
40
  let res = await this.api.callGetMethod(address, name, stack);
41
41
  if (res.exit_code !== 0) {
42
- throw Error('Unable to execute get method. Got exit_code: ' + res.exit_code);
42
+ throw Error("Unable to execute get method. Got exit_code: " + res.exit_code);
43
43
  }
44
44
  return { gas_used: res.gas_used, stack: parseStack(res.stack) };
45
45
  }
@@ -60,10 +60,14 @@ class TonClient {
60
60
  * @param name name of method
61
61
  * @param params optional parameters
62
62
  * @returns stack and gas_used field
63
- */
63
+ */
64
64
  async runMethodWithError(address, name, params = []) {
65
65
  let res = await this.api.callGetMethod(address, name, params);
66
- return { gas_used: res.gas_used, stack: parseStack(res.stack), exit_code: res.exit_code };
66
+ return {
67
+ gas_used: res.gas_used,
68
+ stack: parseStack(res.stack),
69
+ exit_code: res.exit_code,
70
+ };
67
71
  }
68
72
  /**
69
73
  * Invoke get method that returns error code instead of throwing error
@@ -85,7 +89,7 @@ class TonClient {
85
89
  let tx = await this.api.getTransactions(address, opts);
86
90
  let res = [];
87
91
  for (let r of tx) {
88
- res.push((0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(r.data, 'base64'))[0].beginParse()));
92
+ res.push((0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(r.data, "base64"))[0].beginParse()));
89
93
  }
90
94
  return res;
91
95
  }
@@ -99,7 +103,7 @@ class TonClient {
99
103
  async getTransaction(address, lt, hash) {
100
104
  let res = await this.api.getTransaction(address, lt, hash);
101
105
  if (res) {
102
- return (0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(res.data, 'base64'))[0].beginParse());
106
+ return (0, core_1.loadTransaction)(core_1.Cell.fromBoc(Buffer.from(res.data, "base64"))[0].beginParse());
103
107
  }
104
108
  else {
105
109
  return null;
@@ -137,7 +141,7 @@ class TonClient {
137
141
  workchain: r.init.workchain,
138
142
  shard: r.last.shard,
139
143
  initSeqno: r.init.seqno,
140
- latestSeqno: r.last.seqno
144
+ latestSeqno: r.last.seqno,
141
145
  };
142
146
  }
143
147
  /**
@@ -149,7 +153,7 @@ class TonClient {
149
153
  return r.map((m) => ({
150
154
  workchain: m.workchain,
151
155
  shard: m.shard,
152
- seqno: m.seqno
156
+ seqno: m.seqno,
153
157
  }));
154
158
  }
155
159
  /**
@@ -161,12 +165,12 @@ class TonClient {
161
165
  async getShardTransactions(workchain, seqno, shard) {
162
166
  let tx = await this.api.getBlockTransactions(workchain, seqno, shard);
163
167
  if (tx.incomplete) {
164
- throw Error('Unsupported');
168
+ throw Error("Unsupported");
165
169
  }
166
170
  return tx.transactions.map((v) => ({
167
171
  account: core_1.Address.parseRaw(v.account),
168
172
  lt: v.lt,
169
- hash: v.hash
173
+ hash: v.hash,
170
174
  }));
171
175
  }
172
176
  /**
@@ -174,10 +178,7 @@ class TonClient {
174
178
  * @param src source message
175
179
  */
176
180
  async sendMessage(src) {
177
- const boc = (0, core_1.beginCell)()
178
- .store((0, core_1.storeMessage)(src))
179
- .endCell()
180
- .toBoc();
181
+ const boc = (0, core_1.beginCell)().store((0, core_1.storeMessage)(src)).endCell().toBoc();
181
182
  await this.api.sendBoc(boc);
182
183
  }
183
184
  /**
@@ -193,7 +194,12 @@ class TonClient {
193
194
  * @returns
194
195
  */
195
196
  async estimateExternalMessageFee(address, args) {
196
- return await this.api.estimateFee(address, { body: args.body, initCode: args.initCode, initData: args.initData, ignoreSignature: args.ignoreSignature });
197
+ return await this.api.estimateFee(address, {
198
+ body: args.body,
199
+ initCode: args.initCode,
200
+ initData: args.initData,
201
+ ignoreSignature: args.ignoreSignature,
202
+ });
197
203
  }
198
204
  /**
199
205
  * Send external message to contract
@@ -201,10 +207,11 @@ class TonClient {
201
207
  * @param src message body
202
208
  */
203
209
  async sendExternalMessage(contract, src) {
204
- if (await this.isContractDeployed(contract.address) || !contract.init) {
210
+ if ((await this.isContractDeployed(contract.address)) ||
211
+ !contract.init) {
205
212
  const message = (0, core_1.external)({
206
213
  to: contract.address,
207
- body: src
214
+ body: src,
208
215
  });
209
216
  await this.sendMessage(message);
210
217
  }
@@ -212,7 +219,7 @@ class TonClient {
212
219
  const message = (0, core_1.external)({
213
220
  to: contract.address,
214
221
  init: contract.init,
215
- body: src
222
+ body: src,
216
223
  });
217
224
  await this.sendMessage(message);
218
225
  }
@@ -223,7 +230,7 @@ class TonClient {
223
230
  * @returns true if contract is in active state
224
231
  */
225
232
  async isContractDeployed(address) {
226
- return (await this.getContractState(address)).state === 'active';
233
+ return (await this.getContractState(address)).state === "active";
227
234
  }
228
235
  /**
229
236
  * Resolves contract state
@@ -237,18 +244,20 @@ class TonClient {
237
244
  balance,
238
245
  extra_currencies: info.extra_currencies,
239
246
  state,
240
- code: info.code !== '' ? Buffer.from(info.code, 'base64') : null,
241
- data: info.data !== '' ? Buffer.from(info.data, 'base64') : null,
242
- lastTransaction: info.last_transaction_id.lt !== '0' ? {
243
- lt: info.last_transaction_id.lt,
244
- hash: info.last_transaction_id.hash,
245
- } : null,
247
+ code: info.code !== "" ? Buffer.from(info.code, "base64") : null,
248
+ data: info.data !== "" ? Buffer.from(info.data, "base64") : null,
249
+ lastTransaction: info.last_transaction_id.lt !== "0"
250
+ ? {
251
+ lt: info.last_transaction_id.lt,
252
+ hash: info.last_transaction_id.hash,
253
+ }
254
+ : null,
246
255
  blockId: {
247
256
  workchain: info.block_id.workchain,
248
257
  shard: info.block_id.shard,
249
- seqno: info.block_id.seqno
258
+ seqno: info.block_id.seqno,
250
259
  },
251
- timestampt: info.sync_utime
260
+ timestampt: info.sync_utime,
252
261
  };
253
262
  }
254
263
  /**
@@ -271,61 +280,70 @@ class TonClient {
271
280
  }
272
281
  exports.TonClient = TonClient;
273
282
  function parseStackEntry(x) {
274
- const typeName = x['@type'];
283
+ const typeName = x["@type"];
275
284
  switch (typeName) {
276
- case 'tvm.list':
277
- case 'tvm.tuple':
285
+ case "tvm.list":
286
+ case "tvm.tuple":
278
287
  return x.elements.map(parseStackEntry);
279
- case 'tvm.cell':
280
- return core_1.Cell.fromBoc(Buffer.from(x.bytes, 'base64'))[0];
281
- case 'tvm.slice':
282
- return core_1.Cell.fromBoc(Buffer.from(x.bytes, 'base64'))[0];
283
- case 'tvm.stackEntryCell':
288
+ case "tvm.cell":
289
+ return core_1.Cell.fromBoc(Buffer.from(x.bytes, "base64"))[0];
290
+ case "tvm.slice":
291
+ return core_1.Cell.fromBoc(Buffer.from(x.bytes, "base64"))[0];
292
+ case "tvm.stackEntryCell":
284
293
  return parseStackEntry(x.cell);
285
- case 'tvm.stackEntrySlice':
294
+ case "tvm.stackEntrySlice":
286
295
  return parseStackEntry(x.slice);
287
- case 'tvm.stackEntryTuple':
296
+ case "tvm.stackEntryTuple":
288
297
  return parseStackEntry(x.tuple);
289
- case 'tvm.stackEntryList':
298
+ case "tvm.stackEntryList":
290
299
  return parseStackEntry(x.list);
291
- case 'tvm.stackEntryNumber':
300
+ case "tvm.stackEntryNumber":
292
301
  return parseStackEntry(x.number);
293
- case 'tvm.numberDecimal':
302
+ case "tvm.numberDecimal":
294
303
  return BigInt(x.number);
295
304
  default:
296
- throw Error('Unsupported item type: ' + typeName);
305
+ throw Error("Unsupported item type: " + typeName);
297
306
  }
298
307
  }
299
308
  function parseStackItem(s) {
300
- if (s[0] === 'num') {
309
+ if (s[0] === "num") {
301
310
  let val = s[1];
302
- if (val.startsWith('-')) {
303
- return { type: 'int', value: -BigInt(val.slice(1)) };
311
+ if (val.startsWith("-")) {
312
+ return { type: "int", value: -BigInt(val.slice(1)) };
304
313
  }
305
314
  else {
306
- return { type: 'int', value: BigInt(val) };
315
+ return { type: "int", value: BigInt(val) };
307
316
  }
308
317
  }
309
- else if (s[0] === 'null') {
310
- return { type: 'null' };
318
+ else if (s[0] === "null") {
319
+ return { type: "null" };
311
320
  }
312
- else if (s[0] === 'cell') {
313
- return { type: 'cell', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] };
321
+ else if (s[0] === "cell") {
322
+ return {
323
+ type: "cell",
324
+ cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, "base64"))[0],
325
+ };
314
326
  }
315
- else if (s[0] === 'slice') {
316
- return { type: 'slice', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] };
327
+ else if (s[0] === "slice") {
328
+ return {
329
+ type: "slice",
330
+ cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, "base64"))[0],
331
+ };
317
332
  }
318
- else if (s[0] === 'builder') {
319
- return { type: 'builder', cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, 'base64'))[0] };
333
+ else if (s[0] === "builder") {
334
+ return {
335
+ type: "builder",
336
+ cell: core_1.Cell.fromBoc(Buffer.from(s[1].bytes, "base64"))[0],
337
+ };
320
338
  }
321
- else if (s[0] === 'tuple' || s[0] === 'list') {
339
+ else if (s[0] === "tuple" || s[0] === "list") {
322
340
  if (s[1].elements.length === 0) {
323
- return { type: 'null' };
341
+ return { type: "null" };
324
342
  }
325
- return { type: 'tuple', items: s[1].elements.map(parseStackEntry) };
343
+ return { type: "tuple", items: s[1].elements.map(parseStackEntry) };
326
344
  }
327
345
  else {
328
- throw Error('Unsupported stack item type: ' + s[0]);
346
+ throw Error("Unsupported stack item type: " + s[0]);
329
347
  }
330
348
  }
331
349
  function parseStack(src) {
@@ -340,29 +358,34 @@ function createProvider(client, address, init) {
340
358
  async getState() {
341
359
  let state = await client.getContractState(address);
342
360
  let balance = state.balance;
343
- let last = state.lastTransaction ? { lt: BigInt(state.lastTransaction.lt), hash: Buffer.from(state.lastTransaction.hash, 'base64') } : null;
361
+ let last = state.lastTransaction
362
+ ? {
363
+ lt: BigInt(state.lastTransaction.lt),
364
+ hash: Buffer.from(state.lastTransaction.hash, "base64"),
365
+ }
366
+ : null;
344
367
  let ecMap = null;
345
368
  let storage;
346
- if (state.state === 'active') {
369
+ if (state.state === "active") {
347
370
  storage = {
348
- type: 'active',
371
+ type: "active",
349
372
  code: state.code ? state.code : null,
350
373
  data: state.data ? state.data : null,
351
374
  };
352
375
  }
353
- else if (state.state === 'uninitialized') {
376
+ else if (state.state === "uninitialized") {
354
377
  storage = {
355
- type: 'uninit',
378
+ type: "uninit",
356
379
  };
357
380
  }
358
- else if (state.state === 'frozen') {
381
+ else if (state.state === "frozen") {
359
382
  storage = {
360
- type: 'frozen',
383
+ type: "frozen",
361
384
  stateHash: Buffer.alloc(0),
362
385
  };
363
386
  }
364
387
  else {
365
- throw Error('Unsupported state');
388
+ throw Error("Unsupported state");
366
389
  }
367
390
  if (state.extra_currencies && state.extra_currencies.length > 0) {
368
391
  ecMap = {};
@@ -378,8 +401,8 @@ function createProvider(client, address, init) {
378
401
  };
379
402
  },
380
403
  async get(name, args) {
381
- if (typeof name !== 'string') {
382
- throw new Error('Method name must be a string for TonClient provider');
404
+ if (typeof name !== "string") {
405
+ throw new Error("Method name must be a string for TonClient provider");
383
406
  }
384
407
  let method = await client.runMethod(address, name, args);
385
408
  return { stack: method.stack };
@@ -389,7 +412,7 @@ function createProvider(client, address, init) {
389
412
  // Resolve init
390
413
  //
391
414
  let neededInit = null;
392
- if (init && !await client.isContractDeployed(address)) {
415
+ if (init && !(await client.isContractDeployed(address))) {
393
416
  neededInit = init;
394
417
  }
395
418
  //
@@ -398,18 +421,15 @@ function createProvider(client, address, init) {
398
421
  const ext = (0, core_1.external)({
399
422
  to: address,
400
423
  init: neededInit,
401
- body: message
424
+ body: message,
402
425
  });
403
- let boc = (0, core_1.beginCell)()
404
- .store((0, core_1.storeMessage)(ext))
405
- .endCell()
406
- .toBoc();
426
+ let boc = (0, core_1.beginCell)().store((0, core_1.storeMessage)(ext)).endCell().toBoc();
407
427
  await client.sendFile(boc);
408
428
  },
409
429
  async internal(via, message) {
410
430
  // Resolve init
411
431
  let neededInit = null;
412
- if (init && (!await client.isContractDeployed(address))) {
432
+ if (init && !(await client.isContractDeployed(address))) {
413
433
  neededInit = init;
414
434
  }
415
435
  // Resolve bounce
@@ -419,7 +439,7 @@ function createProvider(client, address, init) {
419
439
  }
420
440
  // Resolve value
421
441
  let value;
422
- if (typeof message.value === 'string') {
442
+ if (typeof message.value === "string") {
423
443
  value = (0, core_1.toNano)(message.value);
424
444
  }
425
445
  else {
@@ -427,7 +447,7 @@ function createProvider(client, address, init) {
427
447
  }
428
448
  // Resolve body
429
449
  let body = null;
430
- if (typeof message.body === 'string') {
450
+ if (typeof message.body === "string") {
431
451
  body = (0, core_1.comment)(message.body);
432
452
  }
433
453
  else if (message.body) {
@@ -441,14 +461,19 @@ function createProvider(client, address, init) {
441
461
  sendMode: message.sendMode,
442
462
  extracurrency: message.extracurrency,
443
463
  init: neededInit,
444
- body
464
+ body,
445
465
  });
446
466
  },
447
467
  open(contract) {
448
468
  return (0, core_1.openContract)(contract, (args) => createProvider(client, args.address, args.init ?? null));
449
469
  },
450
470
  getTransactions(address, lt, hash, limit) {
451
- return client.getTransactions(address, { limit: limit ?? 100, lt: lt.toString(), hash: hash.toString('base64'), inclusive: true });
452
- }
471
+ return client.getTransactions(address, {
472
+ limit: limit ?? 100,
473
+ lt: lt.toString(),
474
+ hash: hash.toString("base64"),
475
+ inclusive: true,
476
+ });
477
+ },
453
478
  };
454
479
  }
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { AxiosAdapter, InternalAxiosRequestConfig } from "axios";
9
9
  import { Address, Contract, ContractProvider, OpenedContract, StateInit, Transaction, TupleItem, TupleReader } from "@ton/core";
10
- import { z } from 'zod';
10
+ import { z } from "zod";
11
11
  export type TonClient4Parameters = {
12
12
  /**
13
13
  * API endpoint