I want to call a method of solana smartcontract. I have an IDL. While I'm calling it I'm getting the following error (when I'm calling await this.program.methods.initialize() method):

Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0

this.anchorProvider = anchor.AnchorProvider.env();

const mintAccount = await createMint(

const [pdaGlobalAccount] = await anchor.web3.PublicKey.findProgramAddress(
const [pdaEscrow] = await anchor.web3.PublicKey.findProgramAddress(
// console.log('pdaGlobalAccount', pdaGlobalAccount.toBase58())

// Test initialize instruction
let init = await this.program.methods
    globalState: pdaGlobalAccount,
    escrowAccount: pdaEscrow,
    mint: mintAccount,
    authority: this.adminKey.publicKey,
    systemProgram: anchor.web3.SystemProgram.programId,
    tokenProgram: TOKEN_PROGRAM_ID,

const result = await this.confirmTransaction(init);

here is confirmTransaction method:

async confirmTransaction(tx: string) {
  const latestBlockHash = await this.anchorProvider.connection.getLatestBlockhash();

  return await this.anchorProvider.connection.confirmTransaction({
    blockhash: latestBlockHash.blockhash,
    lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
    signature: tx

1 Answer 1


0x0 means you're attempting to initialize an already initialized account. What's happening here is that because your PDAs have only constant seeds, the same address is generated for them on each run of the test.

Therefore, not only does running your test for the first time initialize pdaGlobalAccount and pdaEscrow, but subsequent tests also fail because they would attempt to initialize the same accounts as the first (because constant seeds give you the exact same address each time).

  • ah, that seems to be the case for me as well. Now the next question is, how to reset everything so that I can initialize again? I stopped solana-test-validator and restarted it.. and then ran the tests again anchor test --skip-local-validator. But I see the same error. That means the state is persistent. How do I clear/reset it? Feb 11, 2023 at 19:57
  • Also, where can I get the list of these error codes (numbers) and their meaning/explanation? Where did you learn that "0x0 means you're attempting to initialize an already initialized account"? Feb 11, 2023 at 20:03
  • solana-test-validator -r resets the validator. You can also do this manually by deleting the test-ledger file. I wish I could give you a good answer to the second question. I'd recomment viewing the program logs though for more context on errors. An easy way to do this is solana logs or just try..catch in javascript
    – Ademola
    Feb 11, 2023 at 20:34
  • solana-test-validator -r is exactly what I need. Thanks a lot. As for the second question, hope as the adoption increases, the docs also gets better. Feb 11, 2023 at 22:42
  • 1
    Re: error codes and their meaning. You can find the codes for system errors here
    – Ademola
    Feb 19, 2023 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.