updateCommitmentInAnchor
Updates an existing commitment and metadata stored within the ZK storage account (PDA) on the Anchor program.
This is similar to storeCommitmentInAnchor but typically calls a different Anchor instruction (e.g., update vs. store or set). It's used for periodically updating a device's status or latest data point in its designated on-chain storage.
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 PDA account to update. |
newCommitment | const String& | The new commitment hash to store. |
metadata | const String& | The new metadata string to store. |
outTxSignature | String& | Output: If successful, the signature of the transaction. |
Return Value
bool: Returnstrueif the data was updated 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=== updateCommitmentInAnchor Example ===");
String pdaSeed = "my_zk_storage_account"; // Seed to find the account
String newCommitment = "99f67890a1b2c3d4e5f678902b9a7a59d6f0d36f5e8d9c12b4c7d0a3a1b2c3e5"; // Updated commitment
String newMetadata = "sensor_id:T-1000,status:offline,last_update:1678886400";
String txSignature;
Serial.println("Updating commitment in the Anchor program...");
if (solana.updateCommitmentInAnchor(MY_PRIVATE_KEY_BASE58, MY_PUBLIC_KEY_BASE58, ZK_PROGRAM_ID, pdaSeed, newCommitment, newMetadata, txSignature)) {
Serial.println("✅ Commitment successfully updated in Anchor program!");
Serial.println(" -> Transaction Signature: " + txSignature);
} else {
Serial.println("❌ Failed to update commitment.");
}
}
void loop() {
// Can be left empty
}