Open kambaroff opened 2 years ago
Hi @ajamaica @samuelvanderwaal @creativedrewy I too am getting the issue message=Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction))
My rust file includes:
pub mod demo { use super::*;
pub fn approve_token(ctx: Context<ApproveToken>, amount: u64) -> Result<()> {
let cpi_accounts = Approve {
to: ctx.accounts.to.to_account_info(),
delegate: ctx.accounts.delegate.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
};
let cpi_program = ctx.accounts.token_program.to_account_info();
// Create the CpiContext we need for the request
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
// Execute anchor's helper function to approve tokens
token::approve(cpi_ctx, amount)?;
Ok(())
}
}
pub struct ApproveToken<'info> { ///CHECK: This is not dangerous because we don't read or write from this account
pub to: AccountInfo<'info>,
pub token_program: Program<'info, Token>,
///CHECK: This is not dangerous because we don't read or write from this account
pub delegate: AccountInfo<'info>,
pub authority: Signer<'info>,
} My test file is as shown: import * as anchor from "@project-serum/anchor"; import { Program } from "@project-serum/anchor"; import { Demo } from "../target/types/demo";
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddress } from "@solana/spl-token";
describe("demo", () => { // Configure the client to use the local cluster. anchor.setProvider(anchor.AnchorProvider.env());
const program = anchor.workspace.Demo as Program
it("Is initialized!", async () => { const fromWalletA = anchor.web3.Keypair.generate() const fromWalletB = anchor.web3.Keypair.generate() const mint = anchor.web3.Keypair.generate()
// Add your test here
let associatedTokenAccount = await getAssociatedTokenAddress(
mint.publicKey,
fromWalletB.publicKey,
);
await program.methods.approveToken(new anchor.BN(100)).accounts({ to:associatedTokenAccount, tokenProgram:TOKEN_PROGRAM_ID, delegate:fromWalletA.publicKey, authority:fromWalletB.publicKey }).signers([fromWalletB]).rpc();
}); });
Please do help I am unable to proceed due to the error
While sending transaction with original solana address I get this exception, however all params are correct.
java.lang.Exception: invalidResponse(rpcError=RPCError(code=-32002, message=Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction))
Method: solana.action.sendSPLTokens( PublicKey(tokenAddress), account.publicKey, PublicKey(address), amount.toLong(), allowUnfundedRecipient = true, account )