Send a Transaction

Here's an small example how to send a transaction using NodeJS for the backend.

Don't forget to import the WIF, you can the wif by exporting it from Poltergeist or Ecto Wallet.

Here's how to import the wallet keys.

Here we'll create the script that will be sending the transaction.

import { PhantasmaAPI, Transaction } from "phantasma-sdk-ts";

const RPC = new PhantasmaAPI("https://testnet.phantasma.info/rpc", undefined as any, "testnet");

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

/**
 * Send a transaction
 * @param transaction Transaction to send already signed
 */
async function SendATransaction(transaction: Transaction) {
  let transactionSignedBytes = transaction.toString(true); // Get the transaction in bytes convert it to string
  let txHash = await RPC.sendRawTransaction(transactionSignedBytes); // Send the transaction to the network
  await delay(5000); // Wait 5 seconds or more
  let result = await RPC.getTransaction(txHash); // Get the result of the transaction
  return result;
}

Check a full example how to transfer tokens

Transfer Tokens

Last updated