I am trying to anchor init an PDA with a vault account, however accounts are not getting created.
Rust Code:
pub struct Initialize<'info> {
/// CHECK: This is not dangerous because we don't read or write from this account
#[account(mut,signer)]
pub initializer: AccountInfo<'info>,
/// CHECK: This is not dangerous because we don't read or write from this account
pub mint: AccountInfo<'info>,
#[account(init,seeds=[mint.key.as_ref()], bump, payer=initializer, space=201,)]
pub escrow_account: Box<Account<'info, EscrowAccount>>,
#[account(init, payer = initializer, token::mint = mint, token::authority = escrow_account,)]
pub vault_account: Account<'info, TokenAccount>,
#[account(
mut,
constraint = initializer_deposit_token_account.amount >= 1,
constraint=initializer_deposit_token_account.owner == initializer.key(),
constraint=initializer_deposit_token_account.mint == mint.key()
)]
pub initializer_deposit_token_account: Account<'info, TokenAccount>,
/// CHECK: This is not dangerous because we don't read or write from this account
pub system_program: AccountInfo<'info>,
pub rent: Sysvar<'info, Rent>,
/// CHECK: This is not dangerous because we don't read or write from this account
pub token_program: AccountInfo<'info>,
pub token: Program<'info, Token>,
}
TS Code:
const [escrowAccount, _nounce] = await PublicKey.findProgramAddress(
[nftMint.toBuffer()],
program.programId
);
let [vault_account_address, stateBump] = await anchor.web3.PublicKey.findProgramAddress(
[Buffer.from("vault"),nftMint.toBuffer()], program.programId,
);
let tx=await program.methods.initialize(_nounce,new anchor.BN(0.001),new anchor.BN(1),new anchor.BN(2),new anchor.BN(20)).accounts({
initializer: wallet.publicKey,
escrowAccount: escrowAccount,
vaultAccount: vault_account_address,
mint: nftMint,
systemProgram: anchor.web3.SystemProgram.programId,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
tokenProgram: TOKEN_PROGRAM_ID,
token: TOKEN_PROGRAM_ID,
initializerDepositTokenAccount: new PublicKey("8Hj9mdExiKSNKWkb1TuNKCRqyxnkUDGFTWDAXH2iGkoR"),
})
.preInstructions([
await program.account.escrowAccount.createInstruction(wallet.payer),
// await createAssociatedTokenAccountInstruction(wallet.publicKey, vault_account_address, escrowAccount, nftMint, program.programId,
// ASSOCIATED_TOKEN_PROGRAM_ID),
])
.rpc()
Error Log:
Error: Signature verification failed
at Transaction.serialize (/node_modules/@solana/web3.js/src/transaction.ts:736:13)
at AnchorProvider.sendAndConfirm (/node_modules/@project-serum/anchor/src/provider.ts:145:22)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at MethodsBuilder.rpc [as _rpcFn] (/node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:29:16)
end init:
1) Initialize escrow
✔ Exchange escrow state
✔ Initialize escrow and cancel escrow
3 passing (2s)
1 failing
1) smart-contract:
Initialize escrow:
Error: Account does not exist FdrJWszxvctmDX8HHfWNufVJcxFeGZdRWjeuScddJTc9
at AccountClient.fetch (node_modules/@project-serum/anchor/src/program/namespace/account.ts:154:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)