I am trying to create a staking program. When I test this code out, I get the subjected error:
use anchor_lang::prelude::*;
use anchor_spl::token::{self, Mint, Token, TokenAccount, Transfer as SplTransfer};
use solana_program::system_instruction;
// This is your program's public key and it will update
// automatically when you build the project.
declare_id!("CXVv68e6ofmf4HF5myUCMP8YifhD69toz4PEeBrn6gkX");
#[program]
pub mod Staking {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
Ok(())
}
}
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(
init_if_needed,
payer = signer,
seeds = [b"vault".as_ref()],
bump,
token::mint = mint,
token::authority = token_vault_account
)]
pub token_vault_account: Account<'info, TokenAccount>,
#[account(mut)]
pub signer: Signer<'info>,
pub mint: Account<'info, Mint>,
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
}
test
import {
createMint,
createAssociatedTokenAccount,
mintTo,
TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
describe("Staking", () => {
it("initializes", async () => {
// Generate keypairs for the new accounts
const payer = pg.wallet.keypair;
// Create a new mint and initialize it
const mintKp = new web3.Keypair();
const mint = await createMint(
pg.program.provider.connection,
pg.wallet.keypair,
payer.publicKey,
null,
0
);
//Create Vault PDA
const [VAULT] = await anchor.web3.PublicKey.findProgramAddress(
[Buffer.from("vault")],
pg.program.programId
);
const txHash = await pg.program.methods
.initialize()
.accounts({
mint: mint,
tokenVaultAccount: VAULT,
signer: payer,
})
.rpc();
console.log(`https://explorer.solana.com/tx/${txHash}?cluster=devnet`);
await pg.connection.confirmTransaction(txHash, "finalized");
});
});