6. Run your service
This tutorial uses the wavs-foundry-template and its Taskfile-based workflow. Real-world WAVS projects may use different tooling and project structures.
Local: Start Anvil, WAVS, and deploy service manager
- Create a
.envfile for your project by copying over the example with the following command:
cp .env.example .env
- Use the following command to start an Anvil test chain, IPFS, Registry, and some optional telemetry. This only runs with
LOCALbeing set in the.env(default).
task -y start-all-local
The command must remain running in your terminal. Open another terminal to run other commands.
You can stop the services with ctrl+c. Some MacOS terminals require pressing this twice.
With the chain running, you can deploy and run your service.
Deploy
Run the following single command to automate the complete WAVS deployment process:
task deploy-full
This handles everything end-to-end:
- Creating a deployer account and funding it
- Deploying the PoA service manager contract
- Deploying the trigger and submission Solidity contracts
- Uploading the compiled WASI component
- Building and uploading the service manifest to IPFS
- Starting the aggregator and registering the service with it
- Starting WAVS and deploying the service
- Registering operators with the service manager
When complete, a deployment summary is written to .docker/deployment_summary.json with the deployed contract addresses.
Trigger the service
Next, use your deployed trigger contract to trigger the oracle to be run. In the following command, you'll specify the INPUT_DATA as abi encoded 1, which corresponds to the ID of Bitcoin.
Running this command will execute /src/script/Trigger.s.sol and pass the ID to the trigger contract, starting the following chain of events:
- The trigger contract will emit an event with the specified ID as its data.
- Operators listening for the event will receive the data and run it in the oracle component off-chain.
- The oracle component will use the ID to query the price of Bitcoin from the CoinMarketCap API.
- The returned data will be signed by operators and passed to the aggregator and then the submission contract, which will verify the operator's signature and submit the price of Bitcoin on-chain 🎉
# Get the trigger address from the deployment summaryexport SERVICE_TRIGGER_ADDR=`jq -r '.evmpriceoracle_trigger.deployedTo' .docker/deployment_summary.json`export RPC_URL=`task get-rpc`export FUNDED_KEY=`task config:funded-key`# Request BTC price from CoinMarketCap (ID=1)export INPUT_DATA=`cast abi-encode "addTrigger(string)" "1"`forge script ./src/script/Trigger.s.sol ${SERVICE_TRIGGER_ADDR} ${INPUT_DATA} --sig 'run(string,string)' --rpc-url ${RPC_URL} --broadcast --private-key ${FUNDED_KEY}
Show the result
Run the following to view the result of your service in your terminal:
export SERVICE_SUBMIT_ADDR=`jq -r '.evmpriceoracle_submit.deployedTo' .docker/deployment_summary.json`RPC_URL=${RPC_URL} forge script ./src/script/ShowResult.s.sol ${SERVICE_SUBMIT_ADDR} 1 --sig 'data(string,uint64)' --rpc-url ${RPC_URL}
Congratulations, you've just made a simple Bitcoin price oracle service using WAVS!
Proceed to the Prediction Market demo to learn how a similar oracle service can be used in a prediction market.
Check out the Service handbook to learn more about services and creating components.
