- Cron job scheduling in the github actions workflows have been commented
out. To resume scheduled runs, uncomment the
scheduleblock in the workflow files.
This repository contains examples of how to use the Blocky Attestation Service (Blocky AS) to create TEE attestations over API data and offchain computation. The examples are designed to be easy to understand and modify, so you can use them as a starting point for your own projects.
Here's a list of the examples in this repository. If you're new to Blocky AS, we recommend working though these examples in the following order:
- Attesting a Function Call shows
you how to use Blocky AS to attest simple function calls: You'll learn how to:
- Create a function that returns a
"Hello, World!"message - Invoke functions in the Blocky AS using its
bky-asCLI - Extract function output from the Blocky AS attestation
- Create a function that returns a
- Bringing A Blocky AS Function Call Attestation On Chain
shows you how to bring a Blocky AS function call attestation on chain. You'll
learn how to:
- Write a smart contract to verify and parse a function call attestation
- Test the smart contract locally
- Error Handling - Attested Function Calls
shows you how to handle errors in your
Blocky AS functions. You'll learn how to:
- Use the result pattern in your function
- Return structured data from your function
- Report errors from your function
- Log errors in your function
- Random shows you how to generate random numbers in your Blocky AS
functions. You'll learn how to:
- Generate random numbers in the Blocky AS runtime
- Create a function that returns a random number within a given range
- Time shows you how to retrieve the wall clock time in your Blocky AS functions.
- Getting Coin Prices From CoinGecko shows you
how to use Blocky AS to fetch and process coin price data from the CoinGecko
API. You'll learn how to:
- Pass in parameters and secrets to your function
- Make an HTTP request to an external API in your function
- Parse a JSON response from an API
- Getting Esports Data From PandaScore shows you how to use Blocky AS to attest and process esports data from the PandaScore API.
- Getting Esports Data From Rimble shows you how to use Blocky AS to attest and process esports data from the Rimble API. PandaScore API.
- Tracking a Shipment with DHL shows you how to use Blocky AS to track a shipment using the DHL API.
- Time Weighted Average Price is a more advanced example that shows you how to calculate the time weighted average price of an asset through iterative calls to Blocky AS.
To learn more about Blocky AS, check out our documentation.
Examples are tested using the testscript library and scripts in
/test/scripts. See
here for an
overview of the library.
Many examples rely on secrets or configuration to run. For testing, these
are provided as environment variables. The tests will notify you if any
required environment variables are missing. Review the _test.go files in
/test for the required variables and provide them in your shell when
running tests.
For example:
LIVE_TEST_PLATFORM=nitro \
LIVE_TEST_CODE=${MEASURE} \
LIVE_TEST_AUTH_TOKEN=${TYK_API_DEV_KEY} \
LIVE_TEST_HOST="https://api.bky.sh/staging/delphi" \
YOUR_COINGECKO_API_KEY=${COINGECKO_API_DEV_KEY} \
make test-liveWe use nix to manage our development and CI environment.
- Use
--argstr bkyAsVersionto specify the version of thebky-asCLI. - Use
--pureto run the shell in pure mode to prevent environment variables from leaking into the nix shell.- Pass env variables to the shell using the
--runflag, or export them once inside the shell. - To preserve env variables from your current shell, do not use the
--pureflag.
- Pass env variables to the shell using the
For example, using nix-shell to run tests in pure mode:
nix-shell \
--pure \
--argstr bkyAsVersion "latest" \
--run "\
YOUR_COINGECKO_API_KEY=${COINGECKO_API_DEV_KEY} \
YOUR_PANDASCORE_API_ENDPOINT=${PANDASCORE_API_DEV_ENDPOINT} \
YOUR_PANDASCORE_API_KEY=${PANDASCORE_API_DEV_KEY} \
YOUR_RIMBLE_API_KEY=${RIMBLE_API_DEV_KEY} \
YOUR_DHL_API_KEY=${DHL_API_DEV_KEY} \
YOUR_SPORTRADAR_API_KEY=${SPORTRADAR_API_DEV_KEY} \
make test"