Skip to content

callMethod

callMethod invokes a method on an existing on-chain component — for example, withdrawing tokens from an account or depositing into a vault.

builder.callMethod(
{
componentAddress: accountAddress,
methodName: "withdraw",
},
[{ Literal: resourceAddress }, { Literal: "500" }],
);

If the component was created earlier in the same transaction and saved with saveVar, you can reference it by workspace name:

builder
.callFunction({ templateAddress, functionName: "new" }, [literalArg("init")])
.saveVar("component")
.callMethod(
{
fromWorkspace: "component",
methodName: "do_something",
},
[{ Literal: "arg1" }],
);

The first argument is a TariMethodDefinition:

interface TariMethodDefinition {
methodName: string;
componentAddress?: string; // Call by address
fromWorkspace?: string; // Call by workspace key (mutually exclusive)
}

One of componentAddress or fromWorkspace must be provided. The builder throws if neither is set.