storeCommitmentInAnchor
Stores a cryptographic commitment (commitment) and associated metadata permanently into the ZK storage account (PDA) on the Anchor program, previously created using initializeZKStorage.
Unlike the initialization function, this function typically updates data within an existing account (or writes the initial data). It provides a more structured and persistent storage method compared to using the Memo Program (storeCommitmentOnChain).
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. |
seedName | const String& | The seed used to find the target PDA storage account. |
commitment | const String& | The commitment hash (hex format, 32 bytes) to store. |
metadata | const String& | Metadata string to store alongside the commitment. |
outTxSignature | String& | Output: If successful, the signature of the transaction. |
Return Value
bool: Returnstrueif the 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=== storeCommitmentInAnchor Example ===");
String pdaSeed = "my_zk_storage_account"; // Seed to find the account
String commitmentToStore = "55e8d9c12b4c7d0a3a1b2c3d4e5f67890a1b2c3d4e5f678902b9a7a59d6f0d36f"; // New commitment
String metadata = "sensor_id:T-1000,status:active";
String txSignature;
Serial.println("Storing commitment in the Anchor program storage account...");
if (solana.storeCommitmentInAnchor(MY_PRIVATE_KEY_BASE58, MY_PUBLIC_KEY_BASE58, ZK_PROGRAM_ID, pdaSeed, commitmentToStore, metadata, txSignature)) {
Serial.println("✅ Commitment successfully stored in Anchor program!");
Serial.println(" -> Transaction Signature: " + txSignature);
} else {
Serial.println("❌ Failed to store commitment (Account might not be initialized).");
}
}
void loop() {
// Can be left empty
}