tronwb 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (318) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +201 -0
  3. package/dist/TronWeb.js +3 -0
  4. package/dist/TronWeb.js.LICENSE.txt +12 -0
  5. package/dist/TronWeb.js.map +1 -0
  6. package/dist/TronWeb.node.js +2 -0
  7. package/dist/TronWeb.node.js.map +1 -0
  8. package/kj9btptx.cjs +1 -0
  9. package/lib/commonjs/index.d.ts +64 -0
  10. package/lib/commonjs/index.js +37 -0
  11. package/lib/commonjs/index.js.map +1 -0
  12. package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.d.ts +127 -0
  13. package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.js +1771 -0
  14. package/lib/commonjs/lib/TransactionBuilder/TransactionBuilder.js.map +1 -0
  15. package/lib/commonjs/lib/TransactionBuilder/helper.d.ts +28 -0
  16. package/lib/commonjs/lib/TransactionBuilder/helper.js +122 -0
  17. package/lib/commonjs/lib/TransactionBuilder/helper.js.map +1 -0
  18. package/lib/commonjs/lib/contract/index.d.ts +29 -0
  19. package/lib/commonjs/lib/contract/index.js +124 -0
  20. package/lib/commonjs/lib/contract/index.js.map +1 -0
  21. package/lib/commonjs/lib/contract/method.d.ts +50 -0
  22. package/lib/commonjs/lib/contract/method.js +238 -0
  23. package/lib/commonjs/lib/contract/method.js.map +1 -0
  24. package/lib/commonjs/lib/event.d.ts +85 -0
  25. package/lib/commonjs/lib/event.js +137 -0
  26. package/lib/commonjs/lib/event.js.map +1 -0
  27. package/lib/commonjs/lib/plugin.d.ts +28 -0
  28. package/lib/commonjs/lib/plugin.js +84 -0
  29. package/lib/commonjs/lib/plugin.js.map +1 -0
  30. package/lib/commonjs/lib/providers/HttpProvider.d.ts +15 -0
  31. package/lib/commonjs/lib/providers/HttpProvider.js +63 -0
  32. package/lib/commonjs/lib/providers/HttpProvider.js.map +1 -0
  33. package/lib/commonjs/lib/providers/index.d.ts +6 -0
  34. package/lib/commonjs/lib/providers/index.js +8 -0
  35. package/lib/commonjs/lib/providers/index.js.map +1 -0
  36. package/lib/commonjs/lib/trx.d.ts +315 -0
  37. package/lib/commonjs/lib/trx.js +965 -0
  38. package/lib/commonjs/lib/trx.js.map +1 -0
  39. package/lib/commonjs/package.json +1 -0
  40. package/lib/commonjs/paramValidator/index.d.ts +19 -0
  41. package/lib/commonjs/paramValidator/index.js +110 -0
  42. package/lib/commonjs/paramValidator/index.js.map +1 -0
  43. package/lib/commonjs/protocol/core/Tron_pb.cjs +7524 -0
  44. package/lib/commonjs/protocol/core/contract/account_contract_pb.cjs +961 -0
  45. package/lib/commonjs/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
  46. package/lib/commonjs/protocol/core/contract/balance_contract_pb.cjs +3826 -0
  47. package/lib/commonjs/protocol/core/contract/common_pb.cjs +34 -0
  48. package/lib/commonjs/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
  49. package/lib/commonjs/protocol/core/contract/proposal_contract_pb.cjs +675 -0
  50. package/lib/commonjs/protocol/core/contract/smart_contract_pb.cjs +2960 -0
  51. package/lib/commonjs/protocol/core/contract/storage_contract_pb.cjs +848 -0
  52. package/lib/commonjs/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
  53. package/lib/commonjs/protocol/core/contract/witness_contract_pb.cjs +956 -0
  54. package/lib/commonjs/tronweb.d.ts +111 -0
  55. package/lib/commonjs/tronweb.js +365 -0
  56. package/lib/commonjs/tronweb.js.map +1 -0
  57. package/lib/commonjs/types/ABI.d.ts +59 -0
  58. package/lib/commonjs/types/ABI.js +3 -0
  59. package/lib/commonjs/types/ABI.js.map +1 -0
  60. package/lib/commonjs/types/APIResponse.d.ts +31 -0
  61. package/lib/commonjs/types/APIResponse.js +3 -0
  62. package/lib/commonjs/types/APIResponse.js.map +1 -0
  63. package/lib/commonjs/types/Contract.d.ts +287 -0
  64. package/lib/commonjs/types/Contract.js +63 -0
  65. package/lib/commonjs/types/Contract.js.map +1 -0
  66. package/lib/commonjs/types/Providers.d.ts +8 -0
  67. package/lib/commonjs/types/Providers.js +3 -0
  68. package/lib/commonjs/types/Providers.js.map +1 -0
  69. package/lib/commonjs/types/Transaction.d.ts +65 -0
  70. package/lib/commonjs/types/Transaction.js +3 -0
  71. package/lib/commonjs/types/Transaction.js.map +1 -0
  72. package/lib/commonjs/types/TransactionBuilder.d.ts +270 -0
  73. package/lib/commonjs/types/TransactionBuilder.js +3 -0
  74. package/lib/commonjs/types/TransactionBuilder.js.map +1 -0
  75. package/lib/commonjs/types/TronWeb.d.ts +20 -0
  76. package/lib/commonjs/types/TronWeb.js +3 -0
  77. package/lib/commonjs/types/TronWeb.js.map +1 -0
  78. package/lib/commonjs/types/Trx.d.ts +263 -0
  79. package/lib/commonjs/types/Trx.js +42 -0
  80. package/lib/commonjs/types/Trx.js.map +1 -0
  81. package/lib/commonjs/types/UtilsTypes.d.ts +23 -0
  82. package/lib/commonjs/types/UtilsTypes.js +3 -0
  83. package/lib/commonjs/types/UtilsTypes.js.map +1 -0
  84. package/lib/commonjs/types/index.d.ts +9 -0
  85. package/lib/commonjs/types/index.js +13 -0
  86. package/lib/commonjs/types/index.js.map +1 -0
  87. package/lib/commonjs/utils/abi.d.ts +5 -0
  88. package/lib/commonjs/utils/abi.js +251 -0
  89. package/lib/commonjs/utils/abi.js.map +1 -0
  90. package/lib/commonjs/utils/accounts.d.ts +22 -0
  91. package/lib/commonjs/utils/accounts.js +51 -0
  92. package/lib/commonjs/utils/accounts.js.map +1 -0
  93. package/lib/commonjs/utils/address.d.ts +12 -0
  94. package/lib/commonjs/utils/address.js +91 -0
  95. package/lib/commonjs/utils/address.js.map +1 -0
  96. package/lib/commonjs/utils/base58.d.ts +3 -0
  97. package/lib/commonjs/utils/base58.js +68 -0
  98. package/lib/commonjs/utils/base58.js.map +1 -0
  99. package/lib/commonjs/utils/base64.d.ts +10 -0
  100. package/lib/commonjs/utils/base64.js +173 -0
  101. package/lib/commonjs/utils/base64.js.map +1 -0
  102. package/lib/commonjs/utils/bytes.d.ts +7 -0
  103. package/lib/commonjs/utils/bytes.js +61 -0
  104. package/lib/commonjs/utils/bytes.js.map +1 -0
  105. package/lib/commonjs/utils/code.d.ts +12 -0
  106. package/lib/commonjs/utils/code.js +166 -0
  107. package/lib/commonjs/utils/code.js.map +1 -0
  108. package/lib/commonjs/utils/crypto.d.ts +25 -0
  109. package/lib/commonjs/utils/crypto.js +222 -0
  110. package/lib/commonjs/utils/crypto.js.map +1 -0
  111. package/lib/commonjs/utils/ethersUtils.d.ts +14 -0
  112. package/lib/commonjs/utils/ethersUtils.js +39 -0
  113. package/lib/commonjs/utils/ethersUtils.js.map +1 -0
  114. package/lib/commonjs/utils/fragments.d.ts +465 -0
  115. package/lib/commonjs/utils/fragments.js +1342 -0
  116. package/lib/commonjs/utils/fragments.js.map +1 -0
  117. package/lib/commonjs/utils/help.d.ts +8 -0
  118. package/lib/commonjs/utils/help.js +61 -0
  119. package/lib/commonjs/utils/help.js.map +1 -0
  120. package/lib/commonjs/utils/index.d.ts +56 -0
  121. package/lib/commonjs/utils/index.js +43 -0
  122. package/lib/commonjs/utils/index.js.map +1 -0
  123. package/lib/commonjs/utils/interface.d.ts +381 -0
  124. package/lib/commonjs/utils/interface.js +1121 -0
  125. package/lib/commonjs/utils/interface.js.map +1 -0
  126. package/lib/commonjs/utils/message.d.ts +4 -0
  127. package/lib/commonjs/utils/message.js +38 -0
  128. package/lib/commonjs/utils/message.js.map +1 -0
  129. package/lib/commonjs/utils/transaction.d.ts +17 -0
  130. package/lib/commonjs/utils/transaction.js +678 -0
  131. package/lib/commonjs/utils/transaction.js.map +1 -0
  132. package/lib/commonjs/utils/typedData.d.ts +148 -0
  133. package/lib/commonjs/utils/typedData.js +498 -0
  134. package/lib/commonjs/utils/typedData.js.map +1 -0
  135. package/lib/commonjs/utils/validations.d.ts +22 -0
  136. package/lib/commonjs/utils/validations.js +128 -0
  137. package/lib/commonjs/utils/validations.js.map +1 -0
  138. package/lib/esm/index.d.ts +64 -0
  139. package/lib/esm/index.js +33 -0
  140. package/lib/esm/index.js.map +1 -0
  141. package/lib/esm/lib/TransactionBuilder/TransactionBuilder.d.ts +127 -0
  142. package/lib/esm/lib/TransactionBuilder/TransactionBuilder.js +1767 -0
  143. package/lib/esm/lib/TransactionBuilder/TransactionBuilder.js.map +1 -0
  144. package/lib/esm/lib/TransactionBuilder/helper.d.ts +28 -0
  145. package/lib/esm/lib/TransactionBuilder/helper.js +112 -0
  146. package/lib/esm/lib/TransactionBuilder/helper.js.map +1 -0
  147. package/lib/esm/lib/contract/index.d.ts +29 -0
  148. package/lib/esm/lib/contract/index.js +118 -0
  149. package/lib/esm/lib/contract/index.js.map +1 -0
  150. package/lib/esm/lib/contract/method.d.ts +50 -0
  151. package/lib/esm/lib/contract/method.js +233 -0
  152. package/lib/esm/lib/contract/method.js.map +1 -0
  153. package/lib/esm/lib/event.d.ts +85 -0
  154. package/lib/esm/lib/event.js +132 -0
  155. package/lib/esm/lib/event.js.map +1 -0
  156. package/lib/esm/lib/plugin.d.ts +28 -0
  157. package/lib/esm/lib/plugin.js +79 -0
  158. package/lib/esm/lib/plugin.js.map +1 -0
  159. package/lib/esm/lib/providers/HttpProvider.d.ts +15 -0
  160. package/lib/esm/lib/providers/HttpProvider.js +59 -0
  161. package/lib/esm/lib/providers/HttpProvider.js.map +1 -0
  162. package/lib/esm/lib/providers/index.d.ts +6 -0
  163. package/lib/esm/lib/providers/index.js +4 -0
  164. package/lib/esm/lib/providers/index.js.map +1 -0
  165. package/lib/esm/lib/trx.d.ts +315 -0
  166. package/lib/esm/lib/trx.js +960 -0
  167. package/lib/esm/lib/trx.js.map +1 -0
  168. package/lib/esm/package.json +1 -0
  169. package/lib/esm/paramValidator/index.d.ts +19 -0
  170. package/lib/esm/paramValidator/index.js +106 -0
  171. package/lib/esm/paramValidator/index.js.map +1 -0
  172. package/lib/esm/protocol/core/Tron_pb.cjs +7524 -0
  173. package/lib/esm/protocol/core/contract/account_contract_pb.cjs +961 -0
  174. package/lib/esm/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
  175. package/lib/esm/protocol/core/contract/balance_contract_pb.cjs +3826 -0
  176. package/lib/esm/protocol/core/contract/common_pb.cjs +34 -0
  177. package/lib/esm/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
  178. package/lib/esm/protocol/core/contract/proposal_contract_pb.cjs +675 -0
  179. package/lib/esm/protocol/core/contract/smart_contract_pb.cjs +2960 -0
  180. package/lib/esm/protocol/core/contract/storage_contract_pb.cjs +848 -0
  181. package/lib/esm/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
  182. package/lib/esm/protocol/core/contract/witness_contract_pb.cjs +956 -0
  183. package/lib/esm/tronweb.d.ts +111 -0
  184. package/lib/esm/tronweb.js +360 -0
  185. package/lib/esm/tronweb.js.map +1 -0
  186. package/lib/esm/types/ABI.d.ts +59 -0
  187. package/lib/esm/types/ABI.js +2 -0
  188. package/lib/esm/types/ABI.js.map +1 -0
  189. package/lib/esm/types/APIResponse.d.ts +31 -0
  190. package/lib/esm/types/APIResponse.js +2 -0
  191. package/lib/esm/types/APIResponse.js.map +1 -0
  192. package/lib/esm/types/Contract.d.ts +287 -0
  193. package/lib/esm/types/Contract.js +60 -0
  194. package/lib/esm/types/Contract.js.map +1 -0
  195. package/lib/esm/types/Providers.d.ts +8 -0
  196. package/lib/esm/types/Providers.js +2 -0
  197. package/lib/esm/types/Providers.js.map +1 -0
  198. package/lib/esm/types/Transaction.d.ts +65 -0
  199. package/lib/esm/types/Transaction.js +2 -0
  200. package/lib/esm/types/Transaction.js.map +1 -0
  201. package/lib/esm/types/TransactionBuilder.d.ts +270 -0
  202. package/lib/esm/types/TransactionBuilder.js +2 -0
  203. package/lib/esm/types/TransactionBuilder.js.map +1 -0
  204. package/lib/esm/types/TronWeb.d.ts +20 -0
  205. package/lib/esm/types/TronWeb.js +2 -0
  206. package/lib/esm/types/TronWeb.js.map +1 -0
  207. package/lib/esm/types/Trx.d.ts +263 -0
  208. package/lib/esm/types/Trx.js +39 -0
  209. package/lib/esm/types/Trx.js.map +1 -0
  210. package/lib/esm/types/UtilsTypes.d.ts +23 -0
  211. package/lib/esm/types/UtilsTypes.js +2 -0
  212. package/lib/esm/types/UtilsTypes.js.map +1 -0
  213. package/lib/esm/types/index.d.ts +9 -0
  214. package/lib/esm/types/index.js +10 -0
  215. package/lib/esm/types/index.js.map +1 -0
  216. package/lib/esm/utils/abi.d.ts +5 -0
  217. package/lib/esm/utils/abi.js +245 -0
  218. package/lib/esm/utils/abi.js.map +1 -0
  219. package/lib/esm/utils/accounts.d.ts +22 -0
  220. package/lib/esm/utils/accounts.js +46 -0
  221. package/lib/esm/utils/accounts.js.map +1 -0
  222. package/lib/esm/utils/address.d.ts +12 -0
  223. package/lib/esm/utils/address.js +82 -0
  224. package/lib/esm/utils/address.js.map +1 -0
  225. package/lib/esm/utils/base58.d.ts +3 -0
  226. package/lib/esm/utils/base58.js +64 -0
  227. package/lib/esm/utils/base58.js.map +1 -0
  228. package/lib/esm/utils/base64.d.ts +10 -0
  229. package/lib/esm/utils/base64.js +169 -0
  230. package/lib/esm/utils/base64.js.map +1 -0
  231. package/lib/esm/utils/bytes.d.ts +7 -0
  232. package/lib/esm/utils/bytes.js +53 -0
  233. package/lib/esm/utils/bytes.js.map +1 -0
  234. package/lib/esm/utils/code.d.ts +12 -0
  235. package/lib/esm/utils/code.js +149 -0
  236. package/lib/esm/utils/code.js.map +1 -0
  237. package/lib/esm/utils/crypto.d.ts +25 -0
  238. package/lib/esm/utils/crypto.js +198 -0
  239. package/lib/esm/utils/crypto.js.map +1 -0
  240. package/lib/esm/utils/ethersUtils.d.ts +14 -0
  241. package/lib/esm/utils/ethersUtils.js +17 -0
  242. package/lib/esm/utils/ethersUtils.js.map +1 -0
  243. package/lib/esm/utils/fragments.d.ts +465 -0
  244. package/lib/esm/utils/fragments.js +1330 -0
  245. package/lib/esm/utils/fragments.js.map +1 -0
  246. package/lib/esm/utils/help.d.ts +8 -0
  247. package/lib/esm/utils/help.js +51 -0
  248. package/lib/esm/utils/help.js.map +1 -0
  249. package/lib/esm/utils/index.d.ts +56 -0
  250. package/lib/esm/utils/index.js +40 -0
  251. package/lib/esm/utils/index.js.map +1 -0
  252. package/lib/esm/utils/interface.d.ts +381 -0
  253. package/lib/esm/utils/interface.js +1112 -0
  254. package/lib/esm/utils/interface.js.map +1 -0
  255. package/lib/esm/utils/message.d.ts +4 -0
  256. package/lib/esm/utils/message.js +32 -0
  257. package/lib/esm/utils/message.js.map +1 -0
  258. package/lib/esm/utils/transaction.d.ts +17 -0
  259. package/lib/esm/utils/transaction.js +669 -0
  260. package/lib/esm/utils/transaction.js.map +1 -0
  261. package/lib/esm/utils/typedData.d.ts +148 -0
  262. package/lib/esm/utils/typedData.js +493 -0
  263. package/lib/esm/utils/typedData.js.map +1 -0
  264. package/lib/esm/utils/validations.d.ts +22 -0
  265. package/lib/esm/utils/validations.js +108 -0
  266. package/lib/esm/utils/validations.js.map +1 -0
  267. package/package.json +110 -0
  268. package/src/index.ts +42 -0
  269. package/src/lib/TransactionBuilder/TransactionBuilder.ts +2272 -0
  270. package/src/lib/TransactionBuilder/helper.ts +139 -0
  271. package/src/lib/contract/index.ts +151 -0
  272. package/src/lib/contract/method.ts +336 -0
  273. package/src/lib/event.ts +248 -0
  274. package/src/lib/plugin.ts +102 -0
  275. package/src/lib/providers/HttpProvider.ts +66 -0
  276. package/src/lib/providers/index.ts +6 -0
  277. package/src/lib/trx.ts +1463 -0
  278. package/src/paramValidator/index.ts +136 -0
  279. package/src/protocol/core/Tron_pb.cjs +7524 -0
  280. package/src/protocol/core/contract/account_contract_pb.cjs +961 -0
  281. package/src/protocol/core/contract/asset_issue_contract_pb.cjs +2196 -0
  282. package/src/protocol/core/contract/balance_contract_pb.cjs +3826 -0
  283. package/src/protocol/core/contract/common_pb.cjs +34 -0
  284. package/src/protocol/core/contract/exchange_contract_pb.cjs +1268 -0
  285. package/src/protocol/core/contract/proposal_contract_pb.cjs +675 -0
  286. package/src/protocol/core/contract/smart_contract_pb.cjs +2960 -0
  287. package/src/protocol/core/contract/storage_contract_pb.cjs +848 -0
  288. package/src/protocol/core/contract/vote_asset_contract_pb.cjs +340 -0
  289. package/src/protocol/core/contract/witness_contract_pb.cjs +956 -0
  290. package/src/tronweb.ts +437 -0
  291. package/src/types/ABI.ts +82 -0
  292. package/src/types/APIResponse.ts +34 -0
  293. package/src/types/Contract.ts +352 -0
  294. package/src/types/Providers.ts +7 -0
  295. package/src/types/Transaction.ts +70 -0
  296. package/src/types/TransactionBuilder.ts +281 -0
  297. package/src/types/TronWeb.ts +23 -0
  298. package/src/types/Trx.ts +285 -0
  299. package/src/types/UtilsTypes.ts +25 -0
  300. package/src/types/index.ts +9 -0
  301. package/src/types/interface.d.ts +1 -0
  302. package/src/utils/abi.ts +257 -0
  303. package/src/utils/accounts.ts +60 -0
  304. package/src/utils/address.ts +89 -0
  305. package/src/utils/base58.ts +78 -0
  306. package/src/utils/base64.ts +200 -0
  307. package/src/utils/bytes.ts +68 -0
  308. package/src/utils/code.ts +172 -0
  309. package/src/utils/crypto.ts +264 -0
  310. package/src/utils/ethersUtils.ts +60 -0
  311. package/src/utils/fragments.ts +1738 -0
  312. package/src/utils/help.ts +59 -0
  313. package/src/utils/index.ts +42 -0
  314. package/src/utils/interface.ts +1362 -0
  315. package/src/utils/message.ts +38 -0
  316. package/src/utils/transaction.ts +991 -0
  317. package/src/utils/typedData.ts +688 -0
  318. package/src/utils/validations.ts +130 -0
@@ -0,0 +1,23 @@
1
+ import { AxiosRequestHeaders } from 'axios';
2
+ import { BigNumber } from 'bignumber.js';
3
+ import type { HeadersType } from './Providers.js';
4
+ import HttpProvider from '../lib/providers/HttpProvider.js';
5
+
6
+ export type IBigNumber = InstanceType<typeof BigNumber>;
7
+
8
+ export interface TronWebOptions {
9
+ fullNode?: NodeProvider;
10
+ solidityNode?: NodeProvider;
11
+ fullHost?: NodeProvider;
12
+ eventServer?: NodeProvider;
13
+ headers?: HeadersType;
14
+ eventHeaders?: AxiosRequestHeaders;
15
+ privateKey?: string;
16
+ disablePlugins?: boolean;
17
+ }
18
+ export interface DefaultAddress {
19
+ hex: string | false;
20
+ base58: string | false;
21
+ }
22
+
23
+ export type NodeProvider = string | HttpProvider;
@@ -0,0 +1,285 @@
1
+ import { AccountType, Permission } from './Contract.js';
2
+ import { SignedTransaction, Transaction } from './Transaction.js';
3
+ import { Resource } from './TransactionBuilder.js';
4
+
5
+ type HTTPMap<T extends string | number | symbol, U> = Record<T, U>[];
6
+
7
+ export interface FrozenSupply {
8
+ frozen_amount: number;
9
+ frozen_days: number;
10
+ }
11
+
12
+ export interface Token {
13
+ id: string;
14
+ owner_address: string;
15
+ name: string;
16
+ abbr: string;
17
+ total_supply: number;
18
+ frozen_supply: FrozenSupply[];
19
+ trx_num: number;
20
+ precision: number;
21
+ num: number;
22
+ start_time: number;
23
+ end_time: number;
24
+ order: number; // useless
25
+ vote_score: number;
26
+ description: string;
27
+ url: string;
28
+ free_asset_net_limit: number;
29
+ public_free_asset_net_limit: number;
30
+ public_free_asset_net_usage: number;
31
+ public_latest_free_net_time: number;
32
+ }
33
+
34
+ export interface Frozen {
35
+ frozen_balance: number;
36
+ expire_time: number;
37
+ }
38
+
39
+ export interface Vote {
40
+ vote_address: string;
41
+ vote_count: number;
42
+ }
43
+
44
+ export interface AccountResource {
45
+ energy_usage: number;
46
+ frozen_balance_for_energy: Frozen;
47
+ latest_consume_time_for_energy: number;
48
+ acquired_delegated_frozen_balance_for_energy: number;
49
+ delegated_frozen_balance_for_energy: number;
50
+ storage_limit: number;
51
+ storage_usage: number;
52
+ latest_exchange_storage_time: number;
53
+ energy_window_size: number;
54
+ delegated_frozenV2_balance_for_energy: number;
55
+ acquired_delegated_frozenV2_balance_for_energy: number;
56
+ energy_window_optimized: boolean;
57
+ }
58
+
59
+ export enum ResourceCode {
60
+ BANDWIDTH = 0x00,
61
+ ENERGY = 0x01,
62
+ TRON_POWER = 0x02,
63
+ }
64
+
65
+ export interface FreezeV2 {
66
+ type: Resource;
67
+ amount: number;
68
+ }
69
+ export interface UnFreezeV2 {
70
+ type: Resource;
71
+ unfreeze_amount: number;
72
+ unfreeze_expire_time: number;
73
+ }
74
+
75
+ export interface Account {
76
+ account_name: string;
77
+ type: AccountType;
78
+ address: string;
79
+ balance: number;
80
+ votes: Vote[];
81
+ asset: HTTPMap<string, number>;
82
+ assetV2: HTTPMap<string, number>;
83
+ frozen: Frozen[];
84
+ net_usage: number;
85
+ acquired_delegated_frozen_balance_for_bandwidth: number;
86
+ delegated_frozen_balance_for_bandwidth: number;
87
+ old_tron_power: number;
88
+ tron_power: Frozen;
89
+ asset_optimized: boolean;
90
+ create_time: number;
91
+ latest_opration_time: number;
92
+ allowance: number;
93
+ latest_withdraw_time: number;
94
+ code: string;
95
+ is_witness: boolean;
96
+ is_committee: boolean;
97
+ frozen_supply: Frozen;
98
+ asset_issued_name: string;
99
+ asset_issued_ID: string;
100
+ latest_asset_operation_time: HTTPMap<string, number>;
101
+ latest_asset_operation_timeV2: HTTPMap<string, number>;
102
+ free_net_usage: number;
103
+ free_asset_net_usage: HTTPMap<string, number>;
104
+ free_asset_net_usageV2: HTTPMap<string, number>;
105
+ latest_consume_time: number;
106
+ latest_consume_free_time: number;
107
+ account_id: string;
108
+ net_window_size: number;
109
+ net_window_optimized: number;
110
+ account_resource: AccountResource;
111
+ codeHash: string;
112
+ owner_permission: Permission;
113
+ witness_permission: Permission;
114
+ active_permission: Permission[];
115
+ frozenV2: FreezeV2[];
116
+ unfrozenV2: UnFreezeV2[];
117
+ delegated_frozenV2_balance_for_bandwidth: number;
118
+ acquired_delegated_frozenV2_balance_for_bandwidth: number;
119
+ }
120
+
121
+ export interface AccountNetMessage {
122
+ freeNetUsed: number;
123
+ freeNetLimit: number;
124
+ NetUsed: number;
125
+ NetLimit: number;
126
+ assetNetUsed: HTTPMap<string, number>;
127
+ assetNetLimit: HTTPMap<string, number>;
128
+ TotalNetLimit: number;
129
+ TotalNetWeight: number;
130
+ }
131
+
132
+ export interface Witness {
133
+ address: string;
134
+ voteCount: number;
135
+ pubKey: string;
136
+ url: string;
137
+ totalProduced: number;
138
+ totalMissed: number;
139
+ latestBlockNum: number;
140
+ latestSlotNum: number;
141
+ isJobs: boolean;
142
+ }
143
+
144
+ enum TransactionSignWeight_response_code {
145
+ ENOUGH_PERMISSION = 'ENOUGH_PERMISSION',
146
+ NOT_ENOUGH_PERMISSION = 'NOT_ENOUGH_PERMISSION', // error in
147
+ SIGNATURE_FORMAT_ERROR = 'SIGNATURE_FORMAT_ERROR',
148
+ COMPUTE_ADDRESS_ERROR = 'COMPUTE_ADDRESS_ERROR',
149
+ PERMISSION_ERROR = 'PERMISSION_ERROR', //The key is not in permission
150
+ OTHER_ERROR = 'OTHER_ERROR',
151
+ }
152
+
153
+ interface TransactionSignWeightResult {
154
+ code: TransactionSignWeight_response_code;
155
+ message: string;
156
+ }
157
+
158
+ export interface TransactionSignWeight {
159
+ permission: Permission;
160
+ approved_list: string[];
161
+ current_weight: number;
162
+ result: TransactionSignWeightResult;
163
+ transaction: { transaction: Transaction };
164
+ }
165
+
166
+ enum BroadcastReturn_response_code {
167
+ SUCCESS = 0,
168
+ SIGERROR = 1, // error in signature
169
+ CONTRACT_VALIDATE_ERROR = 2,
170
+ CONTRACT_EXE_ERROR = 3,
171
+ BANDWITH_ERROR = 4,
172
+ DUP_TRANSACTION_ERROR = 5,
173
+ TAPOS_ERROR = 6,
174
+ TOO_BIG_TRANSACTION_ERROR = 7,
175
+ TRANSACTION_EXPIRATION_ERROR = 8,
176
+ SERVER_BUSY = 9,
177
+ NO_CONNECTION = 10,
178
+ NOT_ENOUGH_EFFECTIVE_CONNECTION = 11,
179
+ OTHER_ERROR = 20,
180
+ }
181
+
182
+ export interface BroadcastReturn<T extends SignedTransaction> {
183
+ result: boolean;
184
+ code: BroadcastReturn_response_code;
185
+ message: string;
186
+ transaction: T;
187
+ }
188
+
189
+ export interface BroadcastHexReturn {
190
+ result: boolean;
191
+ txid: string;
192
+ code: string;
193
+ message: string;
194
+ transaction: string;
195
+ }
196
+
197
+ export interface AddressOptions {
198
+ privateKey?: string;
199
+ address?: string;
200
+ }
201
+
202
+ enum ProposalState {
203
+ PENDING = 0,
204
+ DISAPPROVED = 1,
205
+ APPROVED = 2,
206
+ CANCELED = 3,
207
+ }
208
+
209
+ export interface Proposal {
210
+ proposal_id: number;
211
+ proposer_address: string;
212
+ parameters: HTTPMap<number, number>;
213
+ expiration_time: number;
214
+ create_time: number;
215
+ approvals: string[];
216
+ state: ProposalState;
217
+ }
218
+
219
+ export interface ChainParameter {
220
+ key: string;
221
+ value: number;
222
+ }
223
+
224
+ export interface AccountResourceMessage {
225
+ freeNetUsed: number;
226
+ freeNetLimit: number;
227
+ NetUsed: number;
228
+ NetLimit: number;
229
+ assetNetUsed: HTTPMap<string, number>;
230
+ assetNetLimit: HTTPMap<string, number>;
231
+ TotalNetLimit: number;
232
+ TotalNetWeight: number;
233
+ TotalTronPowerWeight: number;
234
+ tronPowerUsed: number;
235
+ tronPowerLimit: number;
236
+ EnergyUsed: number;
237
+ EnergyLimit: number;
238
+ TotalEnergyLimit: number;
239
+ TotalEnergyWeight: number;
240
+ storageUsed: number;
241
+ storageLimit: number;
242
+ }
243
+
244
+ export type Address = string;
245
+
246
+ export interface Exchange {
247
+ exchange_id: number;
248
+ creator_address: Address;
249
+ create_time: number;
250
+ first_token_id: string;
251
+ first_token_balance: number;
252
+ second_token_id: string;
253
+ second_token_balance: number;
254
+ }
255
+
256
+ export interface TransactionInfo {
257
+ id: string;
258
+ fee: number;
259
+ blockNumber: number;
260
+ blockTimeStamp: number;
261
+ contractResult: string[];
262
+ contract_address: string;
263
+ receipt: {
264
+ energy_usage: number;
265
+ energy_fee: number;
266
+ origin_energy_usage: number;
267
+ energy_usage_total: number;
268
+ net_usage: number;
269
+ net_fee: number;
270
+ result: string;
271
+ energy_penalty_total: number;
272
+ };
273
+ log: {
274
+ address: Address;
275
+ topics: string[];
276
+ data: string;
277
+ }[];
278
+ result?: 'FAILED';
279
+ resMessage: string;
280
+ withdraw_amount: number;
281
+ unfreeze_amount: number;
282
+ withdraw_expire_amount: number;
283
+ cancel_unfreezeV2_amount: HTTPMap<string, number>;
284
+ exchange_id: string;
285
+ }
@@ -0,0 +1,25 @@
1
+ export type BytesLike = number[] | Uint8Array;
2
+
3
+ export type EventQueryDataType = {
4
+ block_number: number;
5
+ block_timestamp: number;
6
+ contract_address: string;
7
+ event_name: string;
8
+ transaction_id: string;
9
+ result: unknown;
10
+ resource_Node: string;
11
+ _unconfirmed?: boolean;
12
+ _fingerprint?: string | undefined;
13
+ };
14
+
15
+ export type MapEventQueryDataType = {
16
+ block: number;
17
+ timestamp: number;
18
+ contract: string;
19
+ name: string;
20
+ transaction: string;
21
+ result: unknown;
22
+ resourceNode: string;
23
+ unconfirmed?: boolean;
24
+ fingerprint?: string | undefined;
25
+ };
@@ -0,0 +1,9 @@
1
+ export * from './ABI.js';
2
+ export * from './APIResponse.js';
3
+ export * from './Contract.js';
4
+ export * from './Providers.js';
5
+ export * from './Transaction.js';
6
+ export * from './TransactionBuilder.js';
7
+ export * from './TronWeb.js';
8
+ export * from './Trx.js';
9
+ export * from './UtilsTypes.js';
@@ -0,0 +1 @@
1
+ declare function parseInt(string: string | number, radix?: number | undefined): number;
@@ -0,0 +1,257 @@
1
+ import { AbiCoder } from './ethersUtils.js';
2
+ import { TronWeb } from '../tronweb.js';
3
+ import { ADDRESS_PREFIX, ADDRESS_PREFIX_REGEX } from './address.js';
4
+ import { FunctionFragment, AbiParamsCommon, AbiInputsType } from '../types/ABI.js';
5
+
6
+ const abiCoder = new AbiCoder();
7
+
8
+ function _addressToHex(value: string) {
9
+ return TronWeb.address.toHex(value).replace(ADDRESS_PREFIX_REGEX, '0x');
10
+ }
11
+
12
+ export function decodeParams(names: string[], types: string[], output: string, ignoreMethodHash = false) {
13
+ if (ignoreMethodHash && output.replace(/^0x/, '').length % 64 === 8) output = '0x' + output.replace(/^0x/, '').substring(8);
14
+
15
+ if (output.replace(/^0x/, '').length % 64) {
16
+ throw new Error('The encoded string is not valid. Its length must be a multiple of 64.');
17
+ }
18
+
19
+ // workaround for unsupported trcToken type
20
+ types = types.map((type) => {
21
+ if (/trcToken/.test(type)) {
22
+ type = type.replace(/trcToken/, 'uint256');
23
+ }
24
+ return type;
25
+ });
26
+
27
+ return abiCoder.decode(types, output).reduce(
28
+ (obj, arg, index) => {
29
+ if (types[index] == 'address') {
30
+ arg = ADDRESS_PREFIX + arg.substr(2).toLowerCase();
31
+ }
32
+
33
+ if (names.length) {
34
+ obj[names[index]] = arg;
35
+ } else {
36
+ obj.push(arg);
37
+ }
38
+
39
+ return obj;
40
+ },
41
+ names.length ? {} : []
42
+ );
43
+ }
44
+
45
+ export function encodeParams(types: string[], values: any[]) {
46
+ for (let i = 0; i < types.length; i++) {
47
+ if (types[i] === 'address') {
48
+ values[i] = TronWeb.address.toHex(values[i]).replace(ADDRESS_PREFIX_REGEX, '0x');
49
+ }
50
+ }
51
+
52
+ return abiCoder.encode(types, values);
53
+ }
54
+
55
+ function extractSize(type: string) {
56
+ const size = type.match(/([a-zA-Z0-9])(\[.*\])/);
57
+ return size ? size[2] : '';
58
+ }
59
+
60
+ function extractArrayDim(type: string) {
61
+ const size = extractSize(type);
62
+ return (size.match(/\]\[/g) || []).length + 1;
63
+ }
64
+
65
+ export function encodeParamsV2ByABI(funABI: FunctionFragment, args: any[]) {
66
+ const types: string[] = [];
67
+
68
+ const buildFullTypeDefinition = (typeDef: AbiParamsCommon): string => {
69
+ if (typeDef && typeDef.type.indexOf('tuple') === 0 && typeDef.components) {
70
+ const innerTypes = typeDef.components.map((innerType: AbiParamsCommon) => {
71
+ return buildFullTypeDefinition(innerType);
72
+ });
73
+ return `tuple(${innerTypes.join(',')})${extractSize(typeDef.type)}`;
74
+ }
75
+
76
+ if (/trcToken/.test(typeDef.type)) return typeDef.type.replace(/trcToken/, 'uint256');
77
+
78
+ return typeDef.type;
79
+ };
80
+
81
+ const convertTypes = (types: string[]) => {
82
+ for (let i = 0; i < types.length; i++) {
83
+ const type = types[i];
84
+ if (/trcToken/.test(type)) types[i] = type.replace(/trcToken/, 'uint256');
85
+ }
86
+ };
87
+
88
+ const convertAddresses = (addrArr: string | string[]) => {
89
+ if (Array.isArray(addrArr)) {
90
+ addrArr.forEach((addrs, i) => {
91
+ addrArr[i] = convertAddresses(addrs) as string;
92
+ });
93
+ return addrArr;
94
+ } else {
95
+ return _addressToHex(addrArr);
96
+ }
97
+ };
98
+
99
+ const mapTuple = (components: ReadonlyArray<FunctionFragment>, args: any[], dimension: number) => {
100
+ if (dimension > 1) {
101
+ if (args.length) {
102
+ args.forEach((arg) => {
103
+ mapTuple(components, arg, dimension - 1);
104
+ });
105
+ }
106
+ } else {
107
+ if (args.length && dimension) {
108
+ args.forEach((arg) => {
109
+ encodeArgs(components, arg);
110
+ });
111
+ }
112
+ }
113
+ };
114
+
115
+ const encodeArgs = (inputs: ReadonlyArray<AbiParamsCommon> = [], args: any[]) => {
116
+ if (inputs.length)
117
+ inputs.forEach((input: AbiParamsCommon, i: number) => {
118
+ const type = input.type;
119
+
120
+ if (args[i])
121
+ if (type === 'address') args[i] = _addressToHex(args[i]);
122
+ else if (type.match(/^([^\x5b]*)(\x5b|$)/)![0] === 'address[') convertAddresses(args[i]);
123
+ else if (type.indexOf('tuple') === 0)
124
+ if (extractSize(type)) {
125
+ const dimension = extractArrayDim(type);
126
+ mapTuple(input.components!, args[i], dimension);
127
+ } else encodeArgs(input.components!, args[i]);
128
+ });
129
+ };
130
+
131
+ if (funABI.inputs && funABI.inputs.length) {
132
+ for (let i = 0; i < funABI.inputs.length; i++) {
133
+ const type = funABI.inputs[i].type;
134
+ // "false" will be converting to `false` and "true" will be working
135
+ // fine as abiCoder assume anything in quotes as `true`
136
+ if (type === 'bool' && args[i] === 'false') {
137
+ args[i] = false;
138
+ }
139
+ types.push(type.indexOf('tuple') === 0 ? buildFullTypeDefinition(funABI.inputs[i]) : type);
140
+ if (args.length < types.length) {
141
+ args.push('');
142
+ }
143
+ }
144
+ }
145
+
146
+ encodeArgs(funABI.inputs, args);
147
+ convertTypes(types);
148
+
149
+ return abiCoder.encode(types, args);
150
+ }
151
+
152
+ export function decodeParamsV2ByABI(funABI: FunctionFragment | AbiInputsType, data: string | Uint8Array) {
153
+ const convertTypeNames = (types: string[]) => {
154
+ for (let i = 0; i < types.length; i++) {
155
+ const type = types[i];
156
+ if (/^trcToken/.test(type)) types[i] = type.replace(/^trcToken/, 'uint256');
157
+ }
158
+ };
159
+
160
+ const convertAddresses = (addrArr: string | string[]) => {
161
+ if (Array.isArray(addrArr)) {
162
+ addrArr.forEach((addrs, i) => {
163
+ addrArr[i] = convertAddresses(addrs) as string;
164
+ });
165
+ return addrArr;
166
+ } else {
167
+ return TronWeb.address.toHex(addrArr);
168
+ }
169
+ };
170
+
171
+ const mapTuple = (components: ReadonlyArray<AbiParamsCommon>, args: string[] | string[][], dimension: number) => {
172
+ if (dimension > 1) {
173
+ if (args.length) {
174
+ args.forEach((arg) => {
175
+ mapTuple(components, arg as string[], dimension - 1);
176
+ });
177
+ }
178
+ } else {
179
+ if (args.length && dimension) {
180
+ args.forEach((arg) => {
181
+ decodeResult(components, arg as string[]);
182
+ });
183
+ }
184
+ }
185
+ };
186
+
187
+ const buildFullTypeNameDefinition = (typeDef: AbiParamsCommon): string => {
188
+ const name = typeDef.name ? ` ${typeDef.name}` : '';
189
+ if (typeDef && typeDef.type.indexOf('tuple') === 0 && typeDef.components) {
190
+ const innerTypes = typeDef.components.map((innerType) => {
191
+ return buildFullTypeNameDefinition(innerType);
192
+ });
193
+ return `tuple(${innerTypes.join(',')})${extractSize(typeDef.type)}${name}`;
194
+ }
195
+ if (/trcToken/.test(typeDef.type)) return typeDef.type.replace(/trcToken/, 'uint256') + name;
196
+
197
+ return typeDef.type + name;
198
+ };
199
+
200
+ const decodeResult = (outputs: ReadonlyArray<AbiParamsCommon>, result: any[]) => {
201
+ if (outputs.length)
202
+ outputs.forEach((output, i) => {
203
+ const { type, name } = output;
204
+
205
+ if (result[i]) {
206
+ if (type === 'address') {
207
+ result[i] = TronWeb.address.toHex(result[i]);
208
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
209
+ //@ts-ignore
210
+ if (name) result[name] = TronWeb.address.toHex(result[i]);
211
+ } else if (type.match(/^([^\x5b]*)(\x5b|$)/)![0] === 'address[') {
212
+ convertAddresses(result[i]);
213
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
214
+ //@ts-ignore
215
+ if (name) result[name] = convertAddresses(result[i]);
216
+ } else if (type.indexOf('tuple') === 0) {
217
+ if (extractSize(type)) {
218
+ const dimension = extractArrayDim(type);
219
+ mapTuple(output.components!, result[i], dimension);
220
+ } else decodeResult(output.components!, result[i]);
221
+
222
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
223
+ //@ts-ignore
224
+ if (name) result[name] = result[i];
225
+ } else {
226
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
227
+ //@ts-ignore
228
+ if (name) result[name] = result[i];
229
+ }
230
+ } else {
231
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
232
+ //@ts-ignore
233
+ if (name) result[name] = result[i];
234
+ }
235
+ });
236
+ };
237
+
238
+ // Only decode if there supposed to be fields
239
+ if ('outputs' in funABI && funABI.outputs && funABI.outputs.length > 0) {
240
+ const outputTypes: any[] = [];
241
+ for (let i = 0; i < funABI.outputs.length; i++) {
242
+ const type = funABI.outputs[i].type;
243
+ const name = funABI.outputs[i].name ? ` ${funABI.outputs[i].name}` : '';
244
+ outputTypes.push(type.indexOf('tuple') === 0 ? buildFullTypeNameDefinition(funABI.outputs[i]) : type + name);
245
+ }
246
+ convertTypeNames(outputTypes);
247
+
248
+ if (!data || !data.length) data = new Uint8Array(32 * funABI.outputs.length); // ensuring the data is at least filled by 0 cause `AbiCoder` throws if there's not engouh data
249
+ // decode data
250
+ const decodeRes = abiCoder.decode(outputTypes, data);
251
+ const decodeResCopy = decodeRes.toArray(true);
252
+ decodeResult(funABI.outputs, decodeResCopy);
253
+
254
+ return decodeResCopy;
255
+ }
256
+ return [];
257
+ }
@@ -0,0 +1,60 @@
1
+ import { byteArray2hexStr } from './bytes.js';
2
+ import { getBase58CheckAddress, genPriKey, getAddressFromPriKey, getPubKeyFromPriKey, pkToAddress } from './crypto.js';
3
+ import { ethersHDNodeWallet, Mnemonic, Wordlist } from './ethersUtils.js';
4
+ import { TRON_BIP39_PATH_INDEX_0 } from './address.js';
5
+
6
+ const INVALID_TRON_PATH_ERROR_MSG = 'Invalid tron path provided';
7
+
8
+ export function generateAccount() {
9
+ const priKeyBytes = genPriKey();
10
+ const pubKeyBytes = getPubKeyFromPriKey(priKeyBytes);
11
+ const addressBytes = getAddressFromPriKey(priKeyBytes);
12
+
13
+ const privateKey = byteArray2hexStr(priKeyBytes);
14
+ const publicKey = byteArray2hexStr(pubKeyBytes);
15
+
16
+ return {
17
+ privateKey,
18
+ publicKey,
19
+ address: {
20
+ base58: getBase58CheckAddress(addressBytes),
21
+ hex: byteArray2hexStr(addressBytes),
22
+ },
23
+ };
24
+ }
25
+
26
+ export function generateRandom(password = '', path = TRON_BIP39_PATH_INDEX_0, wordlist?: Wordlist) {
27
+ const account = ethersHDNodeWallet.createRandom(password, path, wordlist);
28
+
29
+ const result = {
30
+ mnemonic: account.mnemonic,
31
+ privateKey: account.privateKey,
32
+ publicKey: account.signingKey.publicKey,
33
+ address: pkToAddress(account.privateKey.replace(/^0x/, '')),
34
+ path: account.path,
35
+ };
36
+
37
+ return result;
38
+ }
39
+
40
+ export function generateAccountWithMnemonic(
41
+ mnemonic: string,
42
+ path: string = TRON_BIP39_PATH_INDEX_0,
43
+ password: string | null | undefined = '',
44
+ wordlist: Wordlist | null = null
45
+ ) {
46
+ // eslint-disable-next-line no-useless-escape
47
+ if (!String(path).match(/^m\/44\'\/195\'/)) {
48
+ throw new Error(INVALID_TRON_PATH_ERROR_MSG);
49
+ }
50
+ const account = ethersHDNodeWallet.fromMnemonic(Mnemonic.fromPhrase(mnemonic, password, wordlist), path);
51
+
52
+ const result = {
53
+ mnemonic: account.mnemonic,
54
+ privateKey: account.privateKey,
55
+ publicKey: account.signingKey.publicKey,
56
+ address: pkToAddress(account.privateKey.replace(/^0x/, '')),
57
+ };
58
+
59
+ return result;
60
+ }