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();
anchor.setProvider(this.anchorProvider);
const mintAccount = await createMint(
this.anchorProvider.connection,
this.payerKey,
this.mintAuthorityKey.publicKey,
null,
DECIMALS
);
const [pdaGlobalAccount] = await anchor.web3.PublicKey.findProgramAddress(
[Buffer.from("global")],
this.program.programId
);
const [pdaEscrow] = await anchor.web3.PublicKey.findProgramAddress(
[Buffer.from("escrow")],
this.program.programId
);
// console.log('pdaGlobalAccount', pdaGlobalAccount.toBase58())
// Test initialize instruction
let init = await this.program.methods
.initialize()
.accounts({
globalState: pdaGlobalAccount,
escrowAccount: pdaEscrow,
mint: mintAccount,
authority: this.adminKey.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
rent: SYSVAR_RENT_PUBKEY,
})
.signers([this.adminKey])
.rpc();
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
})
}