Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7961

failed to get recent blockhash: SolanaJSONRPCError: failed to get recent blockhash: Method not found

$
0
0
todo.js:132 adding todo: Error: failed to get recent blockhash: SolanaJSONRPCError: failed to get recent blockhash: Method not found    at Connection.getRecentBlockhash (index.browser.esm.js:6542:13)    at async ot.sendAndConfirm (index.js:57:8041)    at async addTodo (todo.js:122:31)console.error

the above is the error I am facing, below is the addTodo block

const addTodo = async (e) => {        e.preventDefault();        if (program && publicKey) {            try {                setTransactionPending(true);                // Fetch the latest blockhash                const latestBlockhashInfo = await connection.getLatestBlockhash();                const { blockhash } = latestBlockhashInfo;                const [profilePda] = PublicKey.findProgramAddressSync(                    [Buffer.from('USER_STATE'), publicKey.toBuffer()],                    program.programId                );                const content = input.trim();                if (!content) {                    setTransactionPending(false);                    return;                }                const [todoPda] = PublicKey.findProgramAddressSync(                    [Buffer.from('TODO_STATE'), publicKey.toBuffer(), Uint8Array.from([lastTodo])],                    program.programId                );                const tx = new anchor.web3.Transaction().add(                    await program.methods.addTodo(content).accounts({                        todoAccount: todoPda,                        userProfile: profilePda,                        authority: publicKey,                        systemProgram: SystemProgram.programId,                    }).instruction()                );                tx.recentBlockhash = blockhash;                tx.feePayer = publicKey;                const txSig = await program.provider.sendAndConfirm(tx);                console.log('Transaction successful with signature:', txSig);                setLastTodo((prev) => prev + 1);                setTodos((prevTodos) => [                    ...prevTodos,                    { account: { content, marked: false, idx: lastTodo } }                ]);                setInput("");            } catch (error) {                console.error('Error adding todo:', error);            } finally {                setTransactionPending(false);            }        }    };    ```

Viewing all articles
Browse latest Browse all 7961

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>