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 127.0.0.1:8899
I'm on the localhost btw
Any help is much appreciated!
EDIT: I have an instruction in my src folder as such:
#[derive(Accounts)]
#[instruction(application_idx: u64)]
pub struct InitNewExchange<'info> {
#[account(
init,
payer = user_sending,
space = Exchange::LEN,
seeds = [b"exchange".as_ref(),
user_sending.key().as_ref(),
user_receiving.key.as_ref(),
mint_of_token_being_sent.key().as_ref(),
application_idx.to_le_bytes().as_ref()],
bump,
)]
application_exchange: Account<'info, Exchange>,
#[account(
init,
payer = user_sending,
seeds = [b"exchange".as_ref(),
user_sending.key().as_ref(),
user_receiving.key.as_ref(),
mint_of_token_being_sent.key().as_ref(),
application_idx.to_le_bytes().as_ref()],
bump,
token::mint = mint_of_token_being_sent,
token::authority = application_exchange,
)]
//Should not be signer or writable
escrow_wallet_exchange: Account<'info, TokenAccount>,
#[account(mut)]
user_sending: Signer<'info>,
user_receiving: AccountInfo<'info>,
mint_of_token_being_sent: Account<'info, Mint>,
#[account(
mut,
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![
b"exchange".as_ref(),
sender.as_ref(),
receiver.as_ref(),
mint_of_token_being_sent_pk.as_ref(),
application_idx_bytes.as_ref(),
bump_vector.as_ref(),
];
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(
ctx.accounts.token_program.to_account_info(),
transfer_instruction,
outer.as_slice(),
);
anchor_spl::token::transfer(cpi_ctx, exchange.amount_tokens.try_into().unwrap())?;
Ok(())
}
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)
.accounts({
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,
})
.signers([sender])
.rpc();
THANKS A LOT once again!!