It seems that you are facing an issue with retrieving the latest block hash from the Solana Blockchain in a vanilla JavaScript mini app using HTML and AJAX with a CDN.
The error message “Method not found Connection.getRecentBlockhash in vanilla javascript” indicates that the Connection object does not have a method called “getRecentBlockhash”, which is likely due to a compatibility issue or an outdated library.
Here is an article that should help you resolve this issue:
Unable to retrieve latest block hash from Solana Blockchain in Vanilla JavaScript Mini app
Error message:
Method not found Connection.getRecentBlockhash in vanilla javascript
Solution:
- Check the libraries you are using: Make sure you are using a library that supports latest block hashes, such as solana-connect or solo-js. You can check the documentation of the library you are using to see if it has the latest block hash functions.
- Use the getRecentBlockhashAsync method: Instead of calling getRecentBlockhash, try using the getRecentBlockhashAsync method, which returns an asynchronous function that retrieves the latest block hash.
Here is an example:
const connection = new Web3Connection(url); // Change the URL of your Solana wallet
async function getRecentBlockhash() {
const recentHash = await connection.getRecentBlockhashAsync();
return latestHash;
}
Code example:
Solana Lottery
CDN Setup:
If you are using a CDN, be sure to add the following script tag to your HTML: