2

I am doing unit tests and I notice that my alchemy endpoint lags behind mainnet-beta in several situations. Sometimes it doesn't get a websocket account update, but the worst obvious case is after doing a swap SOL/USDC: my sol balance has changed and the mainnet-beta endpoint captures that, but not the alchemy endpoint. Any explanation?

import {Connection, PublicKey} from "@solana/web3.js";

let connexion_mainnet = new Connection(
    "https://api.mainnet-beta.solana.com",
    "processed");
let connexion_alchemy = new Connection(
    "https://solana-mainnet.g.alchemy.com/v2/my_end_point",
    "processed");

let wallet = new PublicKey("my_wallet_address")
let balance_mainnet = await connexion_mainnet.getBalance(wallet, "processed")
let balance_alchemy = await connexion_alchemy.getBalance(wallet, "processed")

// fail, balance_mainnet is the right SOL balance,
// according to solscan and orca UI
assert balance_mainnet === balance_achemy 

1 Answer 1

2

Could it be, that you did your swap using another commitment level than the getBalance call? Usually you should go for at least "confirmed" instead of processed because then 66% of stake has voted for that block which makes sure that it will get finalized eventually. See here: Commitment "Processed" vs "Confirmed" vs "Finalized"

Beside that different RPCs nodes have different loads and feature sets. Could also be that the alchemy RPC was still catching up with the cluster maybe. Last time I tried alchemy didn't have accountSubscribe yet. If you can reproduce it probably best to write to the alchemy support.

2
  • 1
    I was the same commitment, processed. I don't think it has an impact here because I have waited like 5min after the swap to check the balance! The catching from the RPC would be a reason, or maybe Alchemy is using a caching system with low frequency refresh
    – mehh
    Commented May 17, 2023 at 17:39
  • Check if both rpc are in the same block. Commented May 18, 2023 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.