Invoking a Script
Note
Current SDK source exposes the invoke-script methods used below. The call reads chain state and does not submit a transaction.
Invoking a Script
Note
invokeRawScript reads chain data without changing state. The arguments go in an array.
To do it using the PhantasmaAPI check this example
Using Phantasma Link
This example is using the PhantasmaLink
Invoking a Script doesn’t need the user to accept anything.
import { PhantasmaLink, ScriptBuilder } from "phantasma-sdk-ts/public";
const CHAIN_NAME = "main"; // This is the name of the chain, please don't change it.
let contractName = "mycontract";
let contractMethod = "getMyInfo";
let args = ["arg1", "arg2"]; // this is just a example of arguments.
const Link = new PhantasmaLink("My Dapp", true);
Link.login(
(success) => {
if (!success) return;
const sb = new ScriptBuilder();
const myScript = sb.beginScript()
.callContract(contractName, contractMethod, args)
.endScript();
Link.invokeScript(myScript, (result) => {
// Handle the Data returned here.
});
},
(error) => {
console.error("Login failed:", error);
},
4,
"phantasma",
"poltergeist"
);