A Ponder-based indexer that monitors the RandomnessSequencer contract and automatically triggers randomness generation using Lit Protocol.
This indexer watches for transactions that require randomness and automatically:
- Detects
MempoolUpdatedevents from the RandomnessSequencer - Generates verifiable randomness using Lit Protocol's PKP (Programmable Key Pair)
- Injects the randomness into the system
- Triggers the mempool flush to process queued transactions
The indexer uses Ponder to watch the RandomnessSequencer contract on the sequencing chain.
When a randomness request is detected:
- Lit Action executes to generate random data
- PKP signs the randomness transaction
- Transaction is submitted to both chains:
- Random value to the Random contract (appchain)
- Trigger to the RandomnessSequencer (sequencing chain)
- Node.js >= 18.14
- Bun (recommended) or npm/yarn
- Deployed RandomnessSequencer contract
- Deployed Random contract
- Lit Protocol PKP with appropriate permissions
npm install
# or
bun installCopy and configure the environment file:
cp .env.example .envRequired variables:
# Chain Configuration
SEQUENCING_CHAIN_ID=<chain-id>
SEQUENCING_CHAIN_RPC_URL=<sequencing-chain-rpc-url>
APPCHAIN_RPC_URL=<appchain-rpc-url>
APPCHAIN_CHAIN_ID=<chain-id>
# Contract Addresses
RANDOMNESS_SEQUENCER_CONTRACT_ADDRESS=<sequencer-address>
RANDOM_CONTRACT_ADDRESS=<random-address>
# Lit Protocol
LIT_PKP_PUBLIC_KEY=<pkp-public-key>
LIT_PKP_ETH_ADDRESS=<pkp-eth-address>
# Private Keys (for development/testing)
LIT_CAPACITY_CREDIT_TOKEN_ID=<capacity-credit-token-id>The indexer requires a Lit Protocol PKP (Programmable Key Pair) to sign randomness transactions.
npm run mintPkp
# or
bun run mintPkpThis will:
- Create a new PKP on the Lit network
- Output the PKP public key and ETH address
- Store the PKP info for later use
Important: Save the PKP details and update your .env file with:
LIT_PKP_PUBLIC_KEYLIT_PKP_ETH_ADDRESS
The PKP needs native tokens on both chains to send transactions. Send ETH to the LIT_PKP_ETH_ADDRESS on both the sequencing chain and appchain.
The PKP needs the RANDOM_ADMIN_ROLE on both contracts. From the contracts directory, run:
# Grant RANDOM_ADMIN_ROLE on RandomnessSequencer (sequencing chain)
make add-randomness-sequencer-admin
# Grant RANDOM_ADMIN_ROLE on Random (appchain)
make add-random-adminStart the indexer in development mode with hot reloading:
npm run dev
# or
bun run devStart the indexer in production mode:
npm run start
# or
bun run startAccess the Ponder database CLI:
npm run db
# or
bun run dbTest the Lit Protocol integration without running the full indexer:
npm run doLit
# or
bun run doLitThis will:
- Connect to Lit Protocol
- Execute the randomness generation action
- Output the generated transaction
- Exit without sending it
The indexer listens for MempoolUpdated events:
ponder.on("RandomnessSequencer:MempoolUpdated", async (event) => {
// Generate randomness via Lit Protocol
const { sequencerTransaction } = await getLitRandomnessSequencerTransaction()
// Send to sequencing chain
const hash = await risaPublicClient.sendRawTransaction({
serializedTransaction: sequencerTransaction,
})
})The Lit Action performs several tasks:
- Fetches random data from Drand (distributed randomness beacon)
- Generates the transaction to update the Random contract
- Generates the transaction to trigger the RandomnessSequencer
- Signs both transactions using the PKP
- Returns the signed transactions to the indexer
- Trigger: User transaction requiring randomness is detected
- Event: RandomnessSequencer emits
MempoolUpdated - Listen: Indexer receives event via Ponder
- Generate: Lit Action creates and signs randomness transactions
- Inject: Indexer submits transactions to both chains
- Process: RandomnessSequencer processes randomness and flushes mempool
npm run lint
# or
bun run lintnpm run typecheck
# or
bun run typecheckRegenerate Ponder types and ABIs:
npm run codegen
# or
bun run codegenThe indexer logs important events:
Generating randomness...
Randomness injection sent to sequencer: 0x1234...
Errors are logged with details:
Error sending transaction: <error details>
- Ensure the PKP has enough native tokens on both chains
- Verify the PKP has
RANDOM_ADMIN_ROLEon both contracts (see Grant PKP Permissions section)
- Check your Lit capacity credit token ID is valid
- Ensure you're using the correct Lit network (testnet vs mainnet)
- Verify the
RANDOMNESS_SEQUENCER_CONTRACT_ADDRESSis correct - Check the contract is deployed on the correct chain
- Ensure the indexer started from the correct block
MIT License - see LICENSE file for details