In this Quickstart documentation, we'll be building an basic Next.js web app that implements an Axiom client-side prover to generate a ZK proof of a user's average account balance over the past
You'll need a key from Alchemy and a project ID from WalletConnect to place in your environmental variables. You can make a copy of and rename .env.local.example to .env.local:
Install required node.js packages with the following command:
Terminal
npminstall
AxiomREPL
We'll first build a circuit in AxiomREPL. AxiomREPL allows developers to specify data fetching and computation for their specific use cases. This circuit will be exported as a client-side prover that will run in the user's browser, with the values in the inputs panel (bottom) that will be overridden by values provided by the Next.js web app. We've included this AxiomREPL link with the code:
// Number of periods to run for; must be constant so circuit is deterministic
const periods = 10;
// Get the total account balance over the periods
let total = witness(0);
for (let i = 0; i < periods; i++) {
const targetBlock = sub(endBlock, mul(constant(i), blockInterval));
const bal = getAccount(targetBlock, user).balance().toCircuitValue();
total = add(total, bal);
}
// Divide by number of periods to get the average account balance
const avgBalance = div(total, constant(periods));
// Add the average account balance to the callback
addToCallback(avgBalance);