A simple updater service that fetches new randomness from drand and updates the Drand Oracle contract.
The updater service is a simple Golang application that:
- Connects to a Ethereum network via an RPC client.
- Subscribes to a Drand randomness feed.
- Sets up a listener for new randomness rounds.
- Sets up a catch-up mechanism to update the Drand Oracle contract with historical randomness based on the latest round information from the Drand Oracle contract.
- Sends a transaction to the Drand Oracle contract to update the randomness.
Note that if the Drand Oracle contract is not yet tracking rounds, the updater will start submitting randomness updates from the genesis round defined in the configuration by GENESIS_ROUND
environment variable.
Pull the Docker image from the GitHub Container Registry or build it locally using the Dockerfile
.
The updater requires the following environment variables:
DRAND_URLS
: A list of Drand URLs.CHAIN_HASH
: The Drand chain hash.DRAND_ORACLE_ADDRESS
: The address of the Drand Oracle contract.RPC
: The RPC URL.CHAIN_ID
: The chain ID.SET_RANDOMNESS_GAS_LIMIT
: The gas limit for the setRandomness transaction.SIGNER_PRIVATE_KEY
: The private key of the signer.SENDER_PRIVATE_KEY
: The private key of the sender.GENESIS_ROUND
: The genesis round.
Let's start by setting up the local development environment. For this, we'll:
- Use Anvil to run a local Ethereum chain.
- Deploy the Drand Oracle contract to the local chain.
- Run the updater service against the local chain.
- Watch the updater service submit randomness updates to the Drand Oracle contract.
Note that signer and sender private keys are provided by Anvil and hard-coded in the Makefile
. Do not use these keys in production.
anvil
Go to the contracts
directory and run:
make deploy-anvil
Go to the updater
directory and run:
make local-run-anvil