storeBatchInAnchor
Stores a summary hash (typically a Merkle root, batchRoot) representing a large batch of commitments or data into the Anchor program. This is used for efficiently managing large, potentially periodic, datasets.
It's similar to storeMerkleRootInAnchor but often includes additional identifiers like batchId to distinguish different batches (e.g., "weekly data batch").
Parameters
| Parameter | Type | Description |
|---|---|---|
privateKeyBase58 | const String& | The private key of the account's authority. |
authorityPubkey | const String& | The public key of the authority. |
programId | const String& | The ID of the Anchor program to interact with. |
batchId | const String& | A unique identifier for this batch of data (e.g., "batch_10102025"). |
batchRoot | const String& | The Merkle root hash representing the entire batch. |
batchSize | uint32_t | The total number of data items (commitments) included in this batch. |
metadata | const String& | Metadata string to store alongside the batch root. |
outTxSignature | String& | Output: If successful, the signature of the transaction. |
Return Value
bool: Returnstrueif the batch data was stored successfully.
Example Code (main.cpp)
#include <Arduino.h>
#include <WiFi.h>
#include "Infratic-lib.h"
// --- WiFi Settings ---
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
// --- Solana Settings ---
const String SOLANA_RPC_URL = "[https://api.devnet.solana.com](https://api.devnet.solana.com)";
const String MY_PRIVATE_KEY_BASE58 = "YOUR_PRIVATE_KEY_BASE58";
const String MY_PUBLIC_KEY_BASE58 = "YOUR_PUBLIC_KEY_BASE58";
const String ZK_PROGRAM_ID = "YOUR_ANCHOR_PROGRAM_ID_HERE"; // Your Anchor program ID
Infratic solana(SOLANA_RPC_URL);
void setup() {
Serial.begin(115200);
delay(1000);
// Connect to WiFi
Serial.print("Connecting to WiFi...");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\n✅ WiFi connected!");
Serial.println("\n=== storeBatchInAnchor Example ===");
// (Assume this 'batchRoot' is a Merkle root generated from a large dataset, e.g., 1000 items)
String batchId = "batch_2025_w40"; // Year 2025, Week 40
String batchRootHash = "e5f67890a1b2c3d4e5f678902b9a7a59d6f0d36f5e8d9c12b4c7d0a3a1b2c3d4";
uint32_t batchSize = 1000;
String metadata = "Weekly report summary hash";
String txSignature;
Serial.println("Storing data batch summary in the Anchor program...");
if (solana.storeBatchInAnchor(MY_PRIVATE_KEY_BASE58, MY_PUBLIC_KEY_BASE58, ZK_PROGRAM_ID, batchId, batchRootHash, batchSize, metadata, txSignature)) {
Serial.println("✅ Data batch successfully stored in Anchor program!");
Serial.println(" -> Transaction Signature: " + txSignature);
} else {
Serial.println("❌ Failed to store data batch.");
}
}
void loop() {
// Can be left empty
}