Skip to content

SkyRizzAI/esp-solana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esp-solana

no_std Solana SDK for ESP32. Wallets, signing, transactions, and RPC — in ~163KB of flash.

Crates.io Documentation

Rust

Solana

Usage

[dependencies]
esp-solana = { git = "https://github.com/SkyRizzAI/esp-solana", features = ["wallet"] }

Requires alloc. On ESP32, set up a heap with esp-alloc:

esp_alloc::heap_allocator!(size: 65536);

Wallet

use esp_solana::wallet::Wallet;

let entropy: [u8; 16] = get_from_hw_rng();
let wallet = Wallet::generate_12(&entropy).unwrap();

let mnemonic = wallet.mnemonic();
let keypair = wallet.keypair(0).unwrap();
let address = wallet.default_pubkey().unwrap();

// restore later
let restored = Wallet::from_mnemonic(mnemonic).unwrap();

Keys and seeds are zeroized from memory on drop.

Transactions

use esp_solana::prelude::*;
use esp_solana::instruction::system_transfer;
use esp_solana::message::Message;
use esp_solana::transaction::Transaction;

let ix = system_transfer(keypair.pubkey(), recipient, 1_000_000);
let msg = Message::compile(keypair.pubkey(), &[ix], blockhash).unwrap();
let tx = Transaction::new(msg, &[&keypair]).unwrap();
let b64 = tx.to_base64(); // ready for sendTransaction

RPC

The SDK doesn't include an HTTP client — you bring your own by implementing RpcClient:

use esp_solana::rpc::{RpcClient, SolanaRpc};

struct MyHttp;
impl RpcClient for MyHttp {
    fn post_json(&self, url: &str, body: &str) -> esp_solana::types::Result<String> {
        todo!("use reqwless, esp-wifi sockets, etc.")
    }
}

let rpc = SolanaRpc::new("https://api.devnet.solana.com", MyHttp);
let blockhash = rpc.get_latest_blockhash()?;
let balance = rpc.get_balance(&keypair.pubkey())?;
let sig = rpc.send_transaction(&b64)?;

Also supports request_airdrop, get_signature_status, get_transaction, get_account_info.

Examples

# host-side transaction demo
cargo run --example host_demo --features wallet

# real devnet transfer (creates wallets, sends SOL, verifies)
cargo run --example devnet_transfer --features wallet

For ESP32-C3 hardware, see examples/esp32c3_demo/.

cd examples/esp32c3_demo
cargo build --release
espflash flash target/riscv32imc-unknown-none-elf/release/esp32c3-solana-demo --monitor

ESP32-C3 flash usage

Config Flash
crypto only (signing + tx + rpc) 148 KB
full SDK with wallet 163 KB

Out of 4MB. Use lto = 'fat' and opt-level = 's' in your release profile.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages