Skip to main content

sendProgramDataTransaction

Creates, signs, and sends a transaction to a specified program with custom data. This is commonly used to store small pieces of data on-chain. The most frequent use case is with Solana's Memo Program, which allows you to attach any text data to a transaction, permanently recording it on the blockchain.

The function also waits for the transaction to be confirmed.

Parameters

ParameterTypeDescription
privateKeyBase58const String&The Base58 private key of the wallet signing the transaction.
fromPubkeyBase58const String&The Base58 public key of the sender (and fee payer).
programIdBase58const String&The Base58 address of the target program (For Memo Program: MemoSq4gqABAXKb96qnH8TysNcVtrp5GzAufjCUajQN).
dataStringconst String&The string data to send to the program.
confirmWaitMsuint32_t(Optional) The maximum time to wait for confirmation in milliseconds. Defaults to 5000ms.

Return Value

  • bool: Returns true if the transaction was sent and confirmed successfully, false otherwise.

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"; // WARNING: Use a devnet-only key.
const String MY_PUBLIC_KEY_BASE58 = "YOUR_PUBLIC_KEY_BASE58";
// Solana Memo Program ID
const String MEMO_PROGRAM_ID = "MemoSq4gqABAXKb96qnH8TysNcVtrp5GzAufjCUajQN";

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=== Send Program Data (Memo) Example ===");

String message = "Sent from an ESP32 with Infratic!";
Serial.println("Sending data: " + message);

if (solana.sendProgramDataTransaction(MY_PRIVATE_KEY_BASE58, MY_PUBLIC_KEY_BASE58,
MEMO_PROGRAM_ID, message, 10000)) { // Wait up to 10 seconds
Serial.println("✅ Data (memo) transaction sent and confirmed successfully!");
} else {
Serial.println("❌ Failed to send data transaction.");
}
}

void loop() {
// Can be left empty
}