sendSol
This is a high-level, all-in-one function for transferring SOL from one wallet to another. It simplifies the process by automatically handling all the necessary background steps:
- Fetching the latest blockhash.
- Creating the transfer transaction.
- Signing the transaction with the provided private key.
- Sending the transaction to the network.
- Waiting for the transaction to be confirmed.
Parameters
| Parameter | Type | Description |
|---|---|---|
privateKeyBase58 | const String& | The Base58-encoded private key of the sender's wallet. Use a devnet/testnet key only. |
fromPubkeyBase58 | const String& | The Base58-encoded public key of the sender's wallet. |
toPubkeyBase58 | const String& | The Base58-encoded public key of the recipient's wallet. |
lamports | uint64_t | The amount to send, in lamports. 1 SOL = 1,000,000,000 lamports. |
Return Value
bool: Returnstrueif the entire transfer process (sending and confirmation) was successful. Returnsfalseif any step failed.
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)";
// WARNING: Use a temporary devnet wallet for testing. Do NOT expose your mainnet private key.
const String MY_PRIVATE_KEY_BASE58 = "YOUR_PRIVATE_KEY_BASE58";
const String MY_PUBLIC_KEY_BASE58 = "YOUR_PUBLIC_KEY_BASE58";
const String RECIPIENT_PUBKEY_BASE58 = "RECIPIENT_PUBKEY_BASE58"; // Address to send SOL to
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 SOL Example ===");
uint64_t lamportsToSend = 200000; // 0.0002 SOL
Serial.print("Attempting to send ");
Serial.print((unsigned long)lamportsToSend);
Serial.print(" lamports to ");
Serial.println(RECIPIENT_PUBKEY_BASE58);
if (solana.sendSol(MY_PRIVATE_KEY_BASE58, MY_PUBLIC_KEY_BASE58, RECIPIENT_PUBKEY_BASE58, lamportsToSend)) {
Serial.println("✅ SOL transfer was sent and confirmed successfully!");
} else {
Serial.println("❌ SOL transfer failed. Check your balance, keys, and the recipient address.");
}
}
void loop() {
// This example runs once in setup.
}