storeCommitmentOnChain
Stores a generated ZK commitment hash (commitment) and associated metadata (metadata) onto the Solana blockchain via a transaction. This is typically used to timestamp the moment the data was "committed".
The function utilizes Solana's Memo Program (spl-memo) to package the commitment and metadata into a transaction instruction, signs it, and sends it to the network.
Parameters
| Parameter | Type | Description |
|---|---|---|
privateKeyBase58 | const String& | The private key of the wallet signing and paying for the transaction. |
fromPubkeyBase58 | const String& | The public key of the sender's wallet. |
commitment | const String& | The commitment hash (usually hex format) to be stored on-chain. |
metadata | const String& | Additional descriptive data to accompany the commitment (e.g., "device_id:123"). |
outTxSignature | String& | Output: If successful, returns the transaction signature. |
Return Value
bool: Returnstrueif the transaction was sent and confirmed successfully,falseotherwise.
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"; // 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);
// 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=== storeCommitmentOnChain Example ===");
// Assume this commitment came from createDataCommitment
String commitmentToStore = "2b9a7a59d6f0d36f5e8d9c12b4c7d0a3a1b2c3d4e5f67890a1b2c3d4e5f67890";
String metadata = "device:ESP32-A1,type:temp_commit";
String txSignature;
Serial.println("Sending commitment to the blockchain...");
if (solana.storeCommitmentOnChain(MY_PRIVATE_KEY_BASE58, MY_PUBLIC_KEY_BASE58, commitmentToStore, metadata, txSignature)) {
Serial.println("✅ Commitment successfully stored on-chain!");
Serial.println(" -> Transaction Signature: " + txSignature);
Serial.println(" -> You can check it on Solana Explorer.");
} else {
Serial.println("❌ Failed to store commitment on-chain.");
}
}
void loop() {
// Can be left empty
}