Skip to main content

Overview

Compose apps are bundled with esbuild and run in secure, auditable sandboxes. The sandboxes will disallow os, filesystem and direct networking activity. To make external http requests, you have to use the provided fetch function. This allows compose apps to be fully auditable, trusted and secure. Compose apps are bundled with esbuild when you run and deploy them, this means you can use any packages with any standard package manager and import from those packages into your task files. However things like native nodejs packages, or packages that rely on filesystem or http access will not work, due to the nature of the sandbox. This will also be the case for Apps running in TEEs in the future. This means you can import libraries like viem for more customized functionality, keep in mind though if you use http-enabled functions from viem you’ll need to specify a custom transport using the built in compose fetch. Otherwise though, you can easily use lots of utility functions like you would in any typescript app.

Example

/// <reference types="../../.compose/types.d.ts" />

import {
  concat,
  keccak256,
  Address,
  Hex,
  pad,
  stringToHex,
  numberToHex,
} from "viem";

export async function main(
  { evm, env }: TaskContext,
  _args: any
) {
  // do some logic that calls viem utilities
  const resultId = keccak256(
    concat([
      stringToHex(assetPair === AssetPair.TEST ? "TEST1" : CHAINLINK_CANDLE_IDENTIFIER, { size: 32 }),
      stringToHex(assetPair, { size: 32 }),
      numberToHex(durationInSeconds, { size: 32 }),
      numberToHex(startTimestamp, { size: 32 }),
    ])
  );

  console.log(resultId);
}

Next Steps