Skip to content

Instantly share code, notes, and snippets.

@adilcpm
Created March 18, 2025 09:48
Show Gist options
  • Save adilcpm/8ad4cdcd9eb000eed20c06d21d17745c to your computer and use it in GitHub Desktop.
Save adilcpm/8ad4cdcd9eb000eed20c06d21d17745c to your computer and use it in GitHub Desktop.
const NOZOMI_TIP_ACCOUNTS: &[Pubkey] = &[
pubkey!("TEMPaMeCRFAS9EKF53Jd6KpHxgL47uWLcpFArU1Fanq"),
pubkey!("noz3jAjPiHuBPqiSPkkugaJDkJscPuRhYnSpbi8UvC4"),
pubkey!("noz3str9KXfpKknefHji8L1mPgimezaiUyCHYMDv1GE"),
pubkey!("noz6uoYCDijhu1V7cutCpwxNiSovEwLdRHPwmgCGDNo"),
pubkey!("noz9EPNcT7WH6Sou3sr3GGjHQYVkN3DNirpbvDkv9YJ"),
pubkey!("nozc5yT15LazbLTFVZzoNZCwjh3yUtW86LoUyqsBu4L"),
pubkey!("nozFrhfnNGoyqwVuwPAW4aaGqempx4PU6g6D9CJMv7Z"),
pubkey!("nozievPk7HyK1Rqy1MPJwVQ7qQg2QoJGyP71oeDwbsu"),
pubkey!("noznbgwYnBLDHu8wcQVCEw6kDrXkPdKkydGJGNXGvL7"),
pubkey!("nozNVWs5N8mgzuD3qigrCG2UoKxZttxzZ85pvAQVrbP"),
pubkey!("nozpEGbwx4BcGp6pvEdAh1JoC2CQGZdU6HbNP1v2p6P"),
pubkey!("nozrhjhkCr3zXT3BiT4WCodYCUFeQvcdUkM7MqhKqge"),
pubkey!("nozrwQtWhEdrA6W8dkbt9gnUaMs52PdAv5byipnadq3"),
pubkey!("nozUacTVWub3cL4mJmGCYjKZTnE9RbdY5AP46iQgbPJ"),
pubkey!("nozWCyTPppJjRuw2fpzDhhWbW355fzosWSzrrMYB1Qk"),
pubkey!("nozWNju6dY353eMkMqURqwQEoM3SFgEKC6psLCSfUne"),
pubkey!("nozxNBgWohjR75vdspfxR5H9ceC7XXH99xpxhVGt3Bb"),
];
pub fn get_random_nozomi_tip_account() -> Pubkey {
NOZOMI_TIP_ACCOUNTS[rand::random::<usize>() % NOZOMI_TIP_ACCOUNTS.len()]
}
const RPC_URL_TEMPORAL: &str =
"http://pit1.nozomi.temporal.xyz/?c=8b696636-979f-440c-800c-cb8b97fb7686";
pub async fn send_transaction_through_nozomi(
instructions: &[Instruction],
blockhash: Hash,
payer: &Keypair,
tip_amount: u64,
temporal_client: &reqwest::Client,
) -> Result<Signature, ClientError> {
let mut instructions = instructions.to_vec();
instructions.push(system_instruction::transfer(
&payer.pubkey(),
&get_random_nozomi_tip_account(),
tip_amount,
));
let transaction = Transaction::new_signed_with_payer(
instructions.as_slice(),
Some(&payer.pubkey()),
&vec![payer],
blockhash,
);
let base64_transaction = BASE64_STANDARD.encode(serialize(&transaction).map_err(|e| {
ClientError::NozomiError(format!("Failed to serialize transaction: {}", e))
})?);
static REQUEST_TEMPLATE: &str = r#"{"jsonrpc":"2.0","method":"sendTransaction","params":["{}",{"encoding":"base64"}],"id":1}"#;
let request_body = REQUEST_TEMPLATE.replace("{}", &base64_transaction);
let response = temporal_client
.post(RPC_URL_TEMPORAL)
.timeout(std::time::Duration::from_secs(5))
.header("Content-Type", "application/json")
.body(request_body)
.send()
.await
.map_err(|e| ClientError::NozomiError(e.to_string()))?;
let result = response
.json::<serde_json::Value>()
.await
.map_err(|e| ClientError::NozomiError(e.to_string()))?;
Signature::from_str(result["result"].as_str().unwrap())
.map_err(|e| ClientError::NozomiError(e.to_string()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment