Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendSplToken: invalid account data for instruction #94

Open
kambaroff opened this issue Jul 22, 2022 · 2 comments
Open

sendSplToken: invalid account data for instruction #94

kambaroff opened this issue Jul 22, 2022 · 2 comments

Comments

@kambaroff
Copy link

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
)

@ashlinSajan
Copy link

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:
#[program]
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(())
} 

}

#[derive(Accounts)]
pub struct ApproveToken<'info> {
///CHECK: This is not dangerous because we don't read or write from this account
#[account(mut)]
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

@ajamaica
Copy link
Contributor

Fixed on #107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants