Comment on page
Client Circuit
The client circuit code
An Axiom Query is specified by writing a special Axiom client circuit using the Axiom Client SDK. We use it here to generate a circuit that proves our request for the parameters from the
Swap
event and the same transaction's to
field. The goal of writing the client circuit code in this section is to export it for use in our Web App that we'll build after this.
We have the following circuit inputs to our client circuit code. These inputs are variables that can be auto-parsed from the
blockNumber
, txIdx
, and logIdx
of a user's Swap
transaction that your web app provides. Circuit Inputs
export interface CircuitValueInputs {
blockNumber: CircuitValue;
txIdx: CircuitValue;
logIdx: CircuitValue;
}
Note: every transaction hash maps to a unique
blockNumber
and txIdx
combination.For example, the following can be parsed into
CircuitValueInputs
by the SDK:{
blockNumber: 9610835,
txIdx: 6,
logIdx: 3
}
The following code implements logic for getting blockchain data and running compute over that data.
Axiom Client Code
export const circuit = async ({ blockNumber, txIdx, logIdx }: CircuitValueInputs) => {
const eventSchema =
"0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67";
// specify and fetch the data you want Axiom to verify
let receipt = getReceipt(blockNumber, txIdx);
let receiptLog = receipt.log(logIdx); //get the log at index 3
// get the topic at index 0 (event schema)
let swapSchema = await receiptLog.topic(0, eventSchema);
// get the topic at index 2
let swapTo = await receiptLog.topic(2, eventSchema);
// get the block number for receipt
let blockNum = await receipt.blockNumber();
// get the `to` field of the transaction
let tx = getTx(blockNumber, txIdx);
let txTo = await tx.to();
addToCallback(swapSchema);
addToCallback(swapTo);
addToCallback(blockNum);
addToCallback(txTo);
};
Last modified 11d ago