🌐
Typescript / Javascript SDK
  • 👋Phantasma - TS
  • 🎆Quick Start
  • Setup
    • 🛠️Setup
  • Shared Methods
    • ☁️PhantasmaAPI
    • 🔗PhantasmaLink
    • 📝ScriptBuilder
      • Create a Script
  • Backend
    • ⚙️Backend
    • 📄Examples
      • Creating a new Address
      • Importing a Wallet
      • Create Script Call
      • Create a Transaction
      • Sign a Transaction
      • Send a Transaction
      • Get a Transaction
      • Invoke a Script
      • Get User Balances
      • Transfer Tokens
      • Decode Transfer Events
      • Get a Block by Height
      • Get data from new Blocks
  • Frontend
    • 🖥️Frontend
    • 📄Examples
      • Connect to the wallet
      • Invoking a Script
      • Sending a transaction
  • Resources
    • 👻Getting Started
    • 👻About Phantasma
    • 🧑‍🤝‍🧑For new Soldiers
    • 👨‍💻For Developers
Powered by GitBook
On this page
  • Creating a Transaction
  • Sign a Transaction
  1. Backend
  2. Examples

Create a Transaction

Creating a Transaction

This how to create a transaction.

import {PhantasmaKeys, Transaction} from 'phantasma-ts';
const NexusName = "testnet"; // Could also be simnet or mainnet
const ChainName = "main"; // Since we only have the main chain, it's always main.
let payload = Base16.encode("Phantasma-NodeJS"); // This is what going to appear on the explorer and on the wallet.
let expiration: Date = new Date(Date.UTC(
 new Date().getUTCFullYear(),
 new Date().getUTCMonth(),
 new Date().getUTCDate(),
 new Date().getUTCHours() + 1,
 new Date().getUTCMinutes() + 10,
 new Date().getUTCSeconds() + 10
));

let transaction = new Transaction(
 NexusName,  //Nexus Name
 ChainName,     //Chain
 myScript,     //In string format
 expiration, //Date Object
 payload     //Extra Info to attach to Transaction in Serialized Hex
);

Sign a Transaction

Now we need to sign the transaction if we want it to be accepted by the blockchain.

import {PhantasmaKeys} from 'phantasma-ts';
let wif = ""; // WIF of your wallet 
let keys = PhantasmaKeys.fromWIF(wif);

transaction.signWithKeys(keys);
let transactionSignedBytes = transaction.toString(true); 
PreviousCreate Script CallNextSign a Transaction

Last updated 1 year ago

📄