Rust
Use full service RPC for fetching latest blockhash.
use solana_client::rpc_client::RpcClient;
use solana_sdk::{message::Instruction, pubkey, pubkey::Pubkey, signature::Keypair, signer::Signer, transaction::Transaction};
use base64::{Engine as _, engine::general_purpose};
const NOZOMI_ENDPOINT: &str = "https://nozomi.temporal.xyz/api/sendTransaction2?c=<YOUR_API_KEY>";
const NOZOMI_TIP: Pubkey = pubkey!("TEMPaMeCRFAS9EKF53Jd6KpHxgL47uWLcpFArU1Fanq");
const MIN_TIP_AMOUNT: u64 = 1_000_000;
const SOLANA_RPC_ENDPOINT: &str = "https://api.mainnet-beta.solana.com";
fn send_nozomi_txn(
ixns: &mut Vec<Instruction>,
signer: &Keypair,
nozomi_endpoint: &str,
solana_rpc_client: &RpcClient
) -> Result<(), Box<dyn std::error::Error>> {
let tip_ixn = solana_system_interface::instruction::transfer(
&signer.pubkey(),
&NOZOMI_TIP,
MIN_TIP_AMOUNT
);
ixns.push(tip_ixn);
let blockhash = solana_rpc_client.get_latest_blockhash()?;
let txn = Transaction::new_signed_with_payer(
ixns,
Some(&signer.pubkey()),
&[signer],
blockhash
);
let txn_bytes = bincode::serialize(&txn)?;
let txn_base64 = general_purpose::STANDARD.encode(&txn_bytes);
let client = reqwest::blocking::Client::new();
let response = client
.post(nozomi_endpoint)
.header("Content-Type", "text/plain")
.body(txn_base64)
.send()?;
// api v2 does not return a signature, just check for success
if response.status().is_success() {
Ok(())
} else {
Err(Box::new(response.error_for_status().unwrap_err()))
}
}
fn build_ixns() -> Vec<Instruction> {
// your instruction building logic here..
vec![]
}
fn main() {
let solana_rpc_client = RpcClient::new(SOLANA_RPC_ENDPOINT.to_string());
// replace with actual keypair loading logic
let signer = Keypair::new();
let mut ixns = build_ixns();
if send_nozomi_txn(
&mut ixns,
&signer,
NOZOMI_ENDPOINT,
&solana_rpc_client
).is_ok() {
println!("Transaction sent successfully");
}
}Last updated

