- New project: scaffold a Foundry starter that already includes an example consumer contract.
- Existing project: wire the hosted roll.codes coordinator into your current Solidity app.
New projects
The starter CLI generates a Foundry project with:src/DiceDuelConsumer.soltest/DiceDuelConsumer.t.solscript/DeployDiceDuelConsumer.s.sol- remappings and Foundry config for Abstract
requestRandomNumberWithTraceId(...) and receives it in randomNumberCallback(...).
1
Build the starter CLI
The CLI source currently lives in this repository.
2
Scaffold a starter project
Run the generator from the CLI package directory:This creates
./my-game with the example consumer already wired to the public IVRFSystem interface.3
Build and test the generated project
4
Configure the hosted coordinator and deploy
- Abstract testnet
- Abstract mainnet
Integrating into an existing project
Use this path if you already have a Foundry project and only need to add roll.codes support.1
Install the dependency
2
Add remappings
Your project should include:
3
Request a random number
Import the public interfaces, store the hosted coordinator address, then request randomness by paying
requestFee().4
Handle the callback safely
Every request is delivered asynchronously. Restrict the callback to the hosted coordinator and settle against stored request state.
5
Deploy only your consumer
Set the hosted coordinator address for the same network as your RPC URL:Then deploy your own consumer contract with your normal Foundry script flow, using
- Abstract testnet
- Abstract mainnet
--account deployer when you broadcast.requestRandomNumberWithTraceId is payable on roll.codes, so callers must send the exact value returned by requestFee().randomNumber. If your app needs a unique value per request within that same round, derive one locally from requestId and randomNumber.
Verify the result
You should end with:- a deployed consumer contract
- a configured roll.codes coordinator address in your deployment inputs
- a request path that pays
requestFee() - a callback that only accepts the hosted coordinator
Next steps
Integration pattern
Copy a fuller consumer example with request storage and settlement guards.
Coordinator reference
Keep the request function, fee call, and callback interface beside you while implementing.
Troubleshooting
Fix fee mismatches, unauthorized callbacks, and pending requests.
CLI reference
Review the starter generator flags and output files.