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
package/src/tronweb.ts ADDED
@@ -0,0 +1,437 @@
1
+ import { HttpProvider, providers } from './lib/providers/index.js';
2
+ import type { Providers } from './lib/providers/index.js';
3
+ import utils from './utils/index.js';
4
+ import { BigNumber } from 'bignumber.js';
5
+ import EventEmitter from 'eventemitter3';
6
+ import semver from 'semver';
7
+
8
+ import { TransactionBuilder } from './lib/TransactionBuilder/TransactionBuilder.js';
9
+ import { Trx } from './lib/trx.js';
10
+ import { Contract } from './lib/contract/index.js';
11
+ import { Plugin } from './lib/plugin.js';
12
+ import { Event } from './lib/event.js';
13
+ import { keccak256 } from './utils/ethersUtils.js';
14
+ import { fromHex, fromPrivateKey, isAddress, toHex, toChecksumAddress, isChecksumAddress } from './utils/address.js';
15
+ import { HeadersType } from './types/Providers.js';
16
+ import { isString } from './utils/validations.js';
17
+ import { DefaultAddress, NodeProvider, TronWebOptions, IBigNumber } from './types/TronWeb.js';
18
+ import { ContractAbiInterface } from './types/ABI.js';
19
+ import { Address } from './types/Trx.js';
20
+
21
+ const DEFAULT_VERSION = '4.7.1';
22
+
23
+ const FEE_LIMIT = 150000000;
24
+
25
+ const version = '6.0.0';
26
+
27
+ function isValidOptions(options: unknown): options is TronWebOptions {
28
+ return (
29
+ !!options &&
30
+ typeof options === 'object' &&
31
+ (!!(options as TronWebOptions).fullNode || !!(options as TronWebOptions).fullHost)
32
+ );
33
+ }
34
+
35
+ export class TronWeb extends EventEmitter {
36
+ providers: Providers;
37
+ BigNumber: typeof BigNumber;
38
+ transactionBuilder: TransactionBuilder;
39
+ trx: Trx;
40
+ plugin: Plugin;
41
+ event: Event;
42
+ version: typeof TronWeb.version;
43
+ static version = version;
44
+ utils: typeof utils;
45
+
46
+ defaultBlock: number | false | 'earliest' | 'latest';
47
+ defaultPrivateKey: string | false;
48
+ defaultAddress: DefaultAddress;
49
+ fullnodeVersion: string;
50
+ feeLimit: number;
51
+
52
+ fullNode!: HttpProvider;
53
+ solidityNode!: HttpProvider;
54
+ eventServer?: HttpProvider;
55
+
56
+ constructor(options: TronWebOptions);
57
+ constructor(fullNode: NodeProvider, solidityNode: NodeProvider, eventServer?: NodeProvider, privateKey?: string);
58
+ /* prettier-ignore */
59
+ constructor(fullNode: NodeProvider, solidityNode: NodeProvider, eventServer: NodeProvider, privateKey?: string);
60
+ constructor(
61
+ options: TronWebOptions | NodeProvider,
62
+ solidityNode: NodeProvider = '',
63
+ eventServer?: NodeProvider,
64
+ privateKey = ''
65
+ ) {
66
+ super();
67
+
68
+ let fullNode;
69
+ let headers: HeadersType | false = false;
70
+ let eventHeaders: HeadersType | false = false;
71
+
72
+ if (isValidOptions(options)) {
73
+ fullNode = options.fullNode || options.fullHost;
74
+ solidityNode = (options.solidityNode || options.fullHost)!;
75
+ eventServer = (options.eventServer || options.fullHost)!;
76
+ headers = options.headers || false;
77
+ eventHeaders = options.eventHeaders || headers;
78
+ privateKey = options.privateKey!;
79
+ } else {
80
+ fullNode = options;
81
+ }
82
+ if (utils.isString(fullNode)) fullNode = new providers.HttpProvider(fullNode);
83
+
84
+ if (utils.isString(solidityNode)) solidityNode = new providers.HttpProvider(solidityNode);
85
+
86
+ if (utils.isString(eventServer)) eventServer = new providers.HttpProvider(eventServer);
87
+
88
+ this.event = new Event(this);
89
+ this.transactionBuilder = new TransactionBuilder(this);
90
+ this.trx = new Trx(this);
91
+ this.plugin = new Plugin(this, {
92
+ disablePlugins: isValidOptions(options) ? options.disablePlugins : false,
93
+ });
94
+ this.utils = utils;
95
+
96
+ this.setFullNode(fullNode as HttpProvider);
97
+ this.setSolidityNode(solidityNode as HttpProvider);
98
+ this.setEventServer(eventServer!);
99
+
100
+ this.providers = providers;
101
+ this.BigNumber = BigNumber;
102
+
103
+ this.defaultBlock = false;
104
+ this.defaultPrivateKey = false;
105
+ this.defaultAddress = {
106
+ hex: false,
107
+ base58: false,
108
+ };
109
+
110
+ this.version = TronWeb.version;
111
+ this.sha3 = TronWeb.sha3;
112
+ this.fromUtf8 = TronWeb.fromUtf8;
113
+ this.address = TronWeb.address;
114
+ this.toAscii = TronWeb.toAscii;
115
+ this.toUtf8 = TronWeb.toUtf8;
116
+ this.isAddress = TronWeb.isAddress;
117
+ this.fromAscii = TronWeb.fromAscii;
118
+ this.toHex = TronWeb.toHex;
119
+ this.toBigNumber = TronWeb.toBigNumber;
120
+ this.toDecimal = TronWeb.toDecimal;
121
+ this.fromDecimal = TronWeb.fromDecimal;
122
+ this.toSun = TronWeb.toSun;
123
+ this.fromSun = TronWeb.fromSun;
124
+ this.createAccount = TronWeb.createAccount;
125
+ this.createRandom = TronWeb.createRandom;
126
+ this.fromMnemonic = TronWeb.fromMnemonic;
127
+
128
+ if (privateKey) this.setPrivateKey(privateKey);
129
+ this.fullnodeVersion = DEFAULT_VERSION;
130
+ this.feeLimit = FEE_LIMIT;
131
+
132
+ if (headers) {
133
+ this.setFullNodeHeader(headers);
134
+ }
135
+
136
+ if (eventHeaders) {
137
+ this.setEventHeader(eventHeaders);
138
+ }
139
+ }
140
+
141
+ async getFullnodeVersion() {
142
+ try {
143
+ const nodeInfo = await this.trx.getNodeInfo();
144
+ this.fullnodeVersion = nodeInfo.configNodeInfo.codeVersion;
145
+ if (this.fullnodeVersion.split('.').length === 2) {
146
+ this.fullnodeVersion += '.0';
147
+ }
148
+ } catch (err) {
149
+ this.fullnodeVersion = DEFAULT_VERSION;
150
+ }
151
+ }
152
+
153
+ setDefaultBlock(blockID: false | 'latest' | 'earliest' | number = false) {
154
+ if ([false, 'latest', 'earliest', 0].includes(blockID)) {
155
+ return (this.defaultBlock = blockID);
156
+ }
157
+
158
+ if (!utils.isInteger(blockID) || !blockID) throw new Error('Invalid block ID provided');
159
+
160
+ return (this.defaultBlock = Math.abs(blockID));
161
+ }
162
+
163
+ setPrivateKey(privateKey: string) {
164
+ try {
165
+ this.setAddress(TronWeb.address.fromPrivateKey(privateKey) as string);
166
+ } catch {
167
+ throw new Error('Invalid private key provided');
168
+ }
169
+
170
+ this.defaultPrivateKey = privateKey;
171
+ this.emit('privateKeyChanged', privateKey);
172
+ }
173
+
174
+ setAddress(address: string) {
175
+ if (!TronWeb.isAddress(address)) throw new Error('Invalid address provided');
176
+
177
+ const hex = TronWeb.address.toHex(address);
178
+ const base58 = TronWeb.address.fromHex(address);
179
+
180
+ if (this.defaultPrivateKey && TronWeb.address.fromPrivateKey(this.defaultPrivateKey) !== base58)
181
+ this.defaultPrivateKey = false;
182
+
183
+ this.defaultAddress = {
184
+ hex,
185
+ base58,
186
+ };
187
+
188
+ this.emit('addressChanged', { hex, base58 });
189
+ }
190
+
191
+ fullnodeSatisfies(version: string) {
192
+ return semver.satisfies(this.fullnodeVersion, version);
193
+ }
194
+
195
+ isValidProvider(provider: unknown) {
196
+ return Object.values(providers).some((knownProvider) => provider instanceof knownProvider);
197
+ }
198
+
199
+ setFullNode(fullNode: HttpProvider | string) {
200
+ if (isString(fullNode)) fullNode = new providers.HttpProvider(fullNode);
201
+
202
+ if (!this.isValidProvider(fullNode)) throw new Error('Invalid full node provided');
203
+
204
+ this.fullNode = fullNode;
205
+ this.fullNode.setStatusPage('wallet/getnowblock');
206
+ }
207
+
208
+ setSolidityNode(solidityNode: HttpProvider | string) {
209
+ if (utils.isString(solidityNode)) solidityNode = new providers.HttpProvider(solidityNode);
210
+
211
+ if (!this.isValidProvider(solidityNode)) throw new Error('Invalid solidity node provided');
212
+
213
+ this.solidityNode = solidityNode;
214
+ this.solidityNode.setStatusPage('walletsolidity/getnowblock');
215
+ }
216
+
217
+ setEventServer(eventServer: NodeProvider, healthcheck?: string) {
218
+ this.event.setServer(eventServer, healthcheck);
219
+ }
220
+
221
+ setHeader(headers = {}) {
222
+ const fullNode = new providers.HttpProvider(this.fullNode.host, 30000, '', '', headers);
223
+ const solidityNode = new providers.HttpProvider(this.solidityNode.host, 30000, '', '', headers);
224
+ const eventServer = new providers.HttpProvider(this.eventServer!.host, 30000, '', '', headers);
225
+
226
+ this.setFullNode(fullNode);
227
+ this.setSolidityNode(solidityNode);
228
+ this.setEventServer(eventServer);
229
+ }
230
+
231
+ setFullNodeHeader(headers = {}) {
232
+ const fullNode = new providers.HttpProvider(this.fullNode.host, 30000, '', '', headers);
233
+ const solidityNode = new providers.HttpProvider(this.solidityNode.host, 30000, '', '', headers);
234
+
235
+ this.setFullNode(fullNode);
236
+ this.setSolidityNode(solidityNode);
237
+ }
238
+
239
+ setEventHeader(headers = {}) {
240
+ const eventServer = new providers.HttpProvider(this.eventServer!.host, 30000, '', '', headers);
241
+ this.setEventServer(eventServer);
242
+ }
243
+
244
+ currentProviders() {
245
+ return {
246
+ fullNode: this.fullNode,
247
+ solidityNode: this.solidityNode,
248
+ eventServer: this.eventServer,
249
+ };
250
+ }
251
+
252
+ currentProvider() {
253
+ return this.currentProviders();
254
+ }
255
+
256
+ getEventResult(...params: Parameters<Event['getEventsByContractAddress']>): ReturnType<Event['getEventsByContractAddress']> {
257
+ return this.event.getEventsByContractAddress(...params);
258
+ }
259
+
260
+ getEventByTransactionID(
261
+ ...params: Parameters<Event['getEventsByTransactionID']>
262
+ ): ReturnType<Event['getEventsByTransactionID']> {
263
+ return this.event.getEventsByTransactionID(...params);
264
+ }
265
+
266
+ contract(abi: ContractAbiInterface = [], address?: Address) {
267
+ return new Contract(this, abi, address!);
268
+ }
269
+
270
+ address: typeof TronWeb.address;
271
+ static get address() {
272
+ return {
273
+ fromHex(address: string) {
274
+ return fromHex(address);
275
+ },
276
+ toHex(address: string) {
277
+ return toHex(address);
278
+ },
279
+ toChecksumAddress(address: string) {
280
+ return toChecksumAddress(address);
281
+ },
282
+ isChecksumAddress(address: string) {
283
+ return isChecksumAddress(address);
284
+ },
285
+ fromPrivateKey(privateKey: string, strict = false) {
286
+ return fromPrivateKey(privateKey, strict);
287
+ },
288
+ };
289
+ }
290
+
291
+ sha3: typeof TronWeb.sha3;
292
+ static sha3(string: string, prefix = true) {
293
+ return (prefix ? '0x' : '') + keccak256(Buffer.from(string, 'utf-8')).toString().substring(2);
294
+ }
295
+
296
+ toHex: typeof TronWeb.toHex;
297
+ static toHex(val: string | number | boolean | Record<string | number | symbol, unknown> | unknown[] | IBigNumber) {
298
+ if (utils.isBoolean(val)) return TronWeb.fromDecimal(+val);
299
+
300
+ if (utils.isBigNumber(val)) return TronWeb.fromDecimal(val);
301
+
302
+ if (typeof val === 'object') return TronWeb.fromUtf8(JSON.stringify(val));
303
+
304
+ if (utils.isString(val)) {
305
+ if (/^(-|)0x/.test(val)) return val;
306
+
307
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
308
+ // @ts-ignore
309
+ if (!isFinite(val) || /^\s*$/.test(val)) return TronWeb.fromUtf8(val);
310
+ }
311
+
312
+ const result = TronWeb.fromDecimal(val as number);
313
+ if (result === '0xNaN') {
314
+ throw new Error('The passed value is not convertible to a hex string');
315
+ } else {
316
+ return result;
317
+ }
318
+ }
319
+
320
+ toUtf8: typeof TronWeb.toUtf8;
321
+ static toUtf8(hex: string) {
322
+ if (utils.isHex(hex)) {
323
+ hex = hex.replace(/^0x/, '');
324
+ return Buffer.from(hex, 'hex').toString('utf8');
325
+ } else {
326
+ throw new Error('The passed value is not a valid hex string');
327
+ }
328
+ }
329
+
330
+ fromUtf8: typeof TronWeb.fromUtf8;
331
+ static fromUtf8(string: string) {
332
+ if (!utils.isString(string)) {
333
+ throw new Error('The passed value is not a valid utf-8 string');
334
+ }
335
+ return '0x' + Buffer.from(string, 'utf8').toString('hex');
336
+ }
337
+
338
+ toAscii: typeof TronWeb.toAscii;
339
+ static toAscii(hex: string) {
340
+ if (utils.isHex(hex)) {
341
+ let str = '';
342
+ let i = 0;
343
+ const l = hex.length;
344
+ if (hex.substring(0, 2) === '0x') {
345
+ i = 2;
346
+ }
347
+ for (; i < l; i += 2) {
348
+ const code = parseInt(hex.substr(i, 2), 16);
349
+ str += String.fromCharCode(code);
350
+ }
351
+ return str;
352
+ } else {
353
+ throw new Error('The passed value is not a valid hex string');
354
+ }
355
+ }
356
+
357
+ fromAscii: typeof TronWeb.fromAscii;
358
+ static fromAscii(string: string, padding?: number) {
359
+ if (!utils.isString(string)) {
360
+ throw new Error('The passed value is not a valid utf-8 string');
361
+ }
362
+ return '0x' + Buffer.from(string, 'ascii').toString('hex').padEnd(padding!, '0');
363
+ }
364
+
365
+ toDecimal: typeof TronWeb.toDecimal;
366
+ static toDecimal(value: string | number | IBigNumber) {
367
+ return TronWeb.toBigNumber(value).toNumber();
368
+ }
369
+
370
+ fromDecimal: typeof TronWeb.fromDecimal;
371
+ static fromDecimal(value: number | IBigNumber) {
372
+ const number = TronWeb.toBigNumber(value);
373
+ const result = number.toString(16);
374
+
375
+ return number.isLessThan(0) ? '-0x' + result.substr(1) : '0x' + result;
376
+ }
377
+
378
+ fromSun: typeof TronWeb.fromSun;
379
+ static fromSun(sun: number): string | IBigNumber {
380
+ const trx = TronWeb.toBigNumber(sun).div(1_000_000);
381
+ return utils.isBigNumber(sun) ? trx : trx.toString(10);
382
+ }
383
+
384
+ toSun: typeof TronWeb.toSun;
385
+ static toSun(trx: number): string | IBigNumber {
386
+ const sun = TronWeb.toBigNumber(trx).times(1_000_000);
387
+ return utils.isBigNumber(trx) ? sun : sun.toString(10);
388
+ }
389
+
390
+ toBigNumber: typeof TronWeb.toBigNumber;
391
+ static toBigNumber(amount: string | number | IBigNumber = 0): IBigNumber {
392
+ if (utils.isBigNumber(amount)) return amount;
393
+
394
+ if (utils.isString(amount) && /^(-|)0x/.test(amount)) return new BigNumber(amount.replace('0x', ''), 16);
395
+
396
+ return new BigNumber(amount.toString(10), 10);
397
+ }
398
+
399
+ isAddress: typeof TronWeb.isAddress;
400
+ static isAddress(address: unknown = ''): boolean {
401
+ return isAddress(address);
402
+ }
403
+
404
+ createAccount: typeof TronWeb.createAccount;
405
+ static async createAccount() {
406
+ const account = utils.accounts.generateAccount();
407
+
408
+ return account;
409
+ }
410
+
411
+ createRandom: typeof TronWeb.createRandom;
412
+ static createRandom(
413
+ ...params: Parameters<(typeof utils)['accounts']['generateRandom']>
414
+ ): ReturnType<(typeof utils)['accounts']['generateRandom']> {
415
+ const account = utils.accounts.generateRandom(...params);
416
+
417
+ return account;
418
+ }
419
+
420
+ fromMnemonic: typeof TronWeb.fromMnemonic;
421
+ static fromMnemonic(
422
+ ...params: Parameters<(typeof utils)['accounts']['generateAccountWithMnemonic']>
423
+ ): ReturnType<(typeof utils)['accounts']['generateAccountWithMnemonic']> {
424
+ const account = utils.accounts.generateAccountWithMnemonic(...params);
425
+
426
+ return account;
427
+ }
428
+
429
+ async isConnected() {
430
+ return {
431
+ fullNode: await this.fullNode.isConnected(),
432
+ solidityNode: await this.solidityNode.isConnected(),
433
+ eventServer: this.eventServer && (await this.eventServer.isConnected()),
434
+ };
435
+ }
436
+ }
437
+ export default TronWeb;
@@ -0,0 +1,82 @@
1
+ export type AbiParamsCommon = {
2
+ readonly name: string;
3
+ readonly type: string;
4
+ readonly baseType?: string;
5
+ readonly indexed?: boolean;
6
+ readonly components?: ReadonlyArray<AbiParamsCommon>;
7
+ readonly arrayLength?: number;
8
+ readonly arrayChildren?: ReadonlyArray<AbiParamsCommon>;
9
+ readonly internalType?: string;
10
+ };
11
+
12
+ export type StateMutabilityTypes = string | 'nonpayable' | 'payable' | 'pure' | 'view';
13
+
14
+ export type FragmentTypes = string | 'constructor' | 'event' | 'function' | 'fallback' | 'receive';
15
+
16
+ export type AbiInputsType = ReadonlyArray<AbiParamsCommon> | Record<any, any> | [];
17
+
18
+ export type AbiOutputsType = AbiInputsType;
19
+
20
+ export type ConstructorFragment = {
21
+ readonly type: string | 'constructor';
22
+ readonly stateMutability: StateMutabilityTypes & (string | 'nonpayable' | 'payable');
23
+ readonly inputs?: ReadonlyArray<AbiParamsCommon>;
24
+ };
25
+
26
+ export type FunctionFragment = {
27
+ readonly name: string;
28
+ readonly type: string | 'function';
29
+ readonly stateMutability?: StateMutabilityTypes;
30
+ readonly inputs?: ReadonlyArray<AbiParamsCommon>;
31
+ readonly outputs?: ReadonlyArray<AbiParamsCommon>;
32
+
33
+ readonly constant?: boolean;
34
+ readonly payable?: boolean;
35
+ };
36
+
37
+ export type FallbackFragment = {
38
+ readonly name: never;
39
+ readonly type: string | 'fallback';
40
+ readonly stateMutability: StateMutabilityTypes;
41
+ readonly inputs: never;
42
+ readonly outputs: never;
43
+
44
+ // legacy properties
45
+ readonly constant?: boolean;
46
+ readonly payable?: boolean;
47
+ };
48
+
49
+ export type ReceiveFragment = {
50
+ readonly name: never;
51
+ readonly type: string | 'receive';
52
+ readonly stateMutability: StateMutabilityTypes;
53
+ readonly inputs: never;
54
+ readonly outputs: never;
55
+
56
+ // legacy properties
57
+ readonly constant?: boolean;
58
+ readonly payable?: boolean;
59
+ };
60
+
61
+ export type EventFragment = {
62
+ readonly name: string;
63
+ readonly type: string | 'event';
64
+ readonly inputs?: ReadonlyArray<AbiParamsCommon>;
65
+ readonly anonymous?: boolean;
66
+ };
67
+
68
+ export type ErrorFragment = {
69
+ readonly name: string;
70
+ readonly type: string | 'error';
71
+ readonly inputs?: ReadonlyArray<AbiParamsCommon>;
72
+ };
73
+
74
+ export type AbiFragment =
75
+ | ConstructorFragment
76
+ | FunctionFragment
77
+ | EventFragment
78
+ | ErrorFragment
79
+ | FallbackFragment
80
+ | ReceiveFragment;
81
+
82
+ export type ContractAbiInterface = ReadonlyArray<AbiFragment>;
@@ -0,0 +1,34 @@
1
+ import { Permission } from './Contract.js';
2
+ import { Transaction, TransactionWrapper } from './Transaction.js';
3
+
4
+ export interface BlockHeaderRawData {
5
+ number: number;
6
+ txTrieRoot: string;
7
+ witness_address: string;
8
+ parentHash: string;
9
+ version: number;
10
+ timestamp: number;
11
+ }
12
+ export interface BlockHeader {
13
+ raw_data: BlockHeaderRawData;
14
+ witness_signature: string;
15
+ }
16
+ export interface BlockWithoutDetail {
17
+ blockID: string;
18
+ block_header: BlockHeader;
19
+ }
20
+
21
+ export interface Block {
22
+ blockID: string;
23
+ /** If a block has 0 transaction, this prop will be undefined */
24
+ transactions?: Transaction[];
25
+ block_header: BlockHeader;
26
+ }
27
+
28
+ export interface GetSignWeightResponse {
29
+ permission: Permission;
30
+ result: {
31
+ code: string;
32
+ };
33
+ transaction: TransactionWrapper;
34
+ }