Skip to content

Calling other smart functions

Smart functions can call other smart functions with the SmartFunction.call() method, which returns a promise that resolves to a Jstz Response object. Here is an example of calling another contract:

typescript
const targetContract: Address = "KT1L8ZzGDzaXZSTmzHkoF2azQRf7dCAfxtqx";

const response = await SmartFunction.call(
  new Request(`jstz://${targetContract}`, {
    method: "POST",
    body: JSON.stringify({ message: "hello" }),
  }),
);
console.log(await response.json());

The URL for the Request object must be jstz:// followed by the address of a Jstz smart function. Smart functions cannot call external APIs or Tezos smart contracts directly. You can set the method in the Request object but you cannot set the Referer header because it automatically becomes the address of the smart function.

:::

Failed calls to smart functions cause Jstz to immediately revert the current transaction. See Handling errors.

:::