Quickstart
This guide shows a minimal backend flow: build a script, sign a transaction, send it, and confirm the result.
1) Install
npm install phantasma-sdk-ts2) Build and Send a Transaction
import {
Address,
Base16,
DomainSettings,
PhantasmaAPI,
PhantasmaKeys,
ScriptBuilder,
Transaction,
} from "phantasma-sdk-ts";
const rpcUrl = "https://testnet.phantasma.info/rpc";
const nexus = "testnet";
const chain = "main";
const api = new PhantasmaAPI(rpcUrl, undefined as any, nexus);
async function sendTransfer() {
const keys = PhantasmaKeys.fromWIF("YOUR_WIF");
const from = keys.Address;
const to = "P2K...";
const gasPrice = DomainSettings.DefaultMinimumGasFee;
const gasLimit = 21000;
const script = new ScriptBuilder()
.BeginScript()
.AllowGas(from, Address.Null, gasPrice, gasLimit)
.CallInterop("Runtime.TransferTokens", [from, to, "KCAL", "1000000000"])
.SpendGas(from)
.EndScript();
const expiration = new Date(Date.now() + 60_000);
const payload = Base16.encode("quickstart");
const tx = new Transaction(nexus, chain, script, expiration, payload);
tx.signWithKeys(keys);
const txHash = await api.sendRawTransaction(tx.toString(true));
return txHash;
}3) Confirm the Result
Notes
Address.Nullis used as the gas target for normal transactions.payloadis a hex string; useBase16.encode.For frontend signing, use
PhantasmaLink.signTxinstead of signing locally.
Last updated