phantasma-sdk-ts 0.1.71

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 (478) hide show
  1. package/.eslintignore +13 -0
  2. package/.eslintrc.cjs +15 -0
  3. package/.github/workflows/npm-publish.yml +47 -0
  4. package/.prettierignore +13 -0
  5. package/.prettierrc +8 -0
  6. package/LICENSE +201 -0
  7. package/README.md +842 -0
  8. package/babel.config.js +6 -0
  9. package/core/index.d.ts +10 -0
  10. package/core/index.d.ts.map +1 -0
  11. package/core/index.js +25 -0
  12. package/core/interfaces/IContract.d.ts +27 -0
  13. package/core/interfaces/IContract.d.ts.map +1 -0
  14. package/core/interfaces/IContract.js +25 -0
  15. package/core/interfaces/IKeyPair.d.ts +7 -0
  16. package/core/interfaces/IKeyPair.d.ts.map +1 -0
  17. package/core/interfaces/IKeyPair.js +2 -0
  18. package/core/interfaces/ISerializable.d.ts +6 -0
  19. package/core/interfaces/ISerializable.d.ts.map +1 -0
  20. package/core/interfaces/ISerializable.js +9 -0
  21. package/core/interfaces/IStack.d.ts +7 -0
  22. package/core/interfaces/IStack.d.ts.map +1 -0
  23. package/core/interfaces/IStack.js +2 -0
  24. package/core/interfaces/IToken.d.ts +29 -0
  25. package/core/interfaces/IToken.d.ts.map +1 -0
  26. package/core/interfaces/IToken.js +22 -0
  27. package/core/interfaces/Signature.d.ts +21 -0
  28. package/core/interfaces/Signature.d.ts.map +1 -0
  29. package/core/interfaces/Signature.js +31 -0
  30. package/core/interfaces/index.d.ts +7 -0
  31. package/core/interfaces/index.d.ts.map +1 -0
  32. package/core/interfaces/index.js +22 -0
  33. package/core/ledger/Address-Transcode.d.ts +20 -0
  34. package/core/ledger/Address-Transcode.d.ts.map +1 -0
  35. package/core/ledger/Address-Transcode.js +70 -0
  36. package/core/ledger/Ledger-Commands.d.ts +76 -0
  37. package/core/ledger/Ledger-Commands.d.ts.map +1 -0
  38. package/core/ledger/Ledger-Commands.js +530 -0
  39. package/core/ledger/Ledger-Utils.d.ts +74 -0
  40. package/core/ledger/Ledger-Utils.d.ts.map +1 -0
  41. package/core/ledger/Ledger-Utils.js +609 -0
  42. package/core/ledger/LedgerConfig.d.ts +17 -0
  43. package/core/ledger/LedgerConfig.d.ts.map +1 -0
  44. package/core/ledger/LedgerConfig.js +2 -0
  45. package/core/ledger/Mnemonic.d.ts +35 -0
  46. package/core/ledger/Mnemonic.d.ts.map +1 -0
  47. package/core/ledger/Mnemonic.js +65 -0
  48. package/core/ledger/Transaction-Sign.d.ts +10 -0
  49. package/core/ledger/Transaction-Sign.d.ts.map +1 -0
  50. package/core/ledger/Transaction-Sign.js +149 -0
  51. package/core/ledger/Transaction-Transcode.d.ts +24 -0
  52. package/core/ledger/Transaction-Transcode.d.ts.map +1 -0
  53. package/core/ledger/Transaction-Transcode.js +47 -0
  54. package/core/ledger/index.d.ts +9 -0
  55. package/core/ledger/index.d.ts.map +1 -0
  56. package/core/ledger/index.js +24 -0
  57. package/core/ledger/interfaces/ApplicationNameResponse.d.ts +6 -0
  58. package/core/ledger/interfaces/ApplicationNameResponse.d.ts.map +1 -0
  59. package/core/ledger/interfaces/ApplicationNameResponse.js +2 -0
  60. package/core/ledger/interfaces/Device.d.ts +7 -0
  61. package/core/ledger/interfaces/Device.d.ts.map +1 -0
  62. package/core/ledger/interfaces/Device.js +2 -0
  63. package/core/ledger/interfaces/DeviceResponse.d.ts +7 -0
  64. package/core/ledger/interfaces/DeviceResponse.d.ts.map +1 -0
  65. package/core/ledger/interfaces/DeviceResponse.js +2 -0
  66. package/core/ledger/interfaces/Ledger.d.ts +2 -0
  67. package/core/ledger/interfaces/Ledger.d.ts.map +1 -0
  68. package/core/ledger/interfaces/Ledger.js +2 -0
  69. package/core/ledger/interfaces/LedgerBalanceFromLedgerResponse.d.ts +12 -0
  70. package/core/ledger/interfaces/LedgerBalanceFromLedgerResponse.d.ts.map +1 -0
  71. package/core/ledger/interfaces/LedgerBalanceFromLedgerResponse.js +2 -0
  72. package/core/ledger/interfaces/LedgerConfig.d.ts +17 -0
  73. package/core/ledger/interfaces/LedgerConfig.d.ts.map +1 -0
  74. package/core/ledger/interfaces/LedgerConfig.js +2 -0
  75. package/core/ledger/interfaces/LedgerDeviceInfoResponse.d.ts +7 -0
  76. package/core/ledger/interfaces/LedgerDeviceInfoResponse.d.ts.map +1 -0
  77. package/core/ledger/interfaces/LedgerDeviceInfoResponse.js +2 -0
  78. package/core/ledger/interfaces/LedgerSendTransactionResponse.d.ts +5 -0
  79. package/core/ledger/interfaces/LedgerSendTransactionResponse.d.ts.map +1 -0
  80. package/core/ledger/interfaces/LedgerSendTransactionResponse.js +2 -0
  81. package/core/ledger/interfaces/LedgerSigner.d.ts +6 -0
  82. package/core/ledger/interfaces/LedgerSigner.d.ts.map +1 -0
  83. package/core/ledger/interfaces/LedgerSigner.js +2 -0
  84. package/core/ledger/interfaces/LedgerSignerData.d.ts +8 -0
  85. package/core/ledger/interfaces/LedgerSignerData.d.ts.map +1 -0
  86. package/core/ledger/interfaces/LedgerSignerData.js +2 -0
  87. package/core/ledger/interfaces/PublicKeyResponse.d.ts +6 -0
  88. package/core/ledger/interfaces/PublicKeyResponse.d.ts.map +1 -0
  89. package/core/ledger/interfaces/PublicKeyResponse.js +2 -0
  90. package/core/ledger/interfaces/SignResponse.d.ts +6 -0
  91. package/core/ledger/interfaces/SignResponse.d.ts.map +1 -0
  92. package/core/ledger/interfaces/SignResponse.js +2 -0
  93. package/core/ledger/interfaces/VersionResponse.d.ts +6 -0
  94. package/core/ledger/interfaces/VersionResponse.d.ts.map +1 -0
  95. package/core/ledger/interfaces/VersionResponse.js +2 -0
  96. package/core/ledger/interfaces/index.d.ts +14 -0
  97. package/core/ledger/interfaces/index.d.ts.map +1 -0
  98. package/core/ledger/interfaces/index.js +29 -0
  99. package/core/ledger/ledger-comm.d.ts +85 -0
  100. package/core/ledger/ledger-comm.d.ts.map +1 -0
  101. package/core/ledger/ledger-comm.js +613 -0
  102. package/core/link/easyConnect.d.ts +23 -0
  103. package/core/link/easyConnect.d.ts.map +1 -0
  104. package/core/link/easyConnect.js +237 -0
  105. package/core/link/easyScript.d.ts +13 -0
  106. package/core/link/easyScript.d.ts.map +1 -0
  107. package/core/link/easyScript.js +52 -0
  108. package/core/link/index.d.ts +2 -0
  109. package/core/link/index.d.ts.map +1 -0
  110. package/core/link/index.js +17 -0
  111. package/core/link/interfaces/IAccount.d.ts +13 -0
  112. package/core/link/interfaces/IAccount.d.ts.map +1 -0
  113. package/core/link/interfaces/IAccount.js +2 -0
  114. package/core/link/interfaces/IFile.d.ts +7 -0
  115. package/core/link/interfaces/IFile.d.ts.map +1 -0
  116. package/core/link/interfaces/IFile.js +2 -0
  117. package/core/link/interfaces/ProofOfWork.d.ts +9 -0
  118. package/core/link/interfaces/ProofOfWork.d.ts.map +1 -0
  119. package/core/link/interfaces/ProofOfWork.js +12 -0
  120. package/core/link/interfaces/index.d.ts +4 -0
  121. package/core/link/interfaces/index.d.ts.map +1 -0
  122. package/core/link/interfaces/index.js +19 -0
  123. package/core/link/phantasmaLink.d.ts +41 -0
  124. package/core/link/phantasmaLink.d.ts.map +1 -0
  125. package/core/link/phantasmaLink.js +479 -0
  126. package/core/rpc/index.d.ts +3 -0
  127. package/core/rpc/index.d.ts.map +1 -0
  128. package/core/rpc/index.js +18 -0
  129. package/core/rpc/interfaces/ABIContract.d.ts +6 -0
  130. package/core/rpc/interfaces/ABIContract.d.ts.map +1 -0
  131. package/core/rpc/interfaces/ABIContract.js +2 -0
  132. package/core/rpc/interfaces/ABIEvent.d.ts +7 -0
  133. package/core/rpc/interfaces/ABIEvent.d.ts.map +1 -0
  134. package/core/rpc/interfaces/ABIEvent.js +2 -0
  135. package/core/rpc/interfaces/ABIMethod.d.ts +7 -0
  136. package/core/rpc/interfaces/ABIMethod.d.ts.map +1 -0
  137. package/core/rpc/interfaces/ABIMethod.js +2 -0
  138. package/core/rpc/interfaces/ABIParameter.d.ts +5 -0
  139. package/core/rpc/interfaces/ABIParameter.d.ts.map +1 -0
  140. package/core/rpc/interfaces/ABIParameter.js +2 -0
  141. package/core/rpc/interfaces/Account.d.ts +16 -0
  142. package/core/rpc/interfaces/Account.d.ts.map +1 -0
  143. package/core/rpc/interfaces/Account.js +2 -0
  144. package/core/rpc/interfaces/AccountTransactions.d.ts +6 -0
  145. package/core/rpc/interfaces/AccountTransactions.d.ts.map +1 -0
  146. package/core/rpc/interfaces/AccountTransactions.js +2 -0
  147. package/core/rpc/interfaces/Archive.d.ts +11 -0
  148. package/core/rpc/interfaces/Archive.d.ts.map +1 -0
  149. package/core/rpc/interfaces/Archive.js +2 -0
  150. package/core/rpc/interfaces/Auction.d.ts +13 -0
  151. package/core/rpc/interfaces/Auction.d.ts.map +1 -0
  152. package/core/rpc/interfaces/Auction.js +2 -0
  153. package/core/rpc/interfaces/Balance.d.ts +8 -0
  154. package/core/rpc/interfaces/Balance.d.ts.map +1 -0
  155. package/core/rpc/interfaces/Balance.js +2 -0
  156. package/core/rpc/interfaces/Block.d.ts +17 -0
  157. package/core/rpc/interfaces/Block.d.ts.map +1 -0
  158. package/core/rpc/interfaces/Block.js +2 -0
  159. package/core/rpc/interfaces/Chain.d.ts +10 -0
  160. package/core/rpc/interfaces/Chain.d.ts.map +1 -0
  161. package/core/rpc/interfaces/Chain.js +2 -0
  162. package/core/rpc/interfaces/Channel.d.ts +13 -0
  163. package/core/rpc/interfaces/Channel.d.ts.map +1 -0
  164. package/core/rpc/interfaces/Channel.js +2 -0
  165. package/core/rpc/interfaces/Contract.d.ts +11 -0
  166. package/core/rpc/interfaces/Contract.d.ts.map +1 -0
  167. package/core/rpc/interfaces/Contract.js +2 -0
  168. package/core/rpc/interfaces/Dapp.d.ts +6 -0
  169. package/core/rpc/interfaces/Dapp.d.ts.map +1 -0
  170. package/core/rpc/interfaces/Dapp.js +2 -0
  171. package/core/rpc/interfaces/Event.d.ts +7 -0
  172. package/core/rpc/interfaces/Event.d.ts.map +1 -0
  173. package/core/rpc/interfaces/Event.js +2 -0
  174. package/core/rpc/interfaces/Governance.d.ts +5 -0
  175. package/core/rpc/interfaces/Governance.d.ts.map +1 -0
  176. package/core/rpc/interfaces/Governance.js +2 -0
  177. package/core/rpc/interfaces/Interop.d.ts +5 -0
  178. package/core/rpc/interfaces/Interop.d.ts.map +1 -0
  179. package/core/rpc/interfaces/Interop.js +2 -0
  180. package/core/rpc/interfaces/KeyValue.d.ts +5 -0
  181. package/core/rpc/interfaces/KeyValue.d.ts.map +1 -0
  182. package/core/rpc/interfaces/KeyValue.js +2 -0
  183. package/core/rpc/interfaces/Leaderboard.d.ts +6 -0
  184. package/core/rpc/interfaces/Leaderboard.d.ts.map +1 -0
  185. package/core/rpc/interfaces/Leaderboard.js +2 -0
  186. package/core/rpc/interfaces/LeaderboardRow.d.ts +5 -0
  187. package/core/rpc/interfaces/LeaderboardRow.d.ts.map +1 -0
  188. package/core/rpc/interfaces/LeaderboardRow.js +2 -0
  189. package/core/rpc/interfaces/NFT.d.ts +14 -0
  190. package/core/rpc/interfaces/NFT.d.ts.map +1 -0
  191. package/core/rpc/interfaces/NFT.js +2 -0
  192. package/core/rpc/interfaces/Nexus.d.ts +14 -0
  193. package/core/rpc/interfaces/Nexus.d.ts.map +1 -0
  194. package/core/rpc/interfaces/Nexus.js +2 -0
  195. package/core/rpc/interfaces/Oracle.d.ts +5 -0
  196. package/core/rpc/interfaces/Oracle.d.ts.map +1 -0
  197. package/core/rpc/interfaces/Oracle.js +2 -0
  198. package/core/rpc/interfaces/Organization.d.ts +6 -0
  199. package/core/rpc/interfaces/Organization.d.ts.map +1 -0
  200. package/core/rpc/interfaces/Organization.js +2 -0
  201. package/core/rpc/interfaces/Paginated.d.ts +8 -0
  202. package/core/rpc/interfaces/Paginated.d.ts.map +1 -0
  203. package/core/rpc/interfaces/Paginated.js +2 -0
  204. package/core/rpc/interfaces/Peer.d.ts +8 -0
  205. package/core/rpc/interfaces/Peer.d.ts.map +1 -0
  206. package/core/rpc/interfaces/Peer.js +2 -0
  207. package/core/rpc/interfaces/Platform.d.ts +9 -0
  208. package/core/rpc/interfaces/Platform.d.ts.map +1 -0
  209. package/core/rpc/interfaces/Platform.js +2 -0
  210. package/core/rpc/interfaces/Receipt.d.ts +10 -0
  211. package/core/rpc/interfaces/Receipt.d.ts.map +1 -0
  212. package/core/rpc/interfaces/Receipt.js +2 -0
  213. package/core/rpc/interfaces/Script.d.ts +9 -0
  214. package/core/rpc/interfaces/Script.d.ts.map +1 -0
  215. package/core/rpc/interfaces/Script.js +2 -0
  216. package/core/rpc/interfaces/SendRawTx.d.ts +5 -0
  217. package/core/rpc/interfaces/SendRawTx.d.ts.map +1 -0
  218. package/core/rpc/interfaces/SendRawTx.js +2 -0
  219. package/core/rpc/interfaces/SignatureResult.d.ts +5 -0
  220. package/core/rpc/interfaces/SignatureResult.d.ts.map +1 -0
  221. package/core/rpc/interfaces/SignatureResult.js +2 -0
  222. package/core/rpc/interfaces/Stake.d.ts +6 -0
  223. package/core/rpc/interfaces/Stake.d.ts.map +1 -0
  224. package/core/rpc/interfaces/Stake.js +2 -0
  225. package/core/rpc/interfaces/Storage.d.ts +8 -0
  226. package/core/rpc/interfaces/Storage.d.ts.map +1 -0
  227. package/core/rpc/interfaces/Storage.js +2 -0
  228. package/core/rpc/interfaces/Swap.d.ts +13 -0
  229. package/core/rpc/interfaces/Swap.d.ts.map +1 -0
  230. package/core/rpc/interfaces/Swap.js +2 -0
  231. package/core/rpc/interfaces/Token.d.ts +19 -0
  232. package/core/rpc/interfaces/Token.d.ts.map +1 -0
  233. package/core/rpc/interfaces/Token.js +2 -0
  234. package/core/rpc/interfaces/TokenData.d.ts +13 -0
  235. package/core/rpc/interfaces/TokenData.d.ts.map +1 -0
  236. package/core/rpc/interfaces/TokenData.js +2 -0
  237. package/core/rpc/interfaces/TokenExternal.d.ts +5 -0
  238. package/core/rpc/interfaces/TokenExternal.d.ts.map +1 -0
  239. package/core/rpc/interfaces/TokenExternal.js +2 -0
  240. package/core/rpc/interfaces/TokenPrice.d.ts +8 -0
  241. package/core/rpc/interfaces/TokenPrice.d.ts.map +1 -0
  242. package/core/rpc/interfaces/TokenPrice.js +2 -0
  243. package/core/rpc/interfaces/TokenSeries.d.ts +12 -0
  244. package/core/rpc/interfaces/TokenSeries.d.ts.map +1 -0
  245. package/core/rpc/interfaces/TokenSeries.js +2 -0
  246. package/core/rpc/interfaces/TransactionData.d.ts +23 -0
  247. package/core/rpc/interfaces/TransactionData.d.ts.map +1 -0
  248. package/core/rpc/interfaces/TransactionData.js +2 -0
  249. package/core/rpc/interfaces/Validator.d.ts +5 -0
  250. package/core/rpc/interfaces/Validator.d.ts.map +1 -0
  251. package/core/rpc/interfaces/Validator.js +2 -0
  252. package/core/rpc/interfaces/index.d.ts +42 -0
  253. package/core/rpc/interfaces/index.d.ts.map +1 -0
  254. package/core/rpc/interfaces/index.js +57 -0
  255. package/core/rpc/phantasma.d.ts +89 -0
  256. package/core/rpc/phantasma.d.ts.map +1 -0
  257. package/core/rpc/phantasma.js +900 -0
  258. package/core/tx/SignatureKind.js +9 -0
  259. package/core/tx/Transaction.d.ts +28 -0
  260. package/core/tx/Transaction.d.ts.map +1 -0
  261. package/core/tx/Transaction.js +209 -0
  262. package/core/tx/index.d.ts +3 -0
  263. package/core/tx/index.d.ts.map +1 -0
  264. package/core/tx/index.js +18 -0
  265. package/core/tx/utils.d.ts +10 -0
  266. package/core/tx/utils.d.ts.map +1 -0
  267. package/core/tx/utils.js +147 -0
  268. package/core/types/Address.d.ts +41 -0
  269. package/core/types/Address.d.ts.map +1 -0
  270. package/core/types/Address.js +276 -0
  271. package/core/types/Consensus.d.ts +61 -0
  272. package/core/types/Consensus.d.ts.map +1 -0
  273. package/core/types/Consensus.js +151 -0
  274. package/core/types/Contract.d.ts +60 -0
  275. package/core/types/Contract.d.ts.map +1 -0
  276. package/core/types/Contract.js +342 -0
  277. package/core/types/DomainSettings.d.ts +87 -0
  278. package/core/types/DomainSettings.d.ts.map +1 -0
  279. package/core/types/DomainSettings.js +107 -0
  280. package/core/types/Ed25519Signature.d.ts +16 -0
  281. package/core/types/Ed25519Signature.d.ts.map +1 -0
  282. package/core/types/Ed25519Signature.js +78 -0
  283. package/core/types/Entropy.d.ts +5 -0
  284. package/core/types/Entropy.d.ts.map +1 -0
  285. package/core/types/Entropy.js +24 -0
  286. package/core/types/Extensions/Base16.d.ts +7 -0
  287. package/core/types/Extensions/Base16.d.ts.map +1 -0
  288. package/core/types/Extensions/Base16.js +36 -0
  289. package/core/types/Extensions/BinaryReader.d.ts +17 -0
  290. package/core/types/Extensions/BinaryReader.d.ts.map +1 -0
  291. package/core/types/Extensions/BinaryReader.js +192 -0
  292. package/core/types/Extensions/BinaryWriter.d.ts +25 -0
  293. package/core/types/Extensions/BinaryWriter.d.ts.map +1 -0
  294. package/core/types/Extensions/BinaryWriter.js +191 -0
  295. package/core/types/Extensions/Describer.d.ts +5 -0
  296. package/core/types/Extensions/Describer.d.ts.map +1 -0
  297. package/core/types/Extensions/Describer.js +25 -0
  298. package/core/types/Extensions/PBinaryReader.d.ts +42 -0
  299. package/core/types/Extensions/PBinaryReader.d.ts.map +1 -0
  300. package/core/types/Extensions/PBinaryReader.js +269 -0
  301. package/core/types/Extensions/PBinaryWriter.d.ts +49 -0
  302. package/core/types/Extensions/PBinaryWriter.d.ts.map +1 -0
  303. package/core/types/Extensions/PBinaryWriter.js +250 -0
  304. package/core/types/Extensions/TableColumns.d.ts +5 -0
  305. package/core/types/Extensions/TableColumns.d.ts.map +1 -0
  306. package/core/types/Extensions/TableColumns.js +22 -0
  307. package/core/types/Extensions/index.d.ts +5 -0
  308. package/core/types/Extensions/index.d.ts.map +1 -0
  309. package/core/types/Extensions/index.js +20 -0
  310. package/core/types/PhantasmaKeys.d.ts +19 -0
  311. package/core/types/PhantasmaKeys.d.ts.map +1 -0
  312. package/core/types/PhantasmaKeys.js +92 -0
  313. package/core/types/Serialization.d.ts +22 -0
  314. package/core/types/Serialization.d.ts.map +1 -0
  315. package/core/types/Serialization.js +195 -0
  316. package/core/types/Stack.d.ts +16 -0
  317. package/core/types/Stack.d.ts.map +1 -0
  318. package/core/types/Stack.js +42 -0
  319. package/core/types/Timestamp.d.ts +26 -0
  320. package/core/types/Timestamp.d.ts.map +1 -0
  321. package/core/types/Timestamp.js +74 -0
  322. package/core/types/index.d.ts +12 -0
  323. package/core/types/index.d.ts.map +1 -0
  324. package/core/types/index.js +27 -0
  325. package/core/utils/index.d.ts +25 -0
  326. package/core/utils/index.d.ts.map +1 -0
  327. package/core/utils/index.js +236 -0
  328. package/core/vm/Contracts.d.ts +17 -0
  329. package/core/vm/Contracts.d.ts.map +1 -0
  330. package/core/vm/Contracts.js +20 -0
  331. package/core/vm/Decoder.d.ts +19 -0
  332. package/core/vm/Decoder.d.ts.map +1 -0
  333. package/core/vm/Decoder.js +175 -0
  334. package/core/vm/EventData.d.ts +97 -0
  335. package/core/vm/EventData.d.ts.map +1 -0
  336. package/core/vm/EventData.js +134 -0
  337. package/core/vm/Opcode.d.ts +57 -0
  338. package/core/vm/Opcode.d.ts.map +1 -0
  339. package/core/vm/Opcode.js +69 -0
  340. package/core/vm/ScriptBuilder.d.ts +65 -0
  341. package/core/vm/ScriptBuilder.d.ts.map +1 -0
  342. package/core/vm/ScriptBuilder.js +592 -0
  343. package/core/vm/VMObject.d.ts +55 -0
  344. package/core/vm/VMObject.d.ts.map +1 -0
  345. package/core/vm/VMObject.js +1101 -0
  346. package/core/vm/VMType.d.ts +12 -0
  347. package/core/vm/VMType.d.ts.map +1 -0
  348. package/core/vm/VMType.js +15 -0
  349. package/core/vm/index.d.ts +8 -0
  350. package/core/vm/index.d.ts.map +1 -0
  351. package/core/vm/index.js +23 -0
  352. package/html/TestWebPage.html +187 -0
  353. package/html/phantasma.js +60504 -0
  354. package/index.d.ts +5 -0
  355. package/index.d.ts.map +1 -0
  356. package/index.js +36 -0
  357. package/jest.config.js +5 -0
  358. package/package.json +67 -0
  359. package/src/core/index.ts +9 -0
  360. package/src/core/interfaces/IContract.ts +28 -0
  361. package/src/core/interfaces/IKeyPair.ts +14 -0
  362. package/src/core/interfaces/ISerializable.ts +6 -0
  363. package/src/core/interfaces/IStack.ts +6 -0
  364. package/src/core/interfaces/IToken.ts +31 -0
  365. package/src/core/interfaces/Signature.ts +32 -0
  366. package/src/core/interfaces/index.ts +6 -0
  367. package/src/core/ledger/Address-Transcode.ts +44 -0
  368. package/src/core/ledger/Ledger-Commands.ts +463 -0
  369. package/src/core/ledger/Ledger-Utils.ts +549 -0
  370. package/src/core/ledger/Mnemonic.ts +79 -0
  371. package/src/core/ledger/Transaction-Sign.ts +126 -0
  372. package/src/core/ledger/Transaction-Transcode.ts +56 -0
  373. package/src/core/ledger/index.ts +8 -0
  374. package/src/core/ledger/interfaces/ApplicationNameResponse.ts +5 -0
  375. package/src/core/ledger/interfaces/Device.ts +6 -0
  376. package/src/core/ledger/interfaces/DeviceResponse.ts +6 -0
  377. package/src/core/ledger/interfaces/Ledger.ts +10 -0
  378. package/src/core/ledger/interfaces/LedgerBalanceFromLedgerResponse.ts +9 -0
  379. package/src/core/ledger/interfaces/LedgerConfig.ts +17 -0
  380. package/src/core/ledger/interfaces/LedgerDeviceInfoResponse.ts +7 -0
  381. package/src/core/ledger/interfaces/LedgerSendTransactionResponse.ts +4 -0
  382. package/src/core/ledger/interfaces/LedgerSigner.ts +6 -0
  383. package/src/core/ledger/interfaces/LedgerSignerData.ts +8 -0
  384. package/src/core/ledger/interfaces/PublicKeyResponse.ts +5 -0
  385. package/src/core/ledger/interfaces/SignResponse.ts +5 -0
  386. package/src/core/ledger/interfaces/VersionResponse.ts +5 -0
  387. package/src/core/ledger/interfaces/index.ts +13 -0
  388. package/src/core/link/easyConnect.ts +214 -0
  389. package/src/core/link/easyScript.ts +67 -0
  390. package/src/core/link/index.ts +1 -0
  391. package/src/core/link/interfaces/IAccount.ts +13 -0
  392. package/src/core/link/interfaces/IFile.ts +6 -0
  393. package/src/core/link/interfaces/ProofOfWork.ts +8 -0
  394. package/src/core/link/interfaces/index.ts +3 -0
  395. package/src/core/link/phantasmaLink.ts +561 -0
  396. package/src/core/rpc/index.ts +2 -0
  397. package/src/core/rpc/interfaces/ABIContract.ts +6 -0
  398. package/src/core/rpc/interfaces/ABIEvent.ts +6 -0
  399. package/src/core/rpc/interfaces/ABIMethod.ts +7 -0
  400. package/src/core/rpc/interfaces/ABIParameter.ts +4 -0
  401. package/src/core/rpc/interfaces/Account.ts +16 -0
  402. package/src/core/rpc/interfaces/AccountTransactions.ts +6 -0
  403. package/src/core/rpc/interfaces/Archive.ts +10 -0
  404. package/src/core/rpc/interfaces/Auction.ts +12 -0
  405. package/src/core/rpc/interfaces/Balance.ts +7 -0
  406. package/src/core/rpc/interfaces/Block.ts +17 -0
  407. package/src/core/rpc/interfaces/Chain.ts +9 -0
  408. package/src/core/rpc/interfaces/Channel.ts +12 -0
  409. package/src/core/rpc/interfaces/Contract.ts +11 -0
  410. package/src/core/rpc/interfaces/Dapp.ts +5 -0
  411. package/src/core/rpc/interfaces/Event.ts +6 -0
  412. package/src/core/rpc/interfaces/Governance.ts +4 -0
  413. package/src/core/rpc/interfaces/Interop.ts +4 -0
  414. package/src/core/rpc/interfaces/KeyValue.ts +4 -0
  415. package/src/core/rpc/interfaces/Leaderboard.ts +6 -0
  416. package/src/core/rpc/interfaces/LeaderboardRow.ts +4 -0
  417. package/src/core/rpc/interfaces/NFT.ts +14 -0
  418. package/src/core/rpc/interfaces/Nexus.ts +14 -0
  419. package/src/core/rpc/interfaces/Oracle.ts +4 -0
  420. package/src/core/rpc/interfaces/Organization.ts +5 -0
  421. package/src/core/rpc/interfaces/Paginated.ts +7 -0
  422. package/src/core/rpc/interfaces/Peer.ts +7 -0
  423. package/src/core/rpc/interfaces/Platform.ts +9 -0
  424. package/src/core/rpc/interfaces/Receipt.ts +9 -0
  425. package/src/core/rpc/interfaces/Script.ts +9 -0
  426. package/src/core/rpc/interfaces/SendRawTx.ts +4 -0
  427. package/src/core/rpc/interfaces/SignatureResult.ts +4 -0
  428. package/src/core/rpc/interfaces/Stake.ts +5 -0
  429. package/src/core/rpc/interfaces/Storage.ts +8 -0
  430. package/src/core/rpc/interfaces/Swap.ts +12 -0
  431. package/src/core/rpc/interfaces/Token.ts +19 -0
  432. package/src/core/rpc/interfaces/TokenData.ts +12 -0
  433. package/src/core/rpc/interfaces/TokenExternal.ts +4 -0
  434. package/src/core/rpc/interfaces/TokenPrice.ts +7 -0
  435. package/src/core/rpc/interfaces/TokenSeries.ts +12 -0
  436. package/src/core/rpc/interfaces/TransactionData.ts +23 -0
  437. package/src/core/rpc/interfaces/Validator.ts +4 -0
  438. package/src/core/rpc/interfaces/index.ts +41 -0
  439. package/src/core/rpc/phantasma.ts +466 -0
  440. package/src/core/tx/Transaction.ts +258 -0
  441. package/src/core/tx/index.ts +2 -0
  442. package/src/core/tx/utils.ts +106 -0
  443. package/src/core/types/Address.ts +290 -0
  444. package/src/core/types/Consensus.ts +181 -0
  445. package/src/core/types/Contract.ts +324 -0
  446. package/src/core/types/DomainSettings.ts +128 -0
  447. package/src/core/types/Ed25519Signature.ts +78 -0
  448. package/src/core/types/Entropy.ts +16 -0
  449. package/src/core/types/Extensions/Base16.ts +36 -0
  450. package/src/core/types/Extensions/Describer.ts +17 -0
  451. package/src/core/types/Extensions/PBinaryReader.ts +247 -0
  452. package/src/core/types/Extensions/PBinaryWriter.ts +278 -0
  453. package/src/core/types/Extensions/index.ts +4 -0
  454. package/src/core/types/PhantasmaKeys.ts +119 -0
  455. package/src/core/types/Serialization.ts +211 -0
  456. package/src/core/types/Stack.ts +46 -0
  457. package/src/core/types/Timestamp.ts +93 -0
  458. package/src/core/types/index.ts +11 -0
  459. package/src/core/utils/index.ts +206 -0
  460. package/src/core/vm/Contracts.ts +17 -0
  461. package/src/core/vm/Decoder.ts +162 -0
  462. package/src/core/vm/Disassembler.ts +1 -0
  463. package/src/core/vm/EventData.ts +135 -0
  464. package/src/core/vm/Opcode.ts +74 -0
  465. package/src/core/vm/ScriptBuilder.ts +588 -0
  466. package/src/core/vm/VMObject.ts +1162 -0
  467. package/src/core/vm/VMType.ts +11 -0
  468. package/src/core/vm/index.ts +7 -0
  469. package/src/core/vm/utils/DisasmMethodCall.ts +22 -0
  470. package/src/core/vm/utils/DisasmUtils.ts +89 -0
  471. package/src/core/vm/utils/index.ts +2 -0
  472. package/src/index.ts +7 -0
  473. package/tests/VMObject.test.ts +146 -0
  474. package/tests/ledger/Address-Transacode.test.ts +26 -0
  475. package/tests/tx/Transaction.test.ts +274 -0
  476. package/tests/types/Address.test.ts +26 -0
  477. package/tests/types/Consensus.test.ts +67 -0
  478. package/tsconfig.json +29 -0
package/README.md ADDED
@@ -0,0 +1,842 @@
1
+ # phantasma-ts
2
+
3
+ A TypeScript SDK for the Phantasma blockchain.
4
+
5
+ ## Installation
6
+
7
+ Use the package manager [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install phatasma-ts.
8
+
9
+ ```bash
10
+ npm install phantasma-ts
11
+ ```
12
+
13
+ ## Importing
14
+
15
+ ```javascript
16
+ const { PhantasmaTS } = require("phantasma-ts");
17
+ ```
18
+
19
+ ## Standalone HTML Import
20
+
21
+ ```html
22
+ <script src="https://cdn.jsdelivr.net/gh/phantasma-io/phantasma-ts/html/phantasma.js"></script>
23
+ ```
24
+
25
+ ```javascript
26
+ phantasma.PhantasmaTS; // To use PhantasmaTS
27
+ phantasma.PhantasmaLink; // To use PhantasmaLink
28
+ phantasma.EasyConnect; // To use EasyConnect, an easy to use PhantasmaLink wrapper
29
+ ```
30
+
31
+ ## Table Of Contents
32
+
33
+ The Phantasma TypeScript SDK transpiles into PhantasmaTS, PhantasmaLink and EasyConnect.
34
+
35
+ 1. [PhantasmaTS](#phantasmats) - Allows you to interact with the Phantasma Blockchain
36
+
37
+ - [Utility Functions](#phantasmats-utility-functions)
38
+ - [Script Builder](#building-a-script-with-script-builder)
39
+ - [Interop Commands](#interop-functions)
40
+ - [Building Transaction](#building-a-transaction)
41
+ - [Deploying Smart Contract](#deploying-a-contract)
42
+ - [RPC](#using-rpc)
43
+
44
+ 2. [PhantasmaLink](#phantasmalink) - Allows you to interact with Phantasma based wallets
45
+ - [Functions](#functions)
46
+ - [Examples](#example-code)
47
+
48
+ 3. [EasyConnect](#easyconnect) - Easy plug and play solution for creating DApps
49
+
50
+ - [Core Functions](#core-functions)
51
+ - [Query Function](#query-function)
52
+ - [Action Function](#action-function)
53
+ - [Easy Script](#easy-script-create)
54
+
55
+ 4. [Misc]
56
+ - [Vocab](#vocab)
57
+
58
+ ---
59
+
60
+ ## PhantasmaTS
61
+
62
+ Use PhantasmaTS to interact with the Phantasma blockchain directly.
63
+
64
+ ### PhantasmaTS Utility Functions
65
+
66
+ Just some standard useful functions that you probably will end up using at some point.
67
+
68
+ ```javascript
69
+ PhantasmaTS.byteArrayToHex(arr: ArrayBuffer | ArrayLike<number>); //Turns a Byte Array into Serialized Hex
70
+ ```
71
+
72
+ ```javascript
73
+ PhantasmaTS.getAddressFromWif(wif: string); //Get's Public Address from WIF (Wallet Import Format)
74
+ ```
75
+
76
+ ```javascript
77
+ PhantasmaTS.getPrivateKeyFromWif(wif: string); //Get's Private Key from WIF (Wallet Import Format)
78
+ ```
79
+
80
+ ```javascript
81
+ PhantasmaTS.hexToByteArray(hexBytes: string); //Turns Serialized Hex into Byte Array
82
+ ```
83
+
84
+ ```javascript
85
+ PhantasmaTS.reverseHex(hex: string); //Reverse <-> esreveR Serialized Hex
86
+ ```
87
+
88
+ ```javascript
89
+ PhantasmaTS.signData(msgHex: string, privateKey: string); //Signs some text with given Private Key
90
+ ```
91
+
92
+ ### Building a Script with Script Builder
93
+
94
+ Building a script is the most important part of interacting with the Phantasma blockchain. Without a propper script, the Phantasma blockchain will not know what you are trying to do.
95
+
96
+ These functions, `.CallContract` and `.CallInterop`, are your bread and butter for creating new scripts.
97
+
98
+ ` .CallContract(contractName: string, methodName: string, [arguments]: array)`
99
+
100
+ ` .CallInterop(functionName: string, [arguments]: array)`
101
+
102
+ - You can find out all the diffrent `.CallInterop` functions below.
103
+
104
+ - For `.CallContract`, you will have to look through the ABI's of all the diffrent smart contracts currently deployed on the Phantasma 'mainnet': [Link Here](https://explorer.phantasma.io/chain/main#tab_contracts)
105
+
106
+ #### Example:
107
+
108
+ ```javascript
109
+ //Creating a new Script Builder Object
110
+ let sb = new PhantasmaTS.ScriptBuilder();
111
+
112
+ //Here is an example of a Transactional Script
113
+ sb
114
+ .AllowGas(fromAddress, sb.NullAddress, gasPrice, gasLimit)
115
+ .CallInterop("Runtime.TransferTokens", ['fromAddress', 'toAddress', 'KCAL', 10000000000]) //10000000000 = 1 KCAL
116
+ .SpendGas(fromAddress)
117
+ .EndScript();
118
+
119
+ --- OR ----
120
+
121
+ //Here is an example of a non Transactional Script
122
+
123
+ sb
124
+ .CallContract('account', 'LookUpName', ['accountName'])
125
+ .EndScript();
126
+
127
+ ```
128
+ #### InvokeRawScript and decoding the result
129
+ ```javascript
130
+
131
+ let sb = new PhantasmaTS.ScriptBuilder();
132
+ sb.CallContract("stake", "GetMasterCount", []);
133
+ let script = sb.EndScript();
134
+ let targetNet = 'main';
135
+
136
+ // NOTE - we assume RPC was instantiated previously already, check other samples to see how
137
+ let response = await RPC.invokeRawScript(targetNet, script);
138
+
139
+ const decoder = new PhantasmaTS.Decoder(response.result);
140
+ const value = decoder.readVmObject();
141
+ console.log(value); // print the decoded value to the console
142
+
143
+ ```
144
+
145
+ #### Interop Functions:
146
+
147
+ Here are some Interop functions that are used to interact with the core functionality of the Phantasma blockchain. Use these inside your script to add extra functionality.
148
+
149
+ ```javascript
150
+ sb.CallInterop("Runtime.MintTokens", [from: string, target: string, tokenSymbol: string , amount: number]); //Used for Fungible Tokens
151
+ ```
152
+
153
+ ```javascript
154
+ sb.CallInterop("Runtime.TransferTokens", [from: string, to: string, tokenSymbol: string, amount: number]); //Used for Fungible Tokens
155
+ ```
156
+
157
+ ```javascript
158
+ sb.CallInterop("Runtime.TransferBalance", [from: string, to: string, tokenSymbol: string]);
159
+ ```
160
+
161
+ ```javascript
162
+ sb.CallInterop("Runtime.TransferToken", [from: string, to: string, tokenSymbol: string, tokenId: number]); //Used for Non Fungible Tokens
163
+ ```
164
+
165
+ ```javascript
166
+ sb.CallInterop("Runtime.SendTokens", [destinationChain: string, from: string, to: string, tokenSymbol: string, amount: number); //Used for Fungible Tokens
167
+ ```
168
+
169
+ ```javascript
170
+ sb.CallInterop("Runtime.SendToken", [destinationChain: string, from: string, to: string, tokenSymbol: string, tokenId: number]); //Used for Non Fungible Tokens
171
+ ```
172
+
173
+ ```javascript
174
+ sb.CallInterop("Runtime.DeployContract", [from: string, contractName: string, pvm: hexString, abi: hexString]);
175
+ ```
176
+
177
+ ### Building a Transaction
178
+
179
+ To build a transaction you will first need to build a script.
180
+
181
+ Note, building a Transaction is for transactional scripts only. Non transactional scripts should use the RPC function `RPC.invokeRawScript(chainInput: string, scriptData: string)`
182
+
183
+ ```javascript
184
+ const { PhantasmaTS } = require("phantasma-ts");
185
+
186
+
187
+ async function sendTransaction() {
188
+
189
+ let WIF = "WIF"; //In WIF Format
190
+ let fromAddress = "yourPublicWalletAddress";
191
+ let toAddress = "addressYoureSendingTo";
192
+
193
+ //Creating RPC Connection **(Needs To Be Updated)
194
+ let RPC = new PhantasmaTS.PhantasmaAPI(
195
+ "http://localhost:7077/rpc",
196
+ null,
197
+ "simnet"
198
+ );
199
+
200
+ //set Gas parameters for Runtime.TransferTokens
201
+ let gasPrice = PhantasmaTS.DomainSettings.DefaultMinimumGasFee; //Internal Blockchain minimum gas fee needed - i.e 100000
202
+ let gasLimit = 9999;
203
+
204
+ //Creating a new Script Builder Object
205
+ let sb = new PhantasmaTS.ScriptBuilder();
206
+
207
+ //Making a Script
208
+ let script = sb
209
+ .BeginScript()
210
+ .AllowGas(fromAddress, sb.NullAddress, gasPrice, gasLimit)
211
+ .CallInterop("Runtime.TransferTokens", [
212
+ fromAddress,
213
+ toAddress,
214
+ "SOUL",
215
+ 100000000,
216
+ ]) //100000000 = 1 SOUL
217
+ .SpendGas(fromAddress)
218
+ .EndScript();
219
+
220
+ //Used to set expiration date
221
+ let expiration = 5; //This is in miniutes
222
+ let getTime = new Date();
223
+ let expiration_date = new Date(getTime.getTime() + expiration * 60000);
224
+
225
+ let payload = PhantasmaTS.Base16.encode("Phantasma-ts"); //Says '7068616e7461736d612d7473' in hex
226
+
227
+ //Creating New Transaction Object
228
+ let transaction = new PhantasmaTS.Transaction(
229
+ "simnet", //Nexus Name - if you're using mainnet change it to mainnet or simnet if you're using you localnode
230
+ "main", //Chain
231
+ script, //In string format
232
+ expiration_date, //Date Object
233
+ payload //Extra Info to attach to Transaction in Serialized Hex
234
+ );
235
+
236
+ //Sign's Transaction with WIF
237
+ transaction.sign(WIF);
238
+ let hexEncodedTx = transaction.ToStringEncoded(true); //converts trasnaction to base16 string -true means transaction is signed-
239
+
240
+ //Send Transaction
241
+ let txHash = await RPC.sendRawTransaction(hexEncodedTx);
242
+ //Return Transaction Hash
243
+ return txHash;
244
+ }
245
+
246
+ ```
247
+ ### Staking SOUL
248
+
249
+ This is an example how to stake SOUL
250
+
251
+ ```javascript
252
+ async function stakeSOUL() {
253
+ let WIF = "WIF"; //WIF format
254
+
255
+ let fromAddress = "yourPublicWalletAddress"; // Phantasma Public Address
256
+
257
+ //Creating a new Script Builder Object
258
+ let sb = new PhantasmaTS.ScriptBuilder();
259
+ let gasPrice = PhantasmaTS.DomainSettings.DefaultMinimumGasFee; //Internal Blockchain minimum gas fee needed - i.e 100000
260
+ let gasLimit = 21000;
261
+ let amount = String(10 * 10 ** 8); // 100 the amount - 10**8 it's to get the decimals to the desired amount
262
+ // Soul has 8 decimals places.
263
+
264
+ //Creating RPC Connection **(Needs To Be Updated)
265
+ let RPC = new PhantasmaTS.PhantasmaAPI(
266
+ "http://localhost:7077/rpc",
267
+ null,
268
+ "simnet"
269
+ );
270
+
271
+ //Making a Script
272
+ let script = sb
273
+ .AllowGas(fromAddress, sb.NullAddress, gasPrice, gasLimit)
274
+ .CallContract("stake", "Stake", [fromAddress, amount])
275
+ .SpendGas(fromAddress)
276
+ .EndScript();
277
+
278
+ //Used to set expiration date
279
+ let expiration = 5; //This is in miniutes
280
+ let getTime = new Date();
281
+ let expiration_date = new Date(getTime.getTime() + expiration * 60000);
282
+
283
+ let payload = "7068616e7461736d612d7473"; //Says 'Phantasma-ts' in hex
284
+
285
+ //Creating New Transaction Object
286
+ let transaction = new PhantasmaTS.Transaction(
287
+ "simnet", //Nexus Name - if you're using mainnet change it to mainnet
288
+ "main", //Chain
289
+ script, //In string format
290
+ expiration_date, //Date Object
291
+ payload //Extra Info to attach to Transaction in Serialized Hex
292
+ );
293
+
294
+ //Sign's Transaction with WIF
295
+ transaction.sign(WIF);
296
+
297
+ let hexEncodedTx = transaction.ToStringEncoded(true);
298
+
299
+ //Send Transaction
300
+ let txHash = await RPC.sendRawTransaction(hexEncodedTx);
301
+
302
+ //Return Transaction Hash
303
+ return txHash;
304
+ }
305
+ ```
306
+
307
+ ### Deploying a Contract
308
+
309
+ ```javascript
310
+ async function deployContract() {
311
+ //Wallet Stuff
312
+ let WIF = "WIF"; //In wif Format
313
+ let fromAddress = "yourPublicWalletAddress";
314
+
315
+ //Contract Stuff
316
+ let pvm = "PVM HEX String";
317
+ let abi = "ABI HEX String";
318
+
319
+ //convert Pvm to Bytes -> uint8Array
320
+ let pvm_byteArr = PhantasmaTS.hexToByteArray(pvm);
321
+ pvm_byteArr.shift();
322
+ let byte_pvm = new Uint8Array(pvm_byteArr);
323
+
324
+ //convert abi to Bytes -> uint8Array
325
+ let abi_byteArr = PhantasmaTS.hexToByteArray(abi);
326
+ abi_byteArr.shift();
327
+ let byte_abi = new Uint8Array(abi_byteArr);
328
+
329
+ let gasPrice = PhantasmaTS.DomainSettings.DefaultMinimumGasFee; //Internal Blockchain minimum gas fee needed - i.e 100000
330
+ let gasLimit = 21000;
331
+ let contractName = "contractName"; //Whatever you want
332
+
333
+ //Creating a new Script Builder Object
334
+ let sb = new PhantasmaTS.ScriptBuilder();
335
+
336
+ //New RPC and Peers Needed
337
+ //Creating RPC Connection, use ('http://testnet.phantasma.io:5101/rpc', null, 'testnet') for testing
338
+ let RPC = new PhantasmaTS.PhantasmaAPI(
339
+ "http://localhost:7077/rpc",
340
+ null,
341
+ "simnet"
342
+ );
343
+
344
+ //Making a Script
345
+ let script = sb
346
+ .AllowGas(fromAddress, sb.NullAddress, gasPrice, gasLimit)
347
+ .CallInterop("Runtime.DeployContract", [
348
+ fromAddress,
349
+ contractName,
350
+ byte_pvm,
351
+ byte_abi,
352
+ ])
353
+ .SpendGas(fromAddress)
354
+ .EndScript();
355
+
356
+ //Used to set expiration date
357
+ let expiration = 5; //This is in miniutes
358
+ let getTime = new Date();
359
+ let expiration_date = new Date(getTime.getTime() + expiration * 60000);
360
+
361
+ //Setting Temp Payload
362
+ let payload = "MyApp";
363
+
364
+ //Creating New Transaction Object
365
+ let transaction = new PhantasmaTS.Transaction(
366
+ "simnet", //Nexus Name
367
+ "main", //Chain
368
+ script, //In string format
369
+ expiration_date, //Date Object
370
+ payload //Extra Info to attach to Transaction in Serialized Hex
371
+ );
372
+
373
+ //Deploying Contract Requires POW -- Use a value of 5 to increase the hash difficulty by at least 5
374
+ transaction.mineTransaction(5);
375
+
376
+ //Signs Transaction with your WIF
377
+ transaction.sign(WIF);
378
+
379
+ let hexEncodedTx = transaction.ToStringEncoded(true);
380
+
381
+ //Sends Transaction
382
+ let txHash = await RPC.sendRawTransaction(hexEncodedTx);
383
+
384
+ //Returns Transaction Hash
385
+ return txHash;
386
+ }
387
+ ```
388
+
389
+ ### Scanning the blockchain for incoming transactions
390
+
391
+ ```javascript
392
+ const { PhantasmaTS } = require("phantasma-ts");
393
+
394
+ let RPC = new PhantasmaTS.PhantasmaAPI(
395
+ "http://pharpc1.phantasma.io:7077/rpc",
396
+ null,
397
+ "mainnet"
398
+ );
399
+
400
+ // Store the current height of the chain
401
+ let currentHeight = 1;
402
+
403
+ let chainName = "main";
404
+
405
+ function onTransactionReceived(address, symbol, amount) {}
406
+
407
+ // Function that periodically checks the height of the chain and fetches the latest block if the height has increased
408
+ async function checkForNewBlocks() {
409
+ // Get the current height of the chain
410
+ let newHeight = await RPC.getBlockHeight(chainName);
411
+
412
+ // Check if the height has increased
413
+ if (newHeight > currentHeight) {
414
+ // Fetch the latest block
415
+ let latestBlock = await RPC.getBlockByHeight(chainName, newHeight);
416
+
417
+ // Check all transactions in this block
418
+ for (i = 0; i < latestBlock.txs.length; i++) {
419
+ let tx = latestBlock.txs[i];
420
+
421
+ // Check all events in this transaction
422
+ for (j = 0; j < tx.events.length; j++) {
423
+ let evt = tx.events[j];
424
+ if (evt.kind == "TokenReceive") {
425
+ var data = PhantasmaTS.getTokenEventData(evt.data);
426
+ onTransactionReceived(evt.address, data.symbol, data.value);
427
+ }
428
+ }
429
+ }
430
+
431
+ // Update the current height of the chain
432
+ currentHeight = newHeight;
433
+ }
434
+
435
+ // Repeat this process after a delay
436
+ setTimeout(checkForNewBlocks, 1000);
437
+ }
438
+
439
+ // Start checking for new blocks
440
+ checkForNewBlocks();
441
+ ```
442
+
443
+ ### Using RPC
444
+
445
+ ```javascript
446
+ let RPC = new PhantasmaTS.PhantasmaAPI(
447
+ "http://pharpc1.phantasma.io:7077/rpc",
448
+ null,
449
+ "mainnet"
450
+ );
451
+ ```
452
+
453
+ #### Utillities:
454
+
455
+ - `RPC.JSONRPC(method: string, params: Array<any>);` <- Used to make any Phantasma RPC call
456
+ - ` RPC.updateRpc()`
457
+ - ` RPC.setRpcHost(rpcHost: string)`
458
+ - ` RPC.setRpcByName(rpcName: string)`
459
+ - ` RPC.setNexus(nexus: string)`
460
+ - ` RPC.convertDecimals(amount: number, decimals: number)`
461
+
462
+ #### All RPC Function Calls:
463
+
464
+ ```javascript
465
+ await RPC.getAccount(account: string); //Returns the account name and balance of given address.
466
+ ```
467
+
468
+ ```javascript
469
+ await RPC.lookUpName(name: string); //Returns the address that owns a given name.
470
+ ```
471
+
472
+ ```javascript
473
+ await RPC.getBlockHeight(chainInput: string); //Returns the height of a chain.
474
+ ```
475
+
476
+ ```javascript
477
+ await RPC.getBlockTransactionCountByHash(blockHash: string); //Returns the number of transactions of given block hash or error if given hash is invalid or is not found.
478
+ ```
479
+
480
+ ```javascript
481
+ await RPC.getBlockByHash(blockHash: string); //Returns information about a block by hash.
482
+ ```
483
+
484
+ ```javascript
485
+ await RPC.getRawBlockByHash(blockHash: string); //Returns a serialized string, containing information about a block by hash.
486
+ ```
487
+
488
+ ```javascript
489
+ await RPC.getBlockByHeight(chainInput: string, height: number); //Returns information about a block by height and chain.
490
+ ```
491
+
492
+ ```javascript
493
+ await RPC.getRawBlockByHeight(chainInput: string, height: number); //Returns a serialized string, in hex format, containing information about a block by height and chain.
494
+ ```
495
+
496
+ ```javascript
497
+ await RPC.getTransactionByBlockHashAndIndex(blockHash: string, index: number); //Returns the information about a transaction requested by a block hash and transaction index.
498
+ ```
499
+
500
+ ```javascript
501
+ await RPC.getAddressTransactions(account: string, page: number, pageSize: number); //Returns last X transactions of given address.
502
+ ```
503
+
504
+ ```javascript
505
+ await RPC.getAddressTransactionCount(account: string, chainInput: string); //Get number of transactions in a specific address and chain.
506
+ ```
507
+
508
+ ```javascript
509
+ await RPC.sendRawTransaction(txData: string); //Allows to broadcast a signed operation on the network, but it&apos;s required to build it manually.
510
+ ```
511
+
512
+ ```javascript
513
+ await RPC.invokeRawScript(chainInput: string, scriptData: string); //Allows to invoke script based on network state, without state changes.
514
+ ```
515
+
516
+ ```javascript
517
+ await RPC.getTransaction(hashText: string); //Returns information about a transaction by hash.
518
+ ```
519
+
520
+ ```javascript
521
+ await RPC.cancelTransaction(hashText: string); //Removes a pending transaction from the mempool.
522
+ ```
523
+
524
+ ```javascript
525
+ await RPC.getChains(); //Returns an array of all chains deployed in Phantasma.
526
+ ```
527
+
528
+ ```javascript
529
+ await RPC.getNexus(); //Returns info about the nexus.
530
+ ```
531
+
532
+ ```javascript
533
+ await RPC.getOrganization(ID: string); //Returns info about an organization.
534
+ ```
535
+
536
+ ```javascript
537
+ await RPC.getLeaderboard(name: string); //Returns content of a Phantasma leaderboard.
538
+ ```
539
+
540
+ ```javascript
541
+ await RPC.getTokens(); //Returns an array of tokens deployed in Phantasma.
542
+ ```
543
+
544
+ ```javascript
545
+ await RPC.getToken(symbol: string); //Returns info about a specific token deployed in Phantasma.
546
+ ```
547
+
548
+ ```javascript
549
+ await RPC.getTokenData(symbol: string, IDtext: string); //Returns data of a non-fungible token, in hexadecimal format.
550
+ ```
551
+
552
+ ```javascript
553
+ await RPC.getTokenBalance(account: string, tokenSymbol: string, chainInput: string); //Returns the balance for a specific token and chain, given an address.
554
+ ```
555
+
556
+ ```javascript
557
+ await RPC.getAuctionsCount(chainAddressOrName: string, symbol: string); //Returns the number of active auctions.
558
+ ```
559
+
560
+ ```javascript
561
+ await RPC.getAuctions(chainAddressOrName: string, symbol: string, page: number, pageSize: number); //Returns the auctions available in the market.
562
+ ```
563
+
564
+ ```javascript
565
+ await RPC.getAuction(chainAddressOrName: string, symbol: string, IDtext: string); //Returns the auction for a specific token.
566
+ ```
567
+
568
+ ```javascript
569
+ await RPC.getArchive(hashText: string)getArchive(hashText: string); //Returns info about a specific archive.
570
+ ```
571
+
572
+ ```javascript
573
+ await RPC.writeArchive(hashText: string, blockIndex: number, blockContent: string); //Writes the contents of an incomplete archive.
574
+ ```
575
+
576
+ ```javascript
577
+ await RPC.getABI(chainAddressOrName: string, contractName: string); //Returns the ABI interface of specific contract.
578
+ ```
579
+
580
+ ```javascript
581
+ await RPC.getPeers(); //Returns list of known peers.
582
+ ```
583
+
584
+ ```javascript
585
+ await RPC.relaySend(receiptHex: string); //Writes a message to the relay network.
586
+ ```
587
+
588
+ ```javascript
589
+ await RPC.relayReceive(account: string); //Receives messages from the relay network.
590
+ ```
591
+
592
+ ```javascript
593
+ await RPC.getEvents(account: string); //Reads pending messages from the relay network.
594
+ ```
595
+
596
+ ```javascript
597
+ await RPC.getPlatforms(); //Returns an array of available interop platforms.
598
+ ```
599
+
600
+ ```javascript
601
+ await RPC.getValidators(); //Returns an array of available validators.
602
+ ```
603
+
604
+ ```javascript
605
+ await RPC.settleSwap(sourcePlatform: string, destPlatform: string, hashText: string); //Tries to settle a pending swap for a specific hash.
606
+ ```
607
+
608
+ ```javascript
609
+ await RPC.getSwapsForAddressOld(account: string); //Returns platform swaps for a specific address.
610
+ ```
611
+
612
+ ```javascript
613
+ await RPC.getSwapsForAddress(account: string, platform: string); //Returns platform swaps for a specific address.
614
+ ```
615
+
616
+ ```javascript
617
+ await RPC.getNFT(symbol: string, nftId: string); //Returns info of a nft.
618
+ ```
619
+
620
+ ## PhantasmaLink
621
+
622
+ PhantasmaLink is a core connecting piece that allows you to interact with Phantasma based Wallets. PhantasmaLink is a building block to help you connect with wallets, however if you are more interested in using a more simple plug and play product, please see [EasyConnect](#easyconnect) **<- Super Useful**
623
+
624
+ Since phantasmaLink is a Class we are going to initiate a new phantasmaLink object.
625
+
626
+ ```javascript
627
+ let dappID = "Dapp Name"; //This is just the name you want to give the connection
628
+ let consoleLogging = true; //This is if you want console logging for Debugging Purposes [Default is set to true]
629
+
630
+ let link = new PhantasmaLink(dappID, consoleLogging);
631
+ ```
632
+
633
+ #### Vocab
634
+
635
+ - ` Callback - Function that gets called on after a success`
636
+ - ` onErrorCallback - Function that gets called on after a failure`
637
+ - ` Script - A set of instructions for that PhantasmaChain to decode that lies inside of a transaction object` See [ScriptBuilder](#building-a-script-with-script-builder)
638
+ - ` Nexus - The chain on Phantasma that is being used: Either 'mainnet' or 'testnet'`
639
+ - ` Payload - Extra data attached to a transaction object`
640
+ - ` ProviderHint - Tells PhantasmaLink which wallet you intend to connect with`
641
+
642
+ ### Functions:
643
+
644
+ ```javascript
645
+ link.login(onLoginCallback, onErrorCallback, providerHint); //Provider Hint can be 'ecto' or 'poltergeist'
646
+ ```
647
+
648
+ ```javascript
649
+ link.invokeScript(script, callback); //Allows you to do a ReadOnly script operation on the Phantasma Blockchain (Sends results as an Argument to Callback Function)
650
+ ```
651
+
652
+ ```javascript
653
+ link.signTx(nexus, script, payload, callback, onErrorCallback); //Signs a Transaction via Wallet (payload can be Null) (Sends results as an Argument to Callback Function)
654
+ ```
655
+
656
+ ```javascript
657
+ link.signTxPow(nexus, script, payload, proofOfWork, callback, onErrorCallback); //Signs a Transaction via Wallet with ProofOfWork Attached (Used for Contract Deployment)
658
+
659
+ //ProofOfWork Enum
660
+ enum ProofOfWork {
661
+ None = 0,
662
+ Minimal = 5,
663
+ Moderate = 15,
664
+ Hard = 19,
665
+ Heavy = 24,
666
+ Extreme = 30
667
+ }
668
+ ```
669
+
670
+ ```javascript
671
+ link.getPeer(callback, onErrorCallback); //Get's the peer list for the currently connected network
672
+ ```
673
+
674
+ ```javascript
675
+ link.signData(data, callback, onErrorCallback); //Allows you to sign some data via your Wallet (Sends results as an Argument to Callback Function)
676
+ ```
677
+
678
+ ```javascript
679
+ link.toggleMessageLogging(); //Toggles Console Message Logging
680
+ ```
681
+
682
+ ```javascript
683
+ link.dappID(); //Returns DappID
684
+ ```
685
+
686
+ ```javascript
687
+ link.sendLinkRequest(request, callback); //Used internally and sends wallet instructions through socket, you probably won't use it unless you know what your doing
688
+ ```
689
+
690
+ ```javascript
691
+ link.createSocket(); //Used internally to connect to wallet, you probably won't use it unless you know what your doing
692
+ link.retry(); //Used internally to retry socket connection, you probably won't use it unless you know what your doing
693
+ ```
694
+
695
+ ```javascript
696
+ link.disconnect(message); //Disconnects From Socket (You can add a reason with the Message Argument)
697
+ ```
698
+
699
+
700
+ ### Example Code
701
+ Here is some example code to initate a wallet connection.
702
+
703
+ ```javascript
704
+ let link = new PhantasmaLink("Dapp"); //"Dapp" is just whatever name you want to give your application
705
+
706
+ //Use this code snippet to connect to a phantasma wallet
707
+ link.login(
708
+ function (success) {
709
+ //Console Logging for Debugging Purposes
710
+ if (success) {
711
+ console.log(
712
+ "Connected to account " + this.account.address + " via " + this.wallet
713
+ );
714
+ } else {
715
+ console.log("Connection Failed");
716
+ }
717
+ },
718
+ (data) => {
719
+ console.log(data);
720
+ },
721
+ "ecto"
722
+ ); //Swap out ecto for 'poltergeist' if wanting to connect to Poltergeist Wallet
723
+ ```
724
+
725
+ ## EasyConnect
726
+
727
+ EasyConnect is a plug and play wrapper for PhantasmaLink that makes creating a DApp simple and easy.
728
+
729
+ Since EasyConnect is a Class we are going to initiate a new EasyConnect object.
730
+
731
+ ```javascript
732
+ //Optional Arguments [ requiredVersion: number, platform: string, providerHint: string]
733
+ let link = new EasyConnect(); //Has Optional Arguments input as Array
734
+ ```
735
+
736
+ ### Core Functions
737
+
738
+ ```javascript
739
+ link.connect(onSuccess, onFail); //Has two optional callback functions, one for Success and one for Failure
740
+ ```
741
+
742
+ ```javascript
743
+ link.disconnect(_message: string); //Allows you to disconnect from the wallet with a desired message
744
+ ```
745
+
746
+ ```javascript
747
+ link.signTransaction(script: string, payload: string, onSuccess, onFail); //Used to send a transaction to Wallet
748
+ ```
749
+
750
+ ```javascript
751
+ link.signData(data:any, onSuccess, onFail); //Allows you to sign data with a wallet keypair
752
+ ```
753
+
754
+ ```javascript
755
+ link.setConfig(_provider: string); //Allows you to set wallet provider, 'auto', 'ecto', 'poltergeist' (Default is already set to 'auto')
756
+ ```
757
+
758
+ ```javascript
759
+ //Allows Async aswell
760
+ link.query(_type: string, _arguments: Array<string>, _callback); //Allows you to query connected wallet/account information (arguments and callback are optional)
761
+ ```
762
+
763
+ ```javascript
764
+ //Allows Async aswell
765
+ link.action(_type: string, _arguments: Array<string>, _callback); //Allows you to send a specified action quickly
766
+ ```
767
+
768
+ ```javascript
769
+ //Allows Async aswell
770
+ link.script.buildScript(_type: string, _arguments: Array<string>, _callback); //Allows you to quickly create a script with only arguments
771
+ // Script Types
772
+ // 'interact', [contractName, methodName, [arguments]]
773
+ // 'invoke', [contractName, methodName, [arguments]]
774
+ // 'interop', [interopName, [arguments]]
775
+ ```
776
+
777
+ ```javascript
778
+ link.invokeScript(script: string, _callback); //Allows you to query data from smart contracts on Phantasma (Non Transactional)
779
+ ```
780
+
781
+ ```javascript
782
+ link.deployContract(script: string, payload:string, proofOfWork, onSuccess, onFail) //Allows you to deploy a contract script
783
+
784
+ //Proof of Work Enum
785
+ export enum ProofOfWork {
786
+ None = 0,
787
+ Minimal = 5,
788
+ Moderate = 15,
789
+ Hard = 19,
790
+ Heavy = 24,
791
+ Extreme = 30
792
+ }
793
+ ```
794
+
795
+ ### Query Function
796
+
797
+ The Query function is an async function that also allows you to use callbacks. You can use it is a promise, or in a chain!
798
+
799
+ ```javascript
800
+ await link.query("account"); //Retrieves all connected wallet account information
801
+ ```
802
+
803
+ ```javascript
804
+ await link.query("name"); //Retrieves registered name associated with connect wallet
805
+ ```
806
+
807
+ ```javascript
808
+ await link.query("balances"); //Shows complete token balance accociated with connected wallet
809
+ ```
810
+
811
+ ```javascript
812
+ await link.query("walletAddress"); //Shows connected wallet address
813
+ ```
814
+
815
+ ```javascript
816
+ await link.query("avatar"); //Shows connected wallet avatar
817
+ ```
818
+
819
+ ### Action Function
820
+
821
+ The Action function is an async function that also allows you to use callbacks. You can use it is a promise, or in a chain!
822
+
823
+ ```javascript
824
+ await link.action('sendFT', [fromAddress:string, toAddress:string, tokenSymbol:string, amount:number]); //Send Fungible Token
825
+ ```
826
+
827
+ ```javascript
828
+ await link.action('sendNFT', [fromAddress:string, toAddress:string, tokenSymbol:string, tokenID:number]); //Send Non Fungible Token
829
+ ```
830
+
831
+ ### Easy Script Create
832
+
833
+ (WIP)
834
+ Allows you to generate scripts quickly.
835
+
836
+ ```javascript
837
+ async buildScript(_type: string, _options: Array<any>);
838
+ // Script Types
839
+ // 'interact', [contractName, methodName, [arguments]]
840
+ // 'invoke', [contractName, methodName, [arguments]]
841
+ // 'interop', [interopName, [arguments]]
842
+ ```