4

I extract the lib.rs file from the Metaplex candy machine folder. Created a new anchor project via anchor init, pasted the smart contract then I run anchor keys list and pasted the key in declare_id in lib.rs and updated the key in Anchor.toml as well. I build and deployed Solana Program successfully on devnet. Now form the front end side it gives me an error Error: Account does not exist 6iTW2keSEsGDEV7r1TGFTSYHKJKW5HKWZa1oR8Yg5yCX

The Project works fine with the previous Solana Program. I just redeployed the rust program using my wallet keys and replaced the idl.json file.

export const _getState = async (provider, wallet) => {
    const programID = new PublicKey(idl.metadata.address);
    const program = new Program(idl, programID, provider);
    const _program = await web3.PublicKey.findProgramAddress(
    [Buffer.from(utils.bytes.utf8.encode('teacher_minting'))],
    program.programId
    );
    console.log(_program.toString());
    const [stakingPubkey] = _program;
    const [userstakingPubkey] =
        await web3.PublicKey.findProgramAddress(
        [wallet.publicKey.toBuffer()],
        program.programId
        );

        console.log("=====================", stakingPubkey.toBase58());
        
    const testdata = await program.account.mintingAccount.fetch(stakingPubkey);
    
    let userdata = [];
    try {
        userdata = await program.account.userMintingAccount.fetch(userstakingPubkey);
    }catch (err) {
        console.log(err);
    }
    console.log("ud:", userdata, testdata);
}

Deployed Program: https://explorer.solana.com/address/CcSFrh2CQdKRCtpJp6mnFZem67GdLU8jJ1MfwEVoLDRm?cluster=devnet

1 Answer 1

2

I forgot to initialize the smart contact after deploying with new address via CLI, that's why it gave me error Account does not exist. Here is the code that I run form frontend side very first after deploying to fix the issue:

export const initialize = async (provider, wallet) => {
    const programID = new PublicKey(idl.metadata.address);
    const program = new Program(idl, programID, provider);

    await program.rpc.initialize(
        stakingBump,
        wallet.publicKey,
        new anchor.BN(9999),
        new anchor.BN(20),
        new anchor.BN(20),
        new anchor.BN(20),
        new anchor.BN(15e8),
        new anchor.BN(2e9),
        new anchor.BN(2e9),
        new anchor.BN(0),
        1,
        {
         accounts: {
         mintingAccount: stakingPubkey,
         initializer: wallet.publicKey,
         systemProgram: SystemProgram.programId,
         tokenProgram: TOKEN_PROGRAM_ID,
         rent: anchor.web3.SYSVAR_RENT_PUBKEY,
        },
    });    
}

Note: Your initialize function may or may not contain params as it depends on your code implementation. Initialize part will create the missing accounts.

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.