{"id":19747489,"url":"https://github.com/phantasma-io/phantasma-ts","last_synced_at":"2026-03-14T12:39:48.783Z","repository":{"id":227134340,"uuid":"770321787","full_name":"phantasma-io/phantasma-ts","owner":"phantasma-io","description":"A TypeScript SDK for the Phantasma blockchain","archived":false,"fork":false,"pushed_at":"2025-05-08T22:20:01.000Z","size":2669,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-04T05:08:21.946Z","etag":null,"topics":["blockchain","crypto","cryptocurrency","dapps-development","layer1","phantasma","phantasmachain","phantasmaio","sdk","smartcontract","smartnft","smartnfts"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phantasma-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-03-11T10:57:30.000Z","updated_at":"2025-05-08T22:19:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"98aeb697-9ebe-468d-87c7-28f78b454d12","html_url":"https://github.com/phantasma-io/phantasma-ts","commit_stats":null,"previous_names":["phantasma-io/phantasma-ts"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/phantasma-io/phantasma-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2Fphantasma-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2Fphantasma-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2Fphantasma-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2Fphantasma-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phantasma-io","download_url":"https://codeload.github.com/phantasma-io/phantasma-ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phantasma-io%2Fphantasma-ts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266606969,"owners_count":23955376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","crypto","cryptocurrency","dapps-development","layer1","phantasma","phantasmachain","phantasmaio","sdk","smartcontract","smartnft","smartnfts"],"created_at":"2024-11-12T02:17:59.743Z","updated_at":"2026-03-14T12:39:48.777Z","avatar_url":"https://github.com/phantasma-io.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phantasma-sdk-ts\n\nA TypeScript SDK for the Phantasma blockchain.\n\n## Installation\n\nUse the package manager [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install phatasma-ts.\n\n```bash\nnpm install phantasma-sdk-ts\n```\n\n## Importing\n\n```javascript\nconst { PhantasmaTS } = require(\"phantasma-sdk-ts\");\n```\n\n## Logging\n\nSDK logging is opt-in. To enable logs, pass your logger (for example, `console`) to `setLogger`. Leave it unset for silent operation.\n\n```javascript\nconst { setLogger } = require(\"phantasma-sdk-ts\");\n\nsetLogger(console); // enable SDK logs\n// setLogger(); // disable SDK logs\n```\n\n## Standalone HTML Import\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/phantasma-sdk-ts@latest/html/phantasma.js\"\u003e\u003c/script\u003e\n```\n\n```javascript\nphantasma.PhantasmaTS; // To use PhantasmaTS\nphantasma.PhantasmaLink; // To use PhantasmaLink\nphantasma.EasyConnect; // To use EasyConnect, an easy to use PhantasmaLink wrapper\n```\n\n## Table Of Contents\n\nThe Phantasma TypeScript SDK transpiles into PhantasmaTS, PhantasmaLink and EasyConnect.\n\n1. [PhantasmaTS](#phantasmats) - Allows you to interact with the Phantasma Blockchain\n\n   - [Utility Functions](#phantasmats-utility-functions)\n   - [Script Builder](#building-a-script-with-script-builder)\n     - [Interop Commands](#interop-functions)\n     - [Building Transaction](#building-a-transaction)\n     - [Deploying Smart Contract](#deploying-a-contract)\n     - [RPC](#using-rpc)\n\n2. [PhantasmaLink](#phantasmalink) - Allows you to interact with Phantasma based wallets\n   - [Functions](#functions)\n   - [Examples](#example-code)\n\n3. [EasyConnect](#easyconnect) - Easy plug and play solution for creating DApps\n\n   - [Core Functions](#core-functions)\n   - [Query Function](#query-function)\n   - [Action Function](#action-function)\n   - [Easy Script](#easy-script-create)\n\n4. [Misc]\n   - [Vocab](#vocab)\n\n---\n\n## PhantasmaTS\n\nUse PhantasmaTS to interact with the Phantasma blockchain directly.\n\n### PhantasmaTS Utility Functions\n\nJust some standard useful functions that you probably will end up using at some point.\n\n```javascript\nPhantasmaTS.byteArrayToHex(arr: ArrayBuffer | ArrayLike\u003cnumber\u003e); //Turns a Byte Array into Serialized Hex\n```\n\n```javascript\nPhantasmaTS.getAddressFromWif(wif: string); //Get's Public Address from WIF (Wallet Import Format)\n```\n\n```javascript\nPhantasmaTS.getPrivateKeyFromWif(wif: string); //Get's Private Key from WIF (Wallet Import Format)\n```\n\n```javascript\nPhantasmaTS.hexToByteArray(hexBytes: string); //Turns Serialized Hex into Byte Array\n```\n\n```javascript\nPhantasmaTS.reverseHex(hex: string); //Reverse \u003c-\u003e esreveR Serialized Hex\n```\n\n```javascript\nPhantasmaTS.signData(msgHex: string, privateKey: string); //Signs some text with given Private Key\n```\n\n### Building a Script with Script Builder\n\nBuilding 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.\n\nThese functions, `.CallContract` and `.CallInterop`, are your bread and butter for creating new scripts.\n\n` .CallContract(contractName: string, methodName: string, [arguments]: array)`\n\n` .CallInterop(functionName: string, [arguments]: array)`\n\n- You can find out all the diffrent `.CallInterop` functions below.\n\n- 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.info/chain/main#tab_contracts)\n\n#### Example:\n\n```javascript\n//Creating a new Script Builder Object\nlet sb = new PhantasmaTS.ScriptBuilder();\n\n//Here is an example of a Transactional Script\n    sb\n    .AllowGas(fromAddress, sb.NullAddress, gasPrice, gasLimit)\n    .CallInterop(\"Runtime.TransferTokens\", ['fromAddress', 'toAddress', 'KCAL', 10000000000]) //10000000000 = 1 KCAL\n    .SpendGas(fromAddress)\n    .EndScript();\n\n--- OR ----\n\n//Here is an example of a non Transactional Script\n\n    sb\n    .CallContract('account', 'LookUpName', ['accountName'])\n    .EndScript();\n\n```\n#### InvokeRawScript and decoding the result\n```javascript\n\nlet sb = new PhantasmaTS.ScriptBuilder();\nsb.CallContract(\"stake\", \"GetMasterCount\", []);\nlet script = sb.EndScript();\nlet targetNet = 'main';\n\n// NOTE - we assume RPC was instantiated previously already, check other samples to see how\nlet response = await RPC.invokeRawScript(targetNet, script);\n\nconst decoder = new PhantasmaTS.Decoder(response.result);\nconst value = decoder.readVmObject();\nconsole.log(value); // print the decoded value to the console\n\n```\n\n#### Interop Functions:\n\nHere 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.\n\n```javascript\nsb.CallInterop(\"Runtime.MintTokens\", [from: string, target: string, tokenSymbol: string , amount: number]); //Used for Fungible Tokens\n```\n\n```javascript\nsb.CallInterop(\"Runtime.TransferTokens\", [from: string, to: string, tokenSymbol: string, amount: number]); //Used for Fungible Tokens\n```\n\n```javascript\nsb.CallInterop(\"Runtime.TransferBalance\", [from: string, to: string, tokenSymbol: string]);\n```\n\n```javascript\nsb.CallInterop(\"Runtime.TransferToken\", [from: string, to: string, tokenSymbol: string, tokenId: number]); //Used for Non Fungible Tokens\n```\n\n```javascript\nsb.CallInterop(\"Runtime.SendTokens\", [destinationChain: string, from: string, to: string, tokenSymbol: string, amount: number); //Used for Fungible Tokens\n```\n\n```javascript\nsb.CallInterop(\"Runtime.SendToken\", [destinationChain: string, from: string, to: string, tokenSymbol: string, tokenId: number]); //Used for Non Fungible Tokens\n```\n\n```javascript\nsb.CallInterop(\"Runtime.DeployContract\", [from: string, contractName: string, pvm: hexString, abi: hexString]);\n```\n\n### Building a Transaction\n\nTo build a transaction you will first need to build a script.\n\nNote, building a Transaction is for transactional scripts only. Non transactional scripts should use the RPC function `RPC.invokeRawScript(chainInput: string, scriptData: string)`\n\n```javascript\nconst { PhantasmaTS } = require(\"phantasma-sdk-ts\");\n\n\nasync function sendTransaction() {\n\n  let WIF = \"WIF\"; //In WIF Format\n  let fromAddress = \"yourPublicWalletAddress\";\n  let toAddress = \"addressYoureSendingTo\";\n\n  //Creating RPC Connection **(Needs To Be Updated)\n  let RPC = new PhantasmaTS.PhantasmaAPI(\n    \"http://localhost:7077/rpc\",\n    null,\n    \"simnet\"\n  );\n\n  //set Gas parameters for Runtime.TransferTokens\n  let gasPrice = PhantasmaTS.DomainSettings.DefaultMinimumGasFee; //Internal Blockchain minimum gas fee needed - i.e 100000\n  let gasLimit = 9999;\n\n  //Creating a new Script Builder Object\n  let sb = new PhantasmaTS.ScriptBuilder();\n\n  //Making a Script\n  let script = sb\n    .BeginScript()\n    .AllowGas(fromAddress, sb.NullAddress, gasPrice, gasLimit)\n    .CallInterop(\"Runtime.TransferTokens\", [\n      fromAddress,\n      toAddress,\n      \"SOUL\",\n      100000000,\n    ]) //100000000 = 1 SOUL\n    .SpendGas(fromAddress)\n    .EndScript();\n\n  //Used to set expiration date\n  let expiration = 5; //This is in miniutes\n  let getTime = new Date();\n  let expiration_date = new Date(getTime.getTime() + expiration * 60000);\n\n  let payload = PhantasmaTS.Base16.encode(\"Phantasma-ts\"); //Says '7068616e7461736d612d7473' in hex\n\n  //Creating New Transaction Object\n  let transaction = new PhantasmaTS.Transaction(\n    \"simnet\", //Nexus Name - if you're using mainnet change it to mainnet or simnet if you're using you localnode\n    \"main\", //Chain\n    script, //In string format\n    expiration_date, //Date Object\n    payload //Extra Info to attach to Transaction in Serialized Hex\n  );\n\n  //Sign's Transaction with WIF\n  transaction.sign(WIF);\n  let hexEncodedTx = transaction.ToStringEncoded(true); //converts trasnaction to base16 string -true means transaction is signed-\n\n  //Send Transaction\n  let txHash = await RPC.sendRawTransaction(hexEncodedTx);\n  //Return Transaction Hash\n  return txHash;\n}\n\n```\n### Staking SOUL\n\nThis is an example how to stake SOUL\n\n```javascript\nasync function stakeSOUL() {\n  let WIF = \"WIF\"; //WIF format\n\n  let fromAddress = \"yourPublicWalletAddress\"; // Phantasma Public Address\n\n  //Creating a new Script Builder Object\n  let sb = new PhantasmaTS.ScriptBuilder();\n  let gasPrice = PhantasmaTS.DomainSettings.DefaultMinimumGasFee; //Internal Blockchain minimum gas fee needed - i.e 100000\n  let gasLimit = 21000;\n  let amount = String(10 * 10 ** 8); // 100 the amount - 10**8 it's to get the decimals to the desired amount\n  // Soul has 8 decimals places.\n\n  //Creating RPC Connection **(Needs To Be Updated)\n  let RPC = new PhantasmaTS.PhantasmaAPI(\n    \"http://localhost:7077/rpc\",\n    null,\n    \"simnet\"\n  );\n\n  //Making a Script\n  let script = sb\n    .AllowGas(fromAddress, sb.NullAddress, gasPrice, gasLimit)\n    .CallContract(\"stake\", \"Stake\", [fromAddress, amount])\n    .SpendGas(fromAddress)\n    .EndScript();\n\n  //Used to set expiration date\n  let expiration = 5; //This is in miniutes\n  let getTime = new Date();\n  let expiration_date = new Date(getTime.getTime() + expiration * 60000);\n\n  let payload = \"7068616e7461736d612d7473\"; //Says 'Phantasma-ts' in hex\n\n  //Creating New Transaction Object\n  let transaction = new PhantasmaTS.Transaction(\n    \"simnet\", //Nexus Name - if you're using mainnet change it to mainnet\n    \"main\", //Chain\n    script, //In string format\n    expiration_date, //Date Object\n    payload //Extra Info to attach to Transaction in Serialized Hex\n  );\n\n  //Sign's Transaction with WIF\n  transaction.sign(WIF);\n\n  let hexEncodedTx = transaction.ToStringEncoded(true);\n\n  //Send Transaction\n  let txHash = await RPC.sendRawTransaction(hexEncodedTx);\n\n  //Return Transaction Hash\n  return txHash;\n}\n```\n\n### Deploying a Contract\n\n```javascript\nasync function deployContract() {\n  //Wallet Stuff\n  let WIF = \"WIF\"; //In wif Format\n  let fromAddress = \"yourPublicWalletAddress\";\n\n  //Contract Stuff\n  let pvm = \"PVM HEX String\";\n  let abi = \"ABI HEX String\";\n\n  //convert Pvm to Bytes -\u003e uint8Array\n  let pvm_byteArr = PhantasmaTS.hexToByteArray(pvm);\n  pvm_byteArr.shift();\n  let byte_pvm = new Uint8Array(pvm_byteArr);\n\n  //convert abi to Bytes -\u003e uint8Array\n  let abi_byteArr = PhantasmaTS.hexToByteArray(abi);\n  abi_byteArr.shift();\n  let byte_abi = new Uint8Array(abi_byteArr);\n\n  let gasPrice = PhantasmaTS.DomainSettings.DefaultMinimumGasFee; //Internal Blockchain minimum gas fee needed - i.e 100000\n  let gasLimit = 21000;\n  let contractName = \"contractName\"; //Whatever you want\n\n  //Creating a new Script Builder Object\n  let sb = new PhantasmaTS.ScriptBuilder();\n\n  //New RPC and Peers Needed\n  //Creating RPC Connection, use ('http://testnet.phantasma.info/rpc', null, 'testnet') for testing\n  let RPC = new PhantasmaTS.PhantasmaAPI(\n    \"http://localhost:5172/rpc\",\n    null,\n    \"simnet\"\n  );\n\n  //Making a Script\n  let script = sb\n    .AllowGas(fromAddress, sb.NullAddress, gasPrice, gasLimit)\n    .CallInterop(\"Runtime.DeployContract\", [\n      fromAddress,\n      contractName,\n      byte_pvm,\n      byte_abi,\n    ])\n    .SpendGas(fromAddress)\n    .EndScript();\n\n  //Used to set expiration date\n  let expiration = 5; //This is in miniutes\n  let getTime = new Date();\n  let expiration_date = new Date(getTime.getTime() + expiration * 60000);\n\n  //Setting Temp Payload\n  let payload = \"MyApp\";\n\n  //Creating New Transaction Object\n  let transaction = new PhantasmaTS.Transaction(\n    \"simnet\", //Nexus Name\n    \"main\", //Chain\n    script, //In string format\n    expiration_date, //Date Object\n    payload //Extra Info to attach to Transaction in Serialized Hex\n  );\n\n  //Deploying Contract Requires POW -- Use a value of 5 to increase the hash difficulty by at least 5\n  transaction.mineTransaction(5);\n\n  //Signs Transaction with your WIF\n  transaction.sign(WIF);\n\n  let hexEncodedTx = transaction.ToStringEncoded(true);\n\n  //Sends Transaction\n  let txHash = await RPC.sendRawTransaction(hexEncodedTx);\n\n  //Returns Transaction Hash\n  return txHash;\n}\n```\n\n### Scanning the blockchain for incoming transactions\n\n```javascript\nconst { PhantasmaTS } = require(\"phantasma-sdk-ts\");\n\nlet RPC = new PhantasmaTS.PhantasmaAPI(\n  \"https://pharpc1.phantasma.info/rpc\",\n  null,\n  \"mainnet\"\n);\n\n// Store the current height of the chain\nlet currentHeight = 1;\n\nlet chainName = \"main\";\n\nfunction onTransactionReceived(address, symbol, amount) {}\n\n// Function that periodically checks the height of the chain and fetches the latest block if the height has increased\nasync function checkForNewBlocks() {\n  // Get the current height of the chain\n  let newHeight = await RPC.getBlockHeight(chainName);\n\n  // Check if the height has increased\n  if (newHeight \u003e currentHeight) {\n    // Fetch the latest block\n    let latestBlock = await RPC.getBlockByHeight(chainName, newHeight);\n\n    // Check all transactions in this block\n    for (i = 0; i \u003c latestBlock.txs.length; i++) {\n      let tx = latestBlock.txs[i];\n\n      // Check all events in this transaction\n      for (j = 0; j \u003c tx.events.length; j++) {\n        let evt = tx.events[j];\n        if (evt.kind == \"TokenReceive\") {\n          var data = PhantasmaTS.getTokenEventData(evt.data);\n          onTransactionReceived(evt.address, data.symbol, data.value);\n        }\n      }\n    }\n\n    // Update the current height of the chain\n    currentHeight = newHeight;\n  }\n\n  // Repeat this process after a delay\n  setTimeout(checkForNewBlocks, 1000);\n}\n\n// Start checking for new blocks\ncheckForNewBlocks();\n```\n\n### Using RPC\n\n```javascript\nlet RPC = new PhantasmaTS.PhantasmaAPI(\n  \"https://pharpc1.phantasma.info/rpc\",\n  null,\n  \"mainnet\"\n);\n```\n\n#### Utillities:\n\n- `RPC.JSONRPC(method: string, params: Array\u003cany\u003e);` \u003c- Used to make any Phantasma RPC call\n- ` RPC.updateRpc()`\n- ` RPC.setRpcHost(rpcHost: string)`\n- ` RPC.setRpcByName(rpcName: string)`\n- ` RPC.setNexus(nexus: string)`\n- ` RPC.convertDecimals(amount: number, decimals: number)`\n\n#### All RPC Function Calls:\n\n```javascript\nawait RPC.getAccount(account: string); //Returns the account name and balance of given address.\n```\n\n```javascript\nawait RPC.lookUpName(name: string); //Returns the address that owns a given name.\n```\n\n```javascript\nawait RPC.getBlockHeight(chainInput: string); //Returns the height of a chain.\n```\n\n```javascript\nawait RPC.getBlockTransactionCountByHash(blockHash: string); //Returns the number of transactions of given block hash or error if given hash is invalid or is not found.\n```\n\n```javascript\nawait RPC.getBlockByHash(blockHash: string); //Returns information about a block by hash.\n```\n\n```javascript\nawait RPC.getRawBlockByHash(blockHash: string); //Returns a serialized string, containing information about a block by hash.\n```\n\n```javascript\nawait RPC.getBlockByHeight(chainInput: string, height: number); //Returns information about a block by height and chain.\n```\n\n```javascript\nawait RPC.getRawBlockByHeight(chainInput: string, height: number); //Returns a serialized string, in hex format, containing information about a block by height and chain.\n```\n\n```javascript\nawait RPC.getTransactionByBlockHashAndIndex(blockHash: string, index: number); //Returns the information about a transaction requested by a block hash and transaction index.\n```\n\n```javascript\nawait RPC.getAddressTransactions(account: string, page: number, pageSize: number); //Returns last X transactions of given address.\n```\n\n```javascript\nawait RPC.getAddressTransactionCount(account: string, chainInput: string); //Get number of transactions in a specific address and chain.\n```\n\n```javascript\nawait RPC.sendRawTransaction(txData: string); //Allows to broadcast a signed operation on the network, but it\u0026apos;s required to build it manually.\n```\n\n```javascript\nawait RPC.invokeRawScript(chainInput: string, scriptData: string); //Allows to invoke script based on network state, without state changes.\n```\n\n```javascript\nawait RPC.getTransaction(hashText: string); //Returns information about a transaction by hash.\n```\n\n```javascript\nawait RPC.cancelTransaction(hashText: string); //Removes a pending transaction from the mempool.\n```\n\n```javascript\nawait RPC.getChains(); //Returns an array of all chains deployed in Phantasma.\n```\n\n```javascript\nawait RPC.getNexus(); //Returns info about the nexus.\n```\n\n```javascript\nawait RPC.getOrganization(ID: string); //Returns info about an organization.\n```\n\n```javascript\nawait RPC.getLeaderboard(name: string); //Returns content of a Phantasma leaderboard.\n```\n\n```javascript\nawait RPC.getTokens(); //Returns an array of tokens deployed in Phantasma.\n```\n\n```javascript\nawait RPC.getToken(symbol: string); //Returns info about a specific token deployed in Phantasma.\n```\n\n```javascript\nawait RPC.getTokenData(symbol: string, IDtext: string); //Returns data of a non-fungible token, in hexadecimal format.\n```\n\n```javascript\nawait RPC.getTokenBalance(account: string, tokenSymbol: string, chainInput: string); //Returns the balance for a specific token and chain, given an address.\n```\n\n```javascript\nawait RPC.getAuctionsCount(chainAddressOrName: string, symbol: string); //Returns the number of active auctions.\n```\n\n```javascript\nawait RPC.getAuctions(chainAddressOrName: string, symbol: string, page: number, pageSize: number); //Returns the auctions available in the market.\n```\n\n```javascript\nawait RPC.getAuction(chainAddressOrName: string, symbol: string, IDtext: string); //Returns the auction for a specific token.\n```\n\n```javascript\nawait RPC.getArchive(hashText: string)getArchive(hashText: string); //Returns info about a specific archive.\n```\n\n```javascript\nawait RPC.writeArchive(hashText: string, blockIndex: number, blockContent: string); //Writes the contents of an incomplete archive.\n```\n\n```javascript\nawait RPC.getABI(chainAddressOrName: string, contractName: string); //Returns the ABI interface of specific contract.\n```\n\n```javascript\nawait RPC.getPeers(); //Returns list of known peers.\n```\n\n```javascript\nawait RPC.relaySend(receiptHex: string); //Writes a message to the relay network.\n```\n\n```javascript\nawait RPC.relayReceive(account: string); //Receives messages from the relay network.\n```\n\n```javascript\nawait RPC.getEvents(account: string); //Reads pending messages from the relay network.\n```\n\n```javascript\nawait RPC.getPlatforms(); //Returns an array of available interop platforms.\n```\n\n```javascript\nawait RPC.getValidators(); //Returns an array of available validators.\n```\n\n```javascript\nawait RPC.settleSwap(sourcePlatform: string, destPlatform: string, hashText: string); //Tries to settle a pending swap for a specific hash.\n```\n\n```javascript\nawait RPC.getSwapsForAddressOld(account: string); //Returns platform swaps for a specific address.\n```\n\n```javascript\nawait RPC.getSwapsForAddress(account: string, platform: string); //Returns platform swaps for a specific address.\n```\n\n```javascript\nawait RPC.getNFT(symbol: string, nftId: string); //Returns info of a nft.\n```\n\n## PhantasmaLink\n\nPhantasmaLink 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) **\u003c- Super Useful**\n\nSince phantasmaLink is a Class we are going to initiate a new phantasmaLink object.\n\n```javascript\nlet dappID = \"Dapp Name\"; //This is just the name you want to give the connection\nlet consoleLogging = true; //This is if you want console logging for Debugging Purposes [Default is set to true]\n\nlet link = new PhantasmaLink(dappID, consoleLogging);\n```\n\n#### Vocab\n\n- ` Callback - Function that gets called on after a success`\n- ` onErrorCallback - Function that gets called on after a failure`\n- ` 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)\n- ` Nexus - The chain on Phantasma that is being used: Either 'mainnet' or 'testnet'`\n- ` Payload - Extra data attached to a transaction object`\n- ` ProviderHint - Tells PhantasmaLink which wallet you intend to connect with`\n\n### Functions:\n\n```javascript\nlink.login(onLoginCallback, onErrorCallback, providerHint); //Provider Hint can be 'ecto' or 'poltergeist'\n```\n\n```javascript\nlink.invokeScript(script, callback); //Allows you to do a ReadOnly script operation on the Phantasma Blockchain (Sends results as an Argument to Callback Function)\n```\n\n```javascript\nlink.signTx(nexus, script, payload, callback, onErrorCallback); //Signs a Transaction via Wallet (payload can be Null) (Sends results as an Argument to Callback Function)\n```\n\n```javascript\nlink.signCarbonTxAndBroadcast(txMsg, onSuccess, onErrorCallback); //Signs \u0026 broadcasts a Carbon TxMsg via wallets that support Phantasma Link v4+\n```\n\n```javascript\nlink.signTxPow(nexus, script, payload, proofOfWork, callback, onErrorCallback);  //Signs a Transaction via Wallet with ProofOfWork Attached (Used for Contract Deployment)\n\n//ProofOfWork Enum\nenum ProofOfWork {\n    None = 0,\n    Minimal = 5,\n    Moderate = 15,\n    Hard = 19,\n    Heavy = 24,\n    Extreme = 30\n}\n```\n\n```javascript\nlink.getPeer(callback, onErrorCallback); //Get's the peer list for the currently connected network\n```\n\n```javascript\nlink.signData(data, callback, onErrorCallback); //Allows you to sign some data via your Wallet (Sends results as an Argument to Callback Function)\n```\n\n```javascript\nlink.toggleMessageLogging(); //Toggles Console Message Logging\n```\n\n```javascript\nlink.dappID(); //Returns DappID\n```\n\n```javascript\nlink.sendLinkRequest(request, callback); //Used internally and sends wallet instructions through socket, you probably won't use it unless you know what your doing\n```\n\n```javascript\nlink.createSocket(); //Used internally to connect to wallet, you probably won't use it unless you know what your doing\nlink.retry(); //Used internally to retry socket connection, you probably won't use it unless you know what your doing\n```\n\n```javascript\nlink.disconnect(message); //Disconnects From Socket (You can add a reason with the Message Argument)\n```\n\n\n### Example Code\nHere is some example code to initate a wallet connection.\n\n```javascript\nlet link = new PhantasmaLink(\"Dapp\"); //\"Dapp\" is just whatever name you want to give your application\n\n//Use this code snippet to connect to a phantasma wallet\nlink.login(\n  function (success) {\n    //Console Logging for Debugging Purposes\n    if (success) {\n      console.log(\n        \"Connected to account \" + this.account.address + \" via \" + this.wallet\n      );\n    } else {\n      console.log(\"Connection Failed\");\n    }\n  },\n  (data) =\u003e {\n    console.log(data);\n  },\n  \"ecto\"\n); //Swap out ecto for 'poltergeist' if wanting to connect to Poltergeist Wallet\n```\n\n### Carbon Transactions (Link v4+)\n\nWallets that expose Phantasma Link v4 (or higher) can sign and broadcast Carbon `TxMsg` payloads directly. Make sure you log in with `version = 4` when calling `link.login`, then forward the message via `signCarbonTxAndBroadcast`. The wallet will return a serialized `SignedTxMsg` blob that can be re-used locally if needed.\n\n```javascript\nimport {\n  TxMsg,\n  TxTypes,\n  SmallString,\n  TxMsgTransferFungible,\n  Bytes32,\n  PhantasmaAPI,\n} from 'phantasma-sdk-ts';\n\nconst api = new PhantasmaAPI('https://pharpc1.phantasma.info/rpc', null, 'mainnet');\n\nconst txMsg = new TxMsg(\n  TxTypes.TransferFungible,\n  BigInt(Math.floor(Date.now() / 1000) + 300), // expiry (UTC seconds)\n  100000n, // max gas\n  0n,\n  new Bytes32(senderPublicKeyBytes), // sender address as 32-byte buffer\n  SmallString.empty,\n  new TxMsgTransferFungible(new Bytes32(receiverPublicKeyBytes), 1n, 10_00000000n)\n);\n\nlink.signCarbonTxAndBroadcast(txMsg, async ({ signedTx }) =\u003e {\n  await api.sendCarbonTransaction(signedTx);\n});\n```\n\n## EasyConnect\n\nEasyConnect is a plug and play wrapper for PhantasmaLink that makes creating a DApp simple and easy.\n\nSince EasyConnect is a Class we are going to initiate a new EasyConnect object.\n\n```javascript\n//Optional Arguments [ requiredVersion: number, platform: string, providerHint: string]\nlet link = new EasyConnect(); //Has Optional Arguments input as Array\n```\n\n### Core Functions\n\n```javascript\nlink.connect(onSuccess, onFail); //Has two optional callback functions, one for Success and one for Failure\n```\n\n```javascript\nlink.disconnect(_message: string); //Allows you to disconnect from the wallet with a desired message\n```\n\n```javascript\nlink.signTransaction(script: string, payload: string, onSuccess, onFail); //Used to send a transaction to Wallet\n```\n\n```javascript\nlink.signCarbonTransaction(txMsg, onSuccess, onFail); //Sends a Carbon TxMsg to the connected wallet (Link v4+)\n```\n\n```javascript\nlink.signData(data:any, onSuccess, onFail); //Allows you to sign data with a wallet keypair\n```\n\n```javascript\nlink.setConfig(_provider: string); //Allows you to set wallet provider, 'auto', 'ecto', 'poltergeist' (Default is already set to 'auto')\n```\n\n```javascript\n//Allows Async aswell\nlink.query(_type: string, _arguments: Array\u003cstring\u003e, _callback); //Allows you to query connected wallet/account information (arguments and callback are optional)\n```\n\n```javascript\n//Allows Async aswell\nlink.action(_type: string, _arguments: Array\u003cstring\u003e, _callback); //Allows you to send a specified action quickly\n```\n\n```javascript\n//Allows Async aswell\nlink.script.buildScript(_type: string, _arguments: Array\u003cstring\u003e, _callback); //Allows you to quickly create a script with only arguments\n// Script Types\n// 'interact', [contractName, methodName, [arguments]]\n// 'invoke', [contractName, methodName, [arguments]]\n// 'interop', [interopName, [arguments]]\n```\n\n```javascript\nlink.invokeScript(script: string, _callback); //Allows you to query data from smart contracts on Phantasma (Non Transactional)\n```\n\n```javascript\nlink.deployContract(script: string, payload:string, proofOfWork, onSuccess, onFail) //Allows you to deploy a contract script\n\n//Proof of Work Enum\nexport enum ProofOfWork {\n    None = 0,\n    Minimal = 5,\n    Moderate = 15,\n    Hard = 19,\n    Heavy = 24,\n    Extreme = 30\n}\n```\n\n\u003e **Note:** Carbon helpers require a Phantasma Link v4 (or newer) session. When instantiating EasyConnect pass `[4, 'phantasma', providerHint]` (or change `requiredVersion`) before calling `connect`, otherwise wallets will reject Carbon signing requests.\n\n### Query Function\n\nThe Query function is an async function that also allows you to use callbacks. You can use it is a promise, or in a chain!\n\n```javascript\nawait link.query(\"account\"); //Retrieves all connected wallet account information\n```\n\n```javascript\nawait link.query(\"name\"); //Retrieves registered name associated with connect wallet\n```\n\n```javascript\nawait link.query(\"balances\"); //Shows complete token balance accociated with connected wallet\n```\n\n```javascript\nawait link.query(\"walletAddress\"); //Shows connected wallet address\n```\n\n```javascript\nawait link.query(\"avatar\"); //Shows connected wallet avatar\n```\n\n### Action Function\n\nThe Action function is an async function that also allows you to use callbacks. You can use it is a promise, or in a chain!\n\n```javascript\nawait link.action('sendFT', [fromAddress:string, toAddress:string, tokenSymbol:string, amount:number]); //Send Fungible Token\n```\n\n```javascript\nawait link.action('sendNFT', [fromAddress:string, toAddress:string, tokenSymbol:string, tokenID:number]); //Send Non Fungible Token\n```\n\n### Easy Script Create\n\n(WIP)\nAllows you to generate scripts quickly.\n\n```javascript\nasync buildScript(_type: string, _options: Array\u003cany\u003e);\n// Script Types\n// 'interact', [contractName, methodName, [arguments]]\n// 'invoke', [contractName, methodName, [arguments]]\n// 'interop', [interopName, [arguments]]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphantasma-io%2Fphantasma-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphantasma-io%2Fphantasma-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphantasma-io%2Fphantasma-ts/lists"}