I'm currently trying to run an escrow program and when i turn on the solana-test-validator in a different terminal it gives me this error:

failed to send transaction: Transaction simulation failed: Attempt to load a program that does not exist

When I turn that off i get the following error:

failed to get recent blockhash: FetchError: request to http://localhost:8899/ failed, reason: connect ECONNREFUSED

I'm on the localhost btw

Any help is much appreciated!

EDIT: I have an instruction in my src folder as such:

#[instruction(application_idx: u64)]
pub struct InitNewExchange<'info> {
        payer = user_sending,
        space = Exchange::LEN,
        seeds = [b"exchange".as_ref(), 
    application_exchange: Account<'info, Exchange>,

        payer = user_sending,
        seeds = [b"exchange".as_ref(), 
        token::mint =  mint_of_token_being_sent,
        token::authority = application_exchange,
    //Should not be signer or writable
    escrow_wallet_exchange: Account<'info, TokenAccount>,

    user_sending: Signer<'info>,
    user_receiving: AccountInfo<'info>,
    mint_of_token_being_sent: Account<'info, Mint>,

        constraint = wallet_to_withdraw_from.owner == user_sending.key(),
        constraint = wallet_to_withdraw_from.mint == mint_of_token_being_sent.key(),
    wallet_to_withdraw_from: Account<'info, TokenAccount>,
    system_program: Program<'info, System>,
    token_program: Program<'info, Token>,
    rent: Sysvar<'info, Rent>,}

and the following handler function for it:

pub fn handler(
    ctx: Context<InitNewExchange>,
    application_idx: i64,
    amount: i64
) -> Result<()> { 
    //Assign attributes to Exchange
    let exchange = &mut ctx.accounts.application_exchange;
    exchange.idx = application_idx;
    exchange.user_sending = ctx.accounts.user_sending.key().clone();
    exchange.user_receiving = ctx.accounts.user_receiving.key().clone();
    exchange.mint_of_token_being_sent = ctx.accounts.mint_of_token_being_sent.key().clone();
    exchange.escrow_wallet = ctx.accounts.escrow_wallet_exchange.key().clone();
    exchange.amount_tokens = amount;
    exchange.bump = *ctx.bumps.get("application_exchange").unwrap();
    msg!("Initializing exchange instance for {} tokens", amount);

    let bump_vector = exchange.bump.to_le_bytes();
    let mint_of_token_being_sent_pk = ctx.accounts.mint_of_token_being_sent.key().clone();
    let application_idx_bytes = application_idx.to_le_bytes();

    let sender = ctx.accounts.user_sending.key();
    let receiver = ctx.accounts.user_receiving.key();

    let inner = vec![

    let outer = vec![inner.as_slice()];

    let transfer_instruction = Transfer{
        from: ctx.accounts.wallet_to_withdraw_from.to_account_info(),
        to: ctx.accounts.escrow_wallet_exchange.to_account_info(),
        //Authority will be the one sending
        authority: ctx.accounts.user_sending.to_account_info(),

    let cpi_ctx = CpiContext::new_with_signer(

    anchor_spl::token::transfer(cpi_ctx, exchange.amount_tokens.try_into().unwrap())?;

and I ran anchor build, anchor deploy (both working), and anchor test (which did not work). The erroneous code comes from this chunk in my test file (but i think all my programs.method calls incur this error):

const tx1 = await program.methods
        .initNewExchange(pda.idx, amount)
            applicationExchange: pda.exchangeKey,
            escrowWalletExchange: pda.escrowWalletKey,
            userSending: sender.publicKey,
            userReceiving: receiver.publicKey,
            //Account data type of mint
            mintOfTokenBeingSent: mintAddress,
            //Wallet of sender for that particular token
            walletToWithdrawFrom: senderWallet,
            systemProgram: anchor.web3.SystemProgram.programId,
            tokenProgram: spl.TOKEN_PROGRAM_ID,
            rent: anchor.web3.SYSVAR_RENT_PUBKEY,

THANKS A LOT once again!!

  • 1
    Can you please update the question with the commands/code that you ran?
    – sohrab
    Jul 28, 2022 at 3:44
  • also the program you're targeting
    – trent.sol
    Jul 28, 2022 at 4:13

5 Answers 5


If you are running NodeJS version 17, try downgrading to version 16 and see if that helps.

Apparently, node v17 resolves localhost to IPv6 instead of IPv4 (, which as been causing issues with solana-test-validator for some time.

  • I'm currently on version 16.15.0 though, checked by using node -v
    – Aengus
    Jul 29, 2022 at 15:50

I found that my error was because I did not change the program id to the one shown after i ran anchor deploy, I had to change it under [programs.localnet] in anchor.toml and the declare.id! field in lib.rs. Thanks everyone for the help!

  • 1
    please add code blocks referencing the config and code changes that were required
    – trent.sol
    Aug 2, 2022 at 6:22

@Aengus it seems like you haven't deployed your program on the net but trying to access PDA's via test cases. Try by first deploying your program on the net.

  • Ah i tried this but unfortunately it did not work. I ran anchor build, anchor deploy then anchor test but i ran into the same error. I am unsure if this would be relevant but I have a beforeEach hook in my test file that actually works, its just the program call that runs into issues. Thank you!
    – Aengus
    Jul 28, 2022 at 6:13
  • This is not an answer, but would be fine as a comment.
    – mikemaccana
    Aug 10, 2022 at 18:22

I tried to add this to Jupo's existing answer but the edit was rejected. 🤷🏻‍♂️

Node 17+ did indeed change the resolution order - node now uses the order from your OS, which may be IPV6 first.

However you don't need to downgrade node to use solana-test-validator, you can set the resolution to use IPV4 by default:

await dnsPromises.setDefaultResultOrder('ipv4first')

I remember facing this issue and then realising that I had deleted the target folder and on building the program later, I forgot to change the program_id in Anchor.toml and lib.rs.

Might wanna check this haha

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.