@ton/ton 13.5.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 (80) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/LICENSE +9 -0
  3. package/README.md +78 -0
  4. package/dist/client/TonClient.d.ts +231 -0
  5. package/dist/client/TonClient.js +392 -0
  6. package/dist/client/TonClient.spec.d.ts +1 -0
  7. package/dist/client/TonClient.spec.js +37 -0
  8. package/dist/client/TonClient4.d.ts +289 -0
  9. package/dist/client/TonClient4.js +514 -0
  10. package/dist/client/TonClient4.spec.d.ts +1 -0
  11. package/dist/client/TonClient4.spec.js +36 -0
  12. package/dist/client/api/HttpApi.d.ts +632 -0
  13. package/dist/client/api/HttpApi.js +297 -0
  14. package/dist/client/api/TonCache.d.ts +16 -0
  15. package/dist/client/api/TonCache.js +33 -0
  16. package/dist/index.d.ts +24 -0
  17. package/dist/index.js +68 -0
  18. package/dist/jetton/JettonMaster.d.ts +21 -0
  19. package/dist/jetton/JettonMaster.js +39 -0
  20. package/dist/jetton/JettonMaster.spec.d.ts +8 -0
  21. package/dist/jetton/JettonMaster.spec.js +27 -0
  22. package/dist/jetton/JettonWallet.d.ts +14 -0
  23. package/dist/jetton/JettonWallet.js +27 -0
  24. package/dist/multisig/MultisigOrder.d.ts +17 -0
  25. package/dist/multisig/MultisigOrder.js +73 -0
  26. package/dist/multisig/MultisigOrder.spec.d.ts +1 -0
  27. package/dist/multisig/MultisigOrder.spec.js +139 -0
  28. package/dist/multisig/MultisigOrderBuilder.d.ts +13 -0
  29. package/dist/multisig/MultisigOrderBuilder.js +37 -0
  30. package/dist/multisig/MultisigWallet.d.ts +26 -0
  31. package/dist/multisig/MultisigWallet.js +120 -0
  32. package/dist/multisig/MultisigWallet.spec.d.ts +1 -0
  33. package/dist/multisig/MultisigWallet.spec.js +230 -0
  34. package/dist/utils/createTestClient.d.ts +9 -0
  35. package/dist/utils/createTestClient.js +18 -0
  36. package/dist/utils/createTestClient4.d.ts +9 -0
  37. package/dist/utils/createTestClient4.js +15 -0
  38. package/dist/utils/maybe.d.ts +8 -0
  39. package/dist/utils/maybe.js +9 -0
  40. package/dist/utils/randomTestKey.d.ts +8 -0
  41. package/dist/utils/randomTestKey.js +24 -0
  42. package/dist/utils/time.d.ts +15 -0
  43. package/dist/utils/time.js +63 -0
  44. package/dist/utils/toUrlSafe.d.ts +8 -0
  45. package/dist/utils/toUrlSafe.js +23 -0
  46. package/dist/wallets/WalletContractV1R1.d.ts +58 -0
  47. package/dist/wallets/WalletContractV1R1.js +100 -0
  48. package/dist/wallets/WalletContractV1R1.spec.d.ts +8 -0
  49. package/dist/wallets/WalletContractV1R1.spec.js +44 -0
  50. package/dist/wallets/WalletContractV1R2.d.ts +58 -0
  51. package/dist/wallets/WalletContractV1R2.js +101 -0
  52. package/dist/wallets/WalletContractV1R2.spec.d.ts +8 -0
  53. package/dist/wallets/WalletContractV1R2.spec.js +44 -0
  54. package/dist/wallets/WalletContractV1R3.d.ts +58 -0
  55. package/dist/wallets/WalletContractV1R3.js +101 -0
  56. package/dist/wallets/WalletContractV1R3.spec.d.ts +8 -0
  57. package/dist/wallets/WalletContractV1R3.spec.js +44 -0
  58. package/dist/wallets/WalletContractV2R1.d.ts +60 -0
  59. package/dist/wallets/WalletContractV2R1.js +102 -0
  60. package/dist/wallets/WalletContractV2R1.spec.d.ts +8 -0
  61. package/dist/wallets/WalletContractV2R1.spec.js +44 -0
  62. package/dist/wallets/WalletContractV2R2.d.ts +60 -0
  63. package/dist/wallets/WalletContractV2R2.js +102 -0
  64. package/dist/wallets/WalletContractV2R2.spec.d.ts +8 -0
  65. package/dist/wallets/WalletContractV2R2.spec.js +44 -0
  66. package/dist/wallets/WalletContractV3R1.d.ts +62 -0
  67. package/dist/wallets/WalletContractV3R1.js +111 -0
  68. package/dist/wallets/WalletContractV3R1.spec.d.ts +8 -0
  69. package/dist/wallets/WalletContractV3R1.spec.js +44 -0
  70. package/dist/wallets/WalletContractV3R2.d.ts +62 -0
  71. package/dist/wallets/WalletContractV3R2.js +111 -0
  72. package/dist/wallets/WalletContractV3R2.spec.d.ts +8 -0
  73. package/dist/wallets/WalletContractV3R2.spec.js +44 -0
  74. package/dist/wallets/WalletContractV4.d.ts +62 -0
  75. package/dist/wallets/WalletContractV4.js +112 -0
  76. package/dist/wallets/WalletContractV4.spec.d.ts +8 -0
  77. package/dist/wallets/WalletContractV4.spec.js +48 -0
  78. package/dist/wallets/signing/createWalletTransfer.d.ts +39 -0
  79. package/dist/wallets/signing/createWalletTransfer.js +122 -0
  80. package/package.json +68 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,133 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [13.5.1] - 2023-07-14
8
+ ## Changed
9
+ - Migrated to `@ton/crypto` package instead of `ton-crypto`
10
+ - Migrated to `@ton/core` instead of `ton-core`
11
+ - Migrated to `@ton/emulator` instead of `ton-emulator`
12
+ - Renamed package to `@ton/ton`
13
+
14
+ ## [13.5.0] - 2023-05-10
15
+ ## Fixed
16
+ - Replaced `io-ts` with `zod` to reduce web bundle size
17
+ - Removed unimplemented method `getOneTransaction` from `TonClient4`
18
+
19
+ ## [13.4.1] - 2023-03-02
20
+
21
+ ## Added
22
+ - call get method aliases for TonClient (#7)
23
+ - add isContractDeployed to TonClient4 (#6)
24
+
25
+ ## Fixed
26
+ - Updated `ton-core` to depend from 0.48.0
27
+ - Fixed typos in `SendMode`
28
+
29
+ ## [13.4.0] - 2023-03-01
30
+
31
+ ## Added
32
+ - `MultisigWallet`, `MultisigOrder` and `MultisigOrderBuilder`
33
+
34
+ ## [13.3.0] - 2023-01-05
35
+
36
+ ## Added
37
+ - `getTransaction` to `TonClient4` to get a single transaction by id
38
+
39
+ ## [13.2.0] - 2022-12-31
40
+
41
+ ## Changed
42
+ - Updaded `ton-core` and renambed `AccountState` to `ContractState`
43
+ - Replaced internal usafe of a `openContract` with `ton-core` one
44
+
45
+ ## [13.1.0] - 2022-12-31
46
+
47
+ ## Changed
48
+ - Upgraded `ton-core` and removed legacy usage of `Message` type
49
+
50
+ ## [13.0.0] - 2022-12-29
51
+
52
+ ## Changed
53
+ - Large refactoring, removing a lot of obsolete features and replacing low level classes like `Cell` with `ton-core` implementation
54
+ - New way to work with contracts
55
+ - Explicit work with wallet contracts
56
+ - Unify stack operations in `TonClient` and `TonClient4`
57
+ - Merged `TupleSlice` and `TupleSlice4` into `TupleReader` from `ton-core`
58
+
59
+ ## Removed
60
+ - Removed magical `Wallet` operations
61
+
62
+ ## [12.3.3] - 2022-12-22
63
+ # Changed
64
+ - Improved BOC serialization
65
+
66
+ ## [12.3.2]
67
+ - Fix unicode symbols in `readString` function
68
+
69
+ ## [10.4.0]
70
+ - `TonClient4` - client for new API
71
+
72
+ ## [10.0.0]-[10.3.0]
73
+ - Exotic Cells parsing
74
+ - `readBitString`
75
+ - VM Stack parsing
76
+
77
+ ## [9.2.0]
78
+ - Builder and dict builder
79
+
80
+ ## [9.1.0]
81
+ - Support for API token
82
+
83
+ ## [9.0.0]
84
+ - Synchronous Cell's `hash` and a lot of related functions like `contractAddress`.
85
+
86
+ ## [6.10.0]
87
+ - Better compatibility with webpack
88
+
89
+ ## [6.8.0]
90
+ - Allow large comments
91
+
92
+ ## [6.7.0]
93
+ - Exported all parsing methods and `contractAddress`
94
+
95
+ ## [6.6.0]
96
+ - ADNL address
97
+
98
+ ## [6.5.2]
99
+ - Improve Internal/External messages typings
100
+
101
+ ## [6.5.0-6.5.1]
102
+ - Ability to include first transaction in getTransactions method
103
+
104
+ ## [6.4.0]
105
+ - Better webpack support
106
+
107
+ ## [6.3.0]
108
+
109
+ - Added dictionary serialization
110
+ - Added `equals` to Cell
111
+
112
+ ## [6.1.0-6.2.1]
113
+
114
+ - Added parsing of int (as addition to uint) in `BitStreamReader` and `Slice`
115
+
116
+ ## [6.0.0]
117
+
118
+ - [BREAKING] Change `RawMessage` to `CellMessage` and use `RawMessage` in parseTransaction
119
+ - Improve parseTransaction typings. Added:
120
+ - RawAccountStatus
121
+ - RawCurrencyCollection
122
+ - RawCommonMessageInfo
123
+ - RawStateInit
124
+ - RawMessage
125
+ - RawHashUpdate
126
+ - RawAccountStatusChange
127
+ - RawStorageUsedShort
128
+ - RawStoragePhase
129
+ - RawComputePhase
130
+ - RawActionPhase
131
+ - RawBouncePhase
132
+ - RawTransactionDescription
133
+ - RawTransaction
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021-2023 Whales Corp.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # TON JS Client
2
+
3
+ [![Version npm](https://img.shields.io/npm/v/ton.svg?logo=npm)](https://www.npmjs.com/package/ton)
4
+
5
+ Cross-platform client for TON blockchain.
6
+
7
+ ## Features
8
+
9
+ - 🚀 Create new wallets
10
+ - 🍰 Get balance
11
+ - ✈️ Transfers
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ yarn add @ton/ton @ton/crypto @ton/core buffer
17
+ ```
18
+
19
+ #### Browser polyfill
20
+
21
+ ```js
22
+ // Add before using library
23
+ require("buffer");
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ To use this library you need HTTP API endpoint, you can use one of the public endpoints:
29
+
30
+ - Mainnet: https://toncenter.com/api/v2/jsonRPC
31
+ - Testnet: https://testnet.toncenter.com/api/v2/jsonRPC
32
+
33
+ ```js
34
+ import { TonClient, WalletContractV4, internal } from "@ton/ton";
35
+ import { mnemonicNew, mnemonicToPrivateKey } from "@ton/crypto";
36
+
37
+ // Create Client
38
+ const client = new TonClient({
39
+ endpoint: 'https://toncenter.com/api/v2/jsonRPC',
40
+ });
41
+
42
+ // Generate new key
43
+ let mnemonics = await mnemonicNew();
44
+ let keyPair = await mnemonicToPrivateKey(mnemonics);
45
+
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);
50
+
51
+ // Get balance
52
+ let balance: bigint = await contract.getBalance();
53
+
54
+ // Create a transfer
55
+ let seqno: number = await contract.getSeqno();
56
+ let transfer = await contract.createTransfer({
57
+ seqno,
58
+ secretKey: keyPair.secretKey,
59
+ messages: [internal({
60
+ value: '1.5',
61
+ to: 'EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N',
62
+ body: 'Hello world',
63
+ })]
64
+ });
65
+
66
+ ```
67
+
68
+ ## Docs
69
+
70
+ [Documentation](https://ton-community.github.io/ton/)
71
+
72
+ ## Acknowledgements
73
+
74
+ This library is developed by the [Whales Corp.](https://tonwhales.com/) and maintained by [Dan Volkov](https://github.com/dvlkv).
75
+
76
+ ## License
77
+
78
+ MIT
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Copyright (c) Whales Corp.
3
+ * All Rights Reserved.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /// <reference types="node" />
9
+ import { AxiosAdapter } from 'axios';
10
+ import { Address, Cell, Contract, ContractProvider, Message, Transaction, TupleItem, TupleReader } from '@ton/core';
11
+ export declare type TonClientParameters = {
12
+ /**
13
+ * API Endpoint
14
+ */
15
+ endpoint: string;
16
+ /**
17
+ * HTTP request timeout in milliseconds.
18
+ */
19
+ timeout?: number;
20
+ /**
21
+ * API Key
22
+ */
23
+ apiKey?: string;
24
+ /**
25
+ * HTTP Adapter for axios
26
+ */
27
+ httpAdapter?: AxiosAdapter;
28
+ };
29
+ export declare class TonClient {
30
+ #private;
31
+ readonly parameters: TonClientParameters;
32
+ constructor(parameters: TonClientParameters);
33
+ /**
34
+ * Get Address Balance
35
+ * @param address address for balance check
36
+ * @returns balance
37
+ */
38
+ getBalance(address: Address): Promise<bigint>;
39
+ /**
40
+ * Invoke get method
41
+ * @param address contract address
42
+ * @param name name of method
43
+ * @param params optional parameters
44
+ * @returns stack and gas_used field
45
+ */
46
+ runMethod(address: Address, name: string, stack?: TupleItem[]): Promise<{
47
+ gas_used: number;
48
+ stack: TupleReader;
49
+ }>;
50
+ /**
51
+ * Invoke get method
52
+ * @param address contract address
53
+ * @param name name of method
54
+ * @param params optional parameters
55
+ * @returns stack and gas_used field
56
+ * @deprecated use runMethod instead
57
+ */
58
+ callGetMethod(address: Address, name: string, stack?: TupleItem[]): Promise<{
59
+ gas_used: number;
60
+ stack: TupleReader;
61
+ }>;
62
+ /**
63
+ * Invoke get method that returns error code instead of throwing error
64
+ * @param address contract address
65
+ * @param name name of method
66
+ * @param params optional parameters
67
+ * @returns stack and gas_used field
68
+ */
69
+ runMethodWithError(address: Address, name: string, params?: any[]): Promise<{
70
+ gas_used: number;
71
+ stack: TupleReader;
72
+ exit_code: number;
73
+ }>;
74
+ /**
75
+ * Invoke get method that returns error code instead of throwing error
76
+ * @param address contract address
77
+ * @param name name of method
78
+ * @param params optional parameters
79
+ * @returns stack and gas_used field
80
+ * @deprecated use runMethodWithError instead
81
+ */
82
+ callGetMethodWithError(address: Address, name: string, stack?: TupleItem[]): Promise<{
83
+ gas_used: number;
84
+ stack: TupleReader;
85
+ }>;
86
+ /**
87
+ * Get transactions
88
+ * @param address address
89
+ */
90
+ getTransactions(address: Address, opts: {
91
+ limit: number;
92
+ lt?: string;
93
+ hash?: string;
94
+ to_lt?: string;
95
+ inclusive?: boolean;
96
+ }): Promise<Transaction[]>;
97
+ /**
98
+ * Get transaction by it's id
99
+ * @param address address
100
+ * @param lt logical time
101
+ * @param hash transaction hash
102
+ * @returns transaction or null if not exist
103
+ */
104
+ getTransaction(address: Address, lt: string, hash: string): Promise<{
105
+ address: bigint;
106
+ lt: bigint;
107
+ prevTransactionHash: bigint;
108
+ prevTransactionLt: bigint;
109
+ now: number;
110
+ outMessagesCount: number;
111
+ oldStatus: import("@ton/core").AccountStatus; /**
112
+ * Get Address Balance
113
+ * @param address address for balance check
114
+ * @returns balance
115
+ */
116
+ endStatus: import("@ton/core").AccountStatus;
117
+ inMessage: Message | undefined;
118
+ outMessages: import("@ton/core").Dictionary<number, Message>;
119
+ totalFees: import("@ton/core").CurrencyCollection;
120
+ stateUpdate: import("@ton/core").HashUpdate;
121
+ description: import("@ton/core").TransactionDescription;
122
+ } | null>;
123
+ /**
124
+ * Fetch latest masterchain info
125
+ * @returns masterchain info
126
+ */
127
+ getMasterchainInfo(): Promise<{
128
+ workchain: number;
129
+ shard: string;
130
+ initSeqno: number;
131
+ latestSeqno: number;
132
+ }>;
133
+ /**
134
+ * Fetch latest workchain shards
135
+ * @param seqno masterchain seqno
136
+ */
137
+ getWorkchainShards(seqno: number): Promise<{
138
+ workchain: number;
139
+ shard: string;
140
+ seqno: number;
141
+ }[]>;
142
+ /**
143
+ * Fetch transactions inf shards
144
+ * @param workchain
145
+ * @param seqno
146
+ * @param shard
147
+ */
148
+ getShardTransactions(workchain: number, seqno: number, shard: string): Promise<{
149
+ account: Address;
150
+ lt: string;
151
+ hash: string;
152
+ }[]>;
153
+ /**
154
+ * Send message to a network
155
+ * @param src source message
156
+ */
157
+ sendMessage(src: Message): Promise<void>;
158
+ /**
159
+ * Send file to a network
160
+ * @param src source file
161
+ */
162
+ sendFile(src: Buffer): Promise<void>;
163
+ /**
164
+ * Estimate fees for external message
165
+ * @param address target address
166
+ * @returns
167
+ */
168
+ estimateExternalMessageFee(address: Address, args: {
169
+ body: Cell;
170
+ initCode: Cell | null;
171
+ initData: Cell | null;
172
+ ignoreSignature: boolean;
173
+ }): Promise<{
174
+ '@type': "query.fees";
175
+ source_fees: {
176
+ '@type': "fees";
177
+ in_fwd_fee: number;
178
+ storage_fee: number;
179
+ gas_fee: number;
180
+ fwd_fee: number;
181
+ };
182
+ }>;
183
+ /**
184
+ * Send external message to contract
185
+ * @param contract contract to send message
186
+ * @param src message body
187
+ */
188
+ sendExternalMessage(contract: Contract, src: Cell): Promise<void>;
189
+ /**
190
+ * Check if contract is deployed
191
+ * @param address addres to check
192
+ * @returns true if contract is in active state
193
+ */
194
+ isContractDeployed(address: Address): Promise<boolean>;
195
+ /**
196
+ * Resolves contract state
197
+ * @param address contract address
198
+ */
199
+ getContractState(address: Address): Promise<{
200
+ balance: bigint;
201
+ state: "active" | "uninitialized" | "frozen";
202
+ code: Buffer | null;
203
+ data: Buffer | null;
204
+ lastTransaction: {
205
+ lt: string;
206
+ hash: string;
207
+ } | null;
208
+ blockId: {
209
+ workchain: number;
210
+ shard: string;
211
+ seqno: number;
212
+ };
213
+ timestampt: number;
214
+ }>;
215
+ /**
216
+ * Open contract
217
+ * @param src source contract
218
+ * @returns contract
219
+ */
220
+ open<T extends Contract>(src: T): import("@ton/core").OpenedContract<T>;
221
+ /**
222
+ * Create a provider
223
+ * @param address address
224
+ * @param init optional init
225
+ * @returns provider
226
+ */
227
+ provider(address: Address, init: {
228
+ code: Cell | null;
229
+ data: Cell | null;
230
+ } | null): ContractProvider;
231
+ }