AxiomREPL Examples

Some additional examples of things that people have done with AxiomREPL to help kickstart your creativity.

Average Account Balance

The following code gets the average balance of an account over 25 periods with an interval of blockInterval blocks, ending at block endBlock (but counting back from that block).

let total = constant(0);
const periods = 25;
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);
const avg = div(total, constant(periods));
    "user": "0xe76a90E3069c9d86e666DcC687e76fcecf4429cF",
    "endBlock": 9900000,
    "blockInterval": 1000

Last updated