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 installed via npm, yarn, or pnpm. 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. To use third-party packages:
  1. Install packages with your preferred package manager (npm install, yarn add, etc.)
  2. Import using bare specifiers in your task files (e.g. import { keccak256 } from "viem")
Packages must be installed in node_modules/ since esbuild resolves imports from there. Deno-style npm: specifiers are not supported in task files.
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

import { TaskContext } from "compose";

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

export async function main({ evm, env }: TaskContext) {
  // 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

Debugging

Debug and monitor your apps

Deploying your App

Learn about deploying your app to the cloud for production use cases.