Skip to main content
Version: Mainnet

Tutorial

info

All the codebase used in the tutorial can be explored here

In this tutorial, we will be exploring the process of verifying proofs using Relayer.

note

Before starting the tutorial make sure to update your Node JS to the latest version (v24.1.0) You can check your Node JS version with command node -v

Let's create a new project and install axios for our project. Run the following commands:

Create a new directory:

mkdir proof-submission

Navigate to the project directory:

cd proof-submission

Initialize an NPM project:

npm init -y && npm pkg set type=module

Install axios and dotenv:

npm i axios dotenv

Let's create a .env file to store our API_KEY, which will be used later to send proofs for verification using Relayer. Use the following code snippet to fill up your .env file. To use the relayer you need an API Key. Create your own API key by signing up here for mainnet.

API_KEY = "generate your API key"

Create a new file named index.js as the entrypoint for our application. Open index.js in your IDE and start with import necessary packages :

import axios from "axios";
import fs from "fs";
import dotenv from "dotenv";
dotenv.config();

After this let's initialize our API URL.

For mainnet:

const API_URL = "https://relayer-api-mainnet.horizenlabs.io/api/v1";

API Documentation

Swagger docs are available for both environments and provide detailed information about each endpoint, expected payloads, and responses. Refer to them when integrating or debugging your API calls: https://relayer-api-mainnet.horizenlabs.io/docs


We would also need to import the required files we have generated already in previous tutorials, which are proof, verification key and public inputs. Use the following code snippets:

const proof = JSON.parse(fs.readFileSync("./data/proof.json"));
const publicInputs = JSON.parse(fs.readFileSync("./data/public.json"));
const key = JSON.parse(fs.readFileSync("./data/main.groth16.vkey.json"));
info

Next we will be writing the core logic to send proofs to zkVerify for verification. All the following code snippets should be inserted within async main function.

async function main() {
// Required code
}

main();

Once you have all the requirements imported, we will start by registering our verification key. We can do this by calling a GET endpoint named register-vk on our relayer service. We will also need to create a params object with all the necessary information about the verification key, which will be sent in the API call. Once we register the verification key, we will store the vkHash in a json file which can be used in subsequent API verification calls.

if(!fs.existsSync("circom-vkey.json")) {
try {
const regParams = {
"proofType": "groth16",
"proofOptions": {
"library": "snarkjs",
"curve": "bn128"
},
"vk": key
}
const regResponse = await axios.post(`${API_URL}/register-vk/${process.env.API_KEY}`, regParams);
fs.writeFileSync(
"circom-vkey.json",
JSON.stringify(regResponse.data)
);
} catch(error) {
fs.writeFileSync(
"circom-vkey.json",
JSON.stringify(error.response.data)
);
}
}
const vk = JSON.parse(fs.readFileSync("circom-vkey.json"));

After registering our verification key, we will start the verification process by calling a POST endpoint named submit-proof. We will also need to create a params object with all the necessary information about the proof and the vkHash we got after registering our verification key, which will be sent in the API call. If you want to aggregate the verified proof (want to verify the proof aggregation on connected chains like Sepolia, Base Sepolia, etc.) check the code snippets with aggregation.

const params = {
"proofType": "groth16",
"vkRegistered": true,
"proofOptions": {
"library": "snarkjs",
"curve": "bn128"
},
"proofData": {
"proof": proof,
"publicSignals": publicInputs,
"vk": vk.vkHash || vk.meta.vkHash
}
}

const requestResponse = await axios.post(`${API_URL}/submit-proof/${process.env.API_KEY}`, params)
console.log(requestResponse.data)

After sending the verification request to the relayer, we can fetch the status of our request using the jobId returned in the response of the previous API call. To get the status, we will be making a GET API call to job-status endpoint. We want to wait till our proof is finalized on zkVerify, thus we will run a loop waiting for 5 seconds between multiple API calls.

if (requestResponse.data.optimisticVerify !== "success") {
console.error("Proof verification, check proof artifacts");
return;
}

while(true) {
const jobStatusResponse = await axios.get(`${API_URL}/job-status/${process.env.API_KEY}/${requestResponse.data.jobId}`);
if(jobStatusResponse.data.status === "Finalized"){
console.log("Job finalized successfully");
console.log(jobStatusResponse.data);
break;
}else{
console.log("Job status: ", jobStatusResponse.data.status);
console.log("Waiting for job to finalize...");
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait for 5 seconds before checking again
}
}

Next run this script by running node index.js command. You should get a response similar to the following:

{
jobId: '23382e04-3d57-11f0-af7b-32a805cdbfd3',
optimisticVerify: 'success'
}
Job status: Submitted
Waiting for job to finalize...
Job status: IncludedInBlock
Waiting for job to finalize...
Job status: IncludedInBlock
Waiting for job to finalize...
Job finalized successfully
{
jobId: '23382e04-3d57-11f0-af7b-32a805cdbfd3',
status: 'Finalized',
statusId: 4,
proofType: 'groth16',
chainId: null,
createdAt: '2025-05-30T13:08:11.000Z',
updatedAt: '2025-05-30T13:08:27.000Z',
txHash: '0xc0d85e5d50fff2bb5d192ee108664878e228d7fc3c1faa2d23da891832873d51',
blockHash: '0xcd574432b1a961305bbeb2c6b6ef399e1ae5102593846756cbb472bfd53d7d43',
transactionDetails: {}
}

In this example, we demonstrated how to wait for "Finalized" status for our proof verification. There are multiple proof status you can wait for. You can check all the available statuses here.

Resources

  1. Submit feedback or an issue: Relayer API: Feedback

  2. Submit a new feature request: Relayer API: New Feature Requests

  3. Reach out to us on Discord or relayer-support@horizenlabs.io if you would like to discuss potential partnerships.