1

I created a React app using @project-serum/anchor, @solana/web3.js and vite. I am trying to send some tokens from one account to another. My code works fine in dev mode but it throws an error when run in production mode (after building the app). Screenshot attached.

Frontend Code:

const donate = async () => {
    const pubKey = new PublicKey(PDA_CROWD_FUNDING);
    await  mainState.programs.cf.methods.donate(new BN(amount * LAMPORTS_PER_SOL)).accounts({
        campaign: pubKey,
        user: mainState.provider.wallet.publicKey,
        systemProgram: SystemProgram.programId
    }).rpc()

Rust Function for the above functionality:

pub fn donate(ctx: Context<Donate>, amount: u64) -> ProgramResult {
    let ix = transfer(&ctx.accounts.user.key(), &ctx.accounts.campaign.key(), amount);
    invoke(&ix, &[ctx.accounts.user.to_account_info(), ctx.accounts.campaign.to_account_info()]);
    (&mut ctx.accounts.campaign).total_funding += amount;
    Ok(())
}

Also, getting something from solana cluster working fine in both dev and prod mode. Only transactions are failing.

Dependencies:

"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@mui/icons-material": "^5.8.2",
"@mui/material": "^5.9.0",
"@project-serum/anchor": "^0.24.2",
"@reduxjs/toolkit": "^1.8.3",
"@solana/web3.js": "1.30.2",
"dotenv": "^16.0.1",
"global": "^4.4.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-redux": "^8.0.2",
"react-router-dom": "^6.3.0"

[EDITED]

I see difference in solana initiators for dev and production.

Dev Initiator

Prod Initiator

0 Answers0