Circuit Functions

Most commonly used AxiomREPL functions

witness

This function creates a CircuitValue that can change between different runs of the circuit (think of it as a JavaScript let). For example, if you wanted to create a circuit that checks if a user's balance is above some threshold, you would make the user's address a witness so that the circuit could be used to prove that any address's balance is above the threshold.

/**
 * Creates a circuit variable from a number, bigint, or string.
 *
 * @param a - The raw circuit input.
 * @returns The witness cell.
 */
witness: (a: number | bigint | string) => CircuitValue;

constant

This function creates a CircuitValue that must be the same every time you run your circuit (think of it as JavaScript const). For example, from the example above, you could make the threshold a constant to enforce that every time the circuit is run, the same threshold is used.

/**
 * Creates a circuit constant from a number, bigint, or string.
 *
 * @param a - The raw circuit input.
 * @returns The constant cell.
 */
constant: (a: number | bigint | string) => CircuitValue;

log

The log(...) function is used to debug the value of a CircuitValue or a CircuitValue256 (or some array of them). This is useful for debugging and checking that the values inside the circuit are what you would expect.

/**
 * Logs the provided *circuit* values to the console. 
 * Use `console.log` for normal logging.
 *
 * @param args - The values to log (can be `CircuitValue`s or `CircuitValue256`s).
 */
log: (...args: (CircuitValue | CircuitValue256)[]) => void;

addToCallback

This function is used to add a values to the data which is passed to your contract when your query is fulfilled. You can call addToCallback a maximum of 128 times inside AxiomREPL. See Handling Axiom Callbacks for more info on setting up your contract to receive the the data you pass to addToCallback.

/**
 * Adds a circuit value to the callback. 
 * Values passed to this function will be passed to your
 * callback client contract on-chain by Axiom.
 *
 * @param a - The circuit value to add to the callback.
 */
addToCallback: (a: CircuitValue | CircuitValue256) => void;

Last updated