confirmTransaction
Checks if a transaction that has been sent to the network has been confirmed. The function polls the network for the given transaction signature and waits for a specified duration for it to be finalized.
This is a critical step to verify if a transaction was successful.
Parameters
| Parameter | Type | Description |
|---|---|---|
signature | const String& | The Base58 encoded signature of the transaction to confirm. |
maxWaitMs | uint32_t | (Optional) The maximum time to wait for confirmation in milliseconds. Defaults to 5000ms. |
Return Value
bool: Returnstrueif the transaction is confirmed within the timeout period,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)";
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=== Confirm Transaction Example ===");
// NOTE: Replace this with a real, recently sent transaction signature from the devnet.
String txSignature = "5k5f3msN3s94fL9J3b2r2u2m7Yw2b2s2k2o8p6c4X4e5g6h7j8k9l0m1n2o3p4q5r6s7t8u9v0w";
Serial.println("Waiting for confirmation of tx: " + txSignature);
if (solana.confirmTransaction(txSignature, 10000)) { // Wait up to 10 seconds
Serial.println("✅ Transaction confirmed!");
} else {
Serial.println("❌ Transaction not confirmed or timed out.");
}
}
void loop() {
// Can be left empty
}