adding todo: SendTransactionError: Simulation failed. Message: Transaction simulation failed: Error processing Instruction 2: custom program error: 0xbc4. Logs: [ "Program ComputeBudget111111111111111111111111111111 invoke [1]", "Program ComputeBudget111111111111111111111111111111 success", "Program ComputeBudget111111111111111111111111111111 invoke [1]", "Program ComputeBudget111111111111111111111111111111 success", "Program TLgsKcCjHfyEbL2k6giZDCauDskQmEUzrKKzSw12wKH invoke [1]", "Program log: Instruction: AddTodo", "Program log: AnchorError caused by account: user_profile. Error Code: AccountNotInitialized. Error Number: 3012. Error Message: The program expected this account to be already initialized.", "Program TLgsKcCjHfyEbL2k6giZDCauDskQmEUzrKKzSw12wKH consumed 3921 of 199700 compute units", "Program TLgsKcCjHfyEbL2k6giZDCauDskQmEUzrKKzSw12wKH failed: custom program error: 0xbc4" ]. Catch the
SendTransactionErrorand call
getLogs() on it for full details. at Connection.sendEncodedTransaction (index.browser.esm.js:7525:13) at async Connection.sendRawTransaction (index.browser.esm.js:7490:20) at async sendAndConfirmRawTransaction (index.js:1122:23) at async AnchorProvider.sendAndConfirm (index.js:1012:20) at async addTodo (todo.js:152:31) at async handleSubmit (index.js:37:13)
const addTodo = async (e) => { e.preventDefault(); if (program && publicKey) { try { setTransactionPending(true); // Ensure userProfile is initialized (implement your own initialization logic here) const profilePda = await initializeUser(); if (!profilePda) { console.error('Failed to initialize userProfile'); return; } const content = input.trim(); if (!content) { setTransactionPending(false); return; } const [todoPda] = PublicKey.findProgramAddressSync( [Buffer.from('TODO_STATE'), publicKey.toBuffer(), Uint8Array.from([lastTodo])], program.programId ); // Create a transaction without manually setting blockhash and fee payer const tx = new anchor.web3.Transaction().add( await program.methods.addTodo(content).accounts({ todoAccount: todoPda, userProfile: profilePda, authority: publicKey, systemProgram: SystemProgram.programId, }).instruction() ); // Solana's provider will handle fetching the latest blockhash and fee payer const txSig = await program.provider.sendAndConfirm(tx); console.log('Transaction successful with signature:', txSig); // Fetch updated todos after adding a new todo const todoAccounts = await program.account.todoAccount.all([authorFilter(publicKey.toString())]); setTodos(todoAccounts); // Update todos state with the latest todos setLastTodo((prev) => prev + 1); setInput(""); // Clear the input field after adding todo toast.success('Successfully added todo.'); } catch (error) { console.error('Error adding todo:', error); toast.error(error.toString()); } finally { setTransactionPending(false); } } }; ```