Icon SunFilledIcon MoonStars

Icon LinkCalling a script

Suppose your Sway script main function is written using the arguments passed to the main function like so:

script;
 
use std::logging::log;
 
fn main(foo: u8) -> u8 {
log("u8 foo");
log(foo);
foo
}

You can still hand code out a solution wrapper using callScript utility to call your script with data. However, if you prefer to use the ABI generated from your script, you can use the ScriptFactory helper:

const foo = 33;
const scriptInstance = new Script<BigNumberish[], BigNumberish>(scriptBin, scriptAbi, wallet);
 
const { value, logs } = await scriptInstance.functions.main(foo).call();

Was this page helpful?