Invoke a Script

Before Invoking a Script, learn how to create one, here.

Also you need to know how to setup the PhantasmaAPI, to be able to call it Check it Here.

import { PhantasmaAPI, ScriptBuilder } from "phantasma-sdk-ts";
const CHAIN_NAME = "main";
const NETWORK_API_URL = "https://testnet.phantasma.info/rpc";
const NETWORK_PEER_URL = undefined;
const NEXUS_NAME = "testnet"; // For mainnet use this "mainnet"

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

async function GetMasterCount(){
    let sb = new ScriptBuilder();
    let script = sb
        .CallContract("stake", "GetMasterCount", []) 
        .EndScript();

    let myScript = sb.str;

    let txResult = await RPC.invokeRawScript(CHAIN_NAME, myScript);
    // this will return the data in a VMObject in Base16, you need to decode it.
    return txResult;
}

Last updated