How it works
- Cron trigger fires every minute
- CoinGecko API provides the current BTC/USD price
- On-chain contract receives the price via a typed contract class
- Collection stores the price for historical queries
Prerequisites
Project structure
Step 1: Set up the project
Clone the example repository:Step 2: Generate contract types
The project includes aPriceOracle.json ABI in src/contracts/. Generate the typed contract class:
PriceOracle class in .compose/generated/ that provides type-safe contract interaction.
Step 3: Understand the task
Thebitcoin-oracle.ts task handles everything:
Key Compose features used
context.fetch— HTTP requests with built-in retry and backoffevm.wallet— managed wallet with gas sponsorshipevm.contracts.PriceOracle— typed contract class generated from ABI JSON viacompose codegencollection— persistent document storage for price history
Step 4: Configure the Compose app
Thecompose.yaml uses a cron trigger to run every minute:
Step 5: Run locally
--fork-chains allows you to run a smart wallet locally. You can also use a private key wallet for your local Compose app. See more here.
The task runs immediately and then every minute. You should see logs showing the fetched price and transaction hash.
Step 6: Deploy to Goldsky
Customization
Change the price source
Replace the CoinGecko URL with any API that returns a JSON price:Use your own contract
- Drop your contract’s ABI JSON into
src/contracts/MyContract.json - Run
goldsky compose codegento generate the typed class - Use it in your task: