compose
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGoldsky Compose
Goldsky Compose
Goldsky Compose is the offchain-to-onchain framework for high-stakes systems. Write TypeScript tasks that run in verifiable sandboxes — triggered by cron, HTTP, or onchain events — with smart wallets, gas sponsorship, and durable collections. Typical use cases: custom price oracles, keepers, circuit breakers, prediction-market resolvers, cross-chain automation, identity/attestation flows, and notifications.
Goldsky Compose是面向高风险系统的链下转链上框架。编写TypeScript 任务,这些任务可在可验证沙箱中运行——由cron、HTTP或链上事件触发——并支持智能钱包、gas赞助和持久化集合。典型用例包括:自定义价格预言机、keeper、断路器、预测市场解析器、跨链自动化、身份/认证流程以及通知服务。
Boundaries
使用边界
- Build new Compose apps or explain what Compose is. For debugging a broken app, use .
/compose-doctor - Do not serve as a manifest / CLI / API reference. For field syntax, flag lookups, or TaskContext shapes, use .
/compose-reference - For , use
goldsky login. For generic secret management, use/auth-setup./secrets
- 用于构建新的Compose应用或解释Compose是什么。如需调试故障应用,请使用。
/compose-doctor - 不充当清单/CLI/API参考工具。如需查询字段语法、标志或TaskContext结构,请使用。
/compose-reference - 如需执行,请使用
goldsky login。如需通用密钥管理,请使用/auth-setup。/secrets
Mode Detection
模式检测
Before running commands, check if the tool is available:
Bash- If Bash is available (CLI mode): use the Walk Me Through It section below to execute commands directly and parse output.
- If Bash is NOT available (reference mode): the Quickstart below is enough for most chatbot Q&A. For step-by-step help, output one command at a time and ask the user to paste output back.
在执行命令前,请检查是否可用工具:
Bash- 如果Bash可用(CLI模式):使用下方的“逐步引导”部分直接执行命令并解析输出。
- 如果Bash不可用(参考模式):下方的快速入门指南足以应对大多数聊天机器人问答场景。如需分步帮助,请每次输出一条命令,并要求用户粘贴返回的输出内容。
What Compose Does
Compose的功能
- Serverless TypeScript runtime for EVM-aware tasks.
- Three trigger types: cron, HTTP, onchain_event.
- Smart wallets (managed by Goldsky, gas-sponsored by default) or BYO EOA wallets (user-supplied private key).
- Built-in secrets, collections (durable storage), typed contract bindings via codegen.
- for hot-reload local dev;
compose devto ship;compose deployto tail.compose logs -f
- 支持EVM感知任务的无服务器TypeScript运行时。
- 三种触发类型:cron、HTTP、onchain_event。
- 智能钱包(由Goldsky托管,默认启用gas赞助)或自备EOA钱包(用户提供私钥)。
- 内置密钥管理、集合(持久化存储)、通过代码生成实现类型化合约绑定。
- 使用进行热重载本地开发;
compose dev部署应用;compose deploy查看实时日志。compose logs -f
Out of Scope (for this skill)
本技能的范围外内容
- Deploying the target onchain contract. Compose writes to contracts that already exist. If the user needs one deployed, direct them to Foundry / Hardhat first and resume here once they have the address + ABI.
- Sourcing a contract ABI. The user provides the ABI JSON file; this skill does not fetch from Etherscan / Sourcify.
- Funding a BYO EOA. If sponsorship is off, the user must fund the address out-of-band.
- 部署目标链上合约:Compose仅与已存在的合约交互。如果用户需要部署合约,请先引导他们使用Foundry / Hardhat,待获取合约地址和ABI后再继续使用本技能。
- 获取合约ABI:用户需提供ABI JSON文件;本技能不会从Etherscan / Sourcify获取ABI。
- 为自备EOA充值:如果关闭gas赞助,用户必须通过其他方式为地址充值。
Quickstart
快速入门
Install
安装
bash
curl https://goldsky.com | sh
goldsky loginbash
curl https://goldsky.com | sh
goldsky loginScaffold + deploy
初始化并部署
bash
goldsky compose init <app-name> # scaffolds a Bitcoin-oracle example
cd <app-name>
goldsky compose dev # hot-reload local server on :4000
goldsky compose deploy # bundle + upload to cloud
goldsky compose status # expect RUNNING
goldsky compose logs -f # stream logsbash
goldsky compose init <app-name> # 初始化一个比特币预言机示例
cd <app-name>
goldsky compose dev # 在:4000端口启动热重载本地服务器
goldsky compose deploy # 打包并上传至云端
goldsky compose status # 预期状态为RUNNING
goldsky compose logs -f # 流式查看日志Minimal compose.yaml
+ task
compose.yaml最简compose.yaml
及任务
compose.yamlyaml
undefinedyaml
undefinedcompose.yaml
compose.yaml
name: my-oracle
api_version: stable
secrets:
- ORACLE_ADDRESS tasks:
- name: hourly_update
path: src/tasks/hourly-update.ts
triggers:
- type: cron expression: "0 * * * *"
```ts
// src/tasks/hourly-update.ts
import type { TaskContext } from "compose";
export async function main({ evm, env, logEvent }: TaskContext) {
const wallet = await evm.wallet({ name: "updater" });
const tx = await wallet.writeContract(
evm.chains.polygonAmoy,
env.ORACLE_ADDRESS,
"update(uint256)",
[BigInt(Date.now())],
{ confirmations: 3, onReorg: { action: { type: "replay" }, depth: 200 } },
);
await logEvent({ code: "updated", message: "ok", data: { hash: tx.hash } });
}name: my-oracle
api_version: stable
secrets:
- ORACLE_ADDRESS tasks:
- name: hourly_update
path: src/tasks/hourly-update.ts
triggers:
- type: cron expression: "0 * * * *"
```ts
// src/tasks/hourly-update.ts
import type { TaskContext } from "compose";
export async function main({ evm, env, logEvent }: TaskContext) {
const wallet = await evm.wallet({ name: "updater" });
const tx = await wallet.writeContract(
evm.chains.polygonAmoy,
env.ORACLE_ADDRESS,
"update(uint256)",
[BigInt(Date.now())],
{ confirmations: 3, onReorg: { action: { type: "replay" }, depth: 200 } },
);
await logEvent({ code: "updated", message: "ok", data: { hash: tx.hash } });
}Core Concepts
核心概念
Tasks
任务
A task is a TypeScript file exporting . Each task declares one or more triggers in .
async function main(context, params?)compose.yaml任务是一个导出的TypeScript文件。每个任务会在中声明一个或多个触发器。
async function main(context, params?)compose.yamlTriggers
触发器
| Type | Fires on | Key config |
|---|---|---|
| schedule | |
| HTTP POST to | |
| decoded log | |
| 类型 | 触发条件 | 关键配置 |
|---|---|---|
| 定时调度 | |
| 向 | |
| 解码后的日志 | |
TaskContext
TaskContext
Every task receives . Secrets flatten into — there is no separate namespace. See for the full API.
{ env, fetch, callTask, logEvent, evm, collection }context.envsecrets/compose-reference每个任务都会接收对象。密钥会扁平化到中——没有单独的命名空间。如需完整API,请查看。
{ env, fetch, callTask, logEvent, evm, collection }context.envsecrets/compose-referenceWallets
钱包
Two kinds:
- Smart wallet (managed) — . Hosted by Goldsky, gas-sponsored by default. Cannot be used in plain local dev — use
evm.wallet({ name: "updater" })or switch to a BYO EOA.compose dev --fork-chains - BYO EOA (private key) — . Gas sponsorship is OFF by default for BYO EOA wallets; opt in explicitly.
evm.wallet({ privateKey: env.MY_KEY, sponsorGas: true })
两种类型:
- 托管智能钱包 — 。由Goldsky托管,默认启用gas赞助。无法在纯本地开发中使用——需使用
evm.wallet({ name: "updater" })或切换至自备EOA钱包。compose dev --fork-chains - 自备EOA(私钥) — 。自备EOA钱包默认关闭gas赞助;需显式开启。
evm.wallet({ privateKey: env.MY_KEY, sponsorGas: true })
Secrets & env
密钥与环境变量
List names in the manifest's array, set values with (or to upload ). Values flatten into at runtime. Names must be SCREAMING_SNAKE_CASE.
secrets:goldsky compose secret set --name X --value Ycompose secret sync.envcontext.env在清单的数组中列出密钥名称,使用设置值(或使用上传文件)。运行时值会扁平化到中。名称必须为大写下划线命名(SCREAMING_SNAKE_CASE)。
secrets:goldsky compose secret set --name X --value Ycompose secret sync.envcontext.envGas sponsorship
Gas赞助
Bundler fallback: Alchemy → Pimlico → Gelato. Broad EVM coverage (mainnet + testnet); see for the chain list and caveats.
/compose-referenceBundler备选方案:Alchemy → Pimlico → Gelato。支持广泛的EVM链(主网+测试网);如需链列表和注意事项,请查看。
/compose-referenceDashboard
控制台
Every deployed app has a dashboard at .
https://app.goldsky.com/<project_id>/dashboard/compose/<app-name>每个已部署的应用都有对应的控制台,地址为。
https://app.goldsky.com/<project_id>/dashboard/compose/<app-name>Capability Tour
功能演示
Inline worked examples. Start with Cron → writeContract if you don't know which applies.
内嵌实战示例。如果不确定适用场景,请从Cron → writeContract开始。
Cron → writeContract (the scaffold default)
Cron → writeContract(初始化默认模板)
Exactly the minimal task above — a cron task that writes to a contract every hour, with for safety.
onReorg: replay正是上述最简任务——一个每小时向合约写入数据的cron任务,配置以确保安全性。
onReorg: replayHTTP task with auth_token
带auth_token的HTTP任务
yaml
undefinedyaml
undefinedcompose.yaml (task entry)
compose.yaml(任务条目)
- name: manual_fire
path: src/tasks/manual-fire.ts
triggers:
- type: http authentication: auth_token
```ts
// src/tasks/manual-fire.ts
import type { TaskContext } from "compose";
export async function main({ logEvent }: TaskContext, params: { amount: number }) {
await logEvent({ code: "fired", message: "manual", data: params });
return { ok: true, received: params.amount };
}Invoke: .
curl -X POST -H "Authorization: Bearer $TOKEN" -d '{"amount": 42}' https://<app-url>/tasks/manual_fire- name: manual_fire
path: src/tasks/manual-fire.ts
triggers:
- type: http authentication: auth_token
```ts
// src/tasks/manual-fire.ts
import type { TaskContext } from "compose";
export async function main({ logEvent }: TaskContext, params: { amount: number }) {
await logEvent({ code: "fired", message: "manual", data: params });
return { ok: true, received: params.amount };
}调用方式:。
curl -X POST -H "Authorization: Bearer $TOKEN" -d '{"amount": 42}' https://<app-url>/tasks/manual_fireOnchain event listener
链上事件监听器
yaml
- name: on_transfer
path: src/tasks/on-transfer.ts
triggers:
- type: onchain_event
network: polygon_amoy
contract: "0xYourContract"
events:
- "Transfer(address,address,uint256)"ts
import type { TaskContext } from "compose";
export async function main(
{ evm, logEvent }: TaskContext,
params: { log: { topics: string[]; data: string; address: string } },
) {
const decoded = await evm.decodeEventLog(
[{ type: "event", name: "Transfer", inputs: [/* ABI inputs */] }],
params.log,
);
await logEvent({ code: "transfer", message: "seen", data: decoded });
}yaml
- name: on_transfer
path: src/tasks/on-transfer.ts
triggers:
- type: onchain_event
network: polygon_amoy
contract: "0xYourContract"
events:
- "Transfer(address,address,uint256)"ts
import type { TaskContext } from "compose";
export async function main(
{ evm, logEvent }: TaskContext,
params: { log: { topics: string[]; data: string; address: string } },
) {
const decoded = await evm.decodeEventLog(
[{ type: "event", name: "Transfer", inputs: [/* ABI输入 */] }],
params.log,
);
await logEvent({ code: "transfer", message: "seen", data: decoded });
}Smart wallet + sponsored writeContract
智能钱包 + 赞助式writeContract
ts
const wallet = await evm.wallet({ name: "my-oracle" }); // sponsorGas defaults TRUE
const tx = await wallet.writeContract(
evm.chains.base,
env.FEED_ADDRESS,
"setPrice(uint256)",
[1234n],
);ts
const wallet = await evm.wallet({ name: "my-oracle" }); // sponsorGas默认开启
const tx = await wallet.writeContract(
evm.chains.base,
env.FEED_ADDRESS,
"setPrice(uint256)",
[1234n],
);BYO EOA with sponsored gas (opt-in)
带gas赞助的自备EOA(需显式开启)
ts
const wallet = await evm.wallet({
privateKey: env.MY_KEY,
sponsorGas: true, // MUST opt in; defaults FALSE
});ts
const wallet = await evm.wallet({
privateKey: env.MY_KEY,
sponsorGas: true, // 必须显式开启;默认关闭
});Durable storage (collection)
持久化存储(集合)
ts
const runs = await collection<{ id: string; ts: number }>("runs");
await runs.setById("latest", { id: "latest", ts: Date.now() });
const recent = await runs.findOne({ ts: { $gt: Date.now() - 86_400_000 } });ts
const runs = await collection<{ id: string; ts: number }>("runs");
await runs.setById("latest", { id: "latest", ts: Date.now() });
const recent = await runs.findOne({ ts: { $gt: Date.now() - 86_400_000 } });Typed contracts via codegen
通过代码生成实现类型化合约
Drop an ABI into . After (or any //), the contract is available as . Full workflow in .
src/contracts/Oracle.jsongoldsky compose codegeninitdevdeployevm.contracts.Oracle/compose-reference将ABI放入。执行(或任何//命令)后,合约可通过访问。完整流程请查看。
src/contracts/Oracle.jsongoldsky compose codegeninitdevdeployevm.contracts.Oracle/compose-referenceWalk Me Through It
逐步引导
Only activate when Bash is available.
仅当Bash可用时启用。
Step 1 — Verify auth
步骤1 — 验证认证状态
goldsky project list 2>&1/auth-setup执行。如果未登录,请使用。
goldsky project list 2>&1/auth-setupStep 2 — Derive first, ask only the ambiguous
步骤2 — 先推导,仅询问模糊信息
From the user's natural-language prompt, derive as many of these as possible before asking:
- Trigger type — "every 5 minutes" → cron; "on each Transfer" → onchain_event; "when I call it" → http.
- Chain — named (,
polygonAmoy) → use it; "testnet" with no name → ask.base - Read vs write — "track", "index", "notify" → read; "update", "set", "submit" → write.
- Wallet — write + sponsored gas → smart wallet (default); user supplied a PK → BYO EOA with .
sponsorGas: true - Secrets — any external API key or contract address → needs a secret entry.
- — default to
api_versionunless user asks otherwise.stable
Only ask the user for fields you couldn't derive.
从用户的自然语言请求中,推导尽可能多的信息,仅询问无法推导的内容:
- 触发器类型 — “每5分钟一次” → cron;“每次Transfer事件” → onchain_event;“我调用时触发” → http。
- 链 — 指定名称(、
polygonAmoy)→ 使用该名称;仅说明“测试网”但未指定名称 → 询问用户。base - 读取 vs 写入 — “跟踪”、“索引”、“通知” → 读取;“更新”、“设置”、“提交” → 写入。
- 钱包 — 写入操作 + gas赞助 → 智能钱包(默认);用户提供私钥 → 带的自备EOA。
sponsorGas: true - 密钥 — 任何外部API密钥或合约地址 → 需要添加密钥条目。
- — 除非用户特别要求,否则默认使用
api_version。stable
仅向用户询问无法推导的字段。
Step 3 — Scaffold
步骤3 — 初始化项目
goldsky compose init <name>执行。检查初始化后的项目结构,了解标准文件布局。
goldsky compose init <name>Step 4 — Edit the manifest
步骤4 — 编辑清单
Replace the scaffold's task block with the derived trigger + secret list. Use the YAML snippets from the Capability Tour above.
将初始化模板中的任务块替换为推导得到的触发器和密钥列表。使用上述功能演示中的YAML片段。
Step 5 — Write the task
步骤5 — 编写任务代码
Replace the scaffold's task file with logic derived from the prompt. Use the capability-tour snippet for the chosen trigger as the starting point.
将初始化模板中的任务文件替换为根据请求推导的逻辑。以所选触发器对应的功能演示片段为起点。
Step 6 — Wire secrets and wallets
步骤6 — 配置密钥和钱包
- Every name in 's
compose.yaml→secrets:(or add togoldsky compose secret set --name X --value Y+.env).compose secret sync - Smart wallet → . Then
goldsky compose wallet create --name <name>to get the address and share with the user (they may need to grant it onchain permissions on the target contract).wallet list - BYO EOA → add the private key to (SCREAMING_SNAKE_CASE name), reference via
.envin the task.env.X
- 的
compose.yaml中的每个名称 → 执行secrets:(或添加到goldsky compose secret set --name X --value Y文件并执行.env)。compose secret sync - 智能钱包 → 执行。然后执行
goldsky compose wallet create --name <name>获取地址并分享给用户(他们可能需要在链上为该地址授予目标合约的权限)。wallet list - 自备EOA → 将私钥添加到文件(使用大写下划线命名),在任务中通过
.env引用。env.X
Step 7 — Local dev
步骤7 — 本地开发
goldsky compose dev--fork-chainsgoldsky compose callTask <name> '<json>'执行。智能钱包在本地开发中需要;如果用户希望针对真实测试网测试,请使用自备EOA。对于HTTP任务:在另一个终端执行。
goldsky compose dev--fork-chainsgoldsky compose callTask <name> '<json>'Step 8 — Deploy
步骤8 — 部署应用
goldsky compose deploy执行。预期流程:“Building Dedicated app database…” → “Deploying app…” → “Provisioning infra…”(首次部署可能需要一两分钟)。
goldsky compose deployStep 9 — Verify
步骤9 — 验证部署
bash
goldsky compose status --json # expect .status == "RUNNING"
goldsky compose logs -f # expect app-specific log linesShare the dashboard URL: .
https://app.goldsky.com/<project_id>/dashboard/compose/<app-name>bash
goldsky compose status --json # 预期.status == "RUNNING"
goldsky compose logs -f # 预期看到应用特定的日志行分享控制台URL:。
https://app.goldsky.com/<project_id>/dashboard/compose/<app-name>Important Rules
重要规则
- Smart wallets don't work in plain — use
compose devor switch to a BYO EOA for local iteration.--fork-chains - BYO EOA gas sponsorship defaults to FALSE — opt in explicitly with .
sponsorGas: true - Cloud secrets are not synced from automatically. Run
.envorcompose secret sync.compose deploy --sync-env - Secret names must be SCREAMING_SNAKE_CASE.
- is required for deploy. Default to
api_version.stable
- 智能钱包无法在纯中使用 — 本地迭代需使用
compose dev或切换至自备EOA钱包。--fork-chains - 自备EOA的gas赞助默认关闭 — 需显式添加开启。
sponsorGas: true - 云端密钥不会自动从同步。需执行
.env或compose secret sync。compose deploy --sync-env - 密钥名称必须为大写下划线命名(SCREAMING_SNAKE_CASE)。
- 部署必须指定。默认使用
api_version。stable
Related
相关技能
- — Diagnose and fix broken Compose apps.
/compose-doctor - — Manifest, CLI, TaskContext API, wallets, gas sponsorship, codegen.
/compose-reference - —
/auth-setupwalkthrough.goldsky login - — Generic secret management.
/secrets
- — 诊断并修复故障Compose应用。
/compose-doctor - — 清单、CLI、TaskContext API、钱包、gas赞助、代码生成的参考文档。
/compose-reference - —
/auth-setup分步引导。goldsky login - — 通用密钥管理。
/secrets