storeBatchCommitmentsOnChain
Stores a batch of commitments (commitments), previously generated by createBatchCommitments, onto the Solana blockchain within a single transaction. This is significantly more cost-effective and efficient than sending each commitment in a separate transaction.
The function typically aggregates all commitments into a single Memo Program instruction.
Parameters
| Parameter | Type | Description |
|---|---|---|
privateKeyBase58 | const String& | The private key of the wallet paying for the transaction. |
fromPubkeyBase58 | const String& | The public key of the sender's wallet. |
commitments | const std::vector<ZKCommitment>& | The vector of ZKCommitment structures to be stored on-chain. |
outTxSignature | String& | Output: If successful, returns the signature of the batch transaction. |
Return Value
bool: Returnstrueif the transaction was sent and confirmed successfully.
Example Code (main.cpp)
#include <Arduino.h>
#include <WiFi.h>
#include <vector>
#include "Infratic-lib.h" // Assume ZKCommitment struct is defined here
// --- 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"; // Your Devnet wallet
const String MY_PUBLIC_KEY_BASE58 = "YOUR_PUBLIC_KEY_BASE58";
Infratic solana(SOLANA_RPC_URL);
void setup() {
Serial.begin(115200);
delay(1000);
// 1. (Offline) First, create the batch commitments
Serial.println("Creating batch commitments...");
std::vector<String> dataList;
dataList.push_back("BatchData_1_OnChain");
dataList.push_back("BatchData_2_OnChain");
String sharedSecret = "batchSecretKey";
std::vector<ZKCommitment> commitments;
if (!solana.createBatchCommitments(dataList, sharedSecret, commitments)) {
Serial.println("❌ Test Failed: Could not create commitments first.");
return;
}
Serial.printf("✅ %d commitments created.\n", commitments.size());
// 2. (Online) Connect to WiFi and send on-chain
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=== storeBatchCommitmentsOnChain Example ===");
String txSignature;
Serial.println("Sending batch commitments on-chain in a single transaction...");
if (solana.storeBatchCommitmentsOnChain(MY_PRIVATE_KEY_BASE58, MY_PUBLIC_KEY_BASE58, commitments, txSignature)) {
Serial.println("✅ Batch commitments successfully stored on-chain!");
Serial.println(" -> Transaction Signature: " + txSignature);
} else {
Serial.println("❌ Failed to store batch commitments on-chain.");
}
}
void loop() {
// Can be left empty
}