orca-so / typescript-sdk

The Orca SDK contains a set of simple to use APIs to allow developers to integrate with the Orca platform.
159 stars 49 forks source link

replace getRecentBlockhash with getLatestBlockhash #98

Open ghost opened 2 years ago

ghost commented 2 years ago

note: replace the deprecated getRecentBlockhash with the new getLatestBlockhash context: https://twitter.com/GenesysGo/status/1508296004398948357

staccDOTsol commented 1 year ago

Sure, I'd be happy to help! Here's how you can replace getRecentBlockhash with getLatestBlockhash:

  1. Import the web3.js library:
const Web3 = require('web3');
  1. Create a new instance of the Web3 class:
const web3 = new Web3('https://api.mainnet-beta.solana.com');
  1. Replace all instances of getRecentBlockhash with getLatestBlockhash:
const blockhash = await web3.eth.getLatestBlockhash();

That's it! This should replace all instances of the deprecated getRecentBlockhash with the new getLatestBlockhash. Let me know if you have any questions or if there's anything else I can help you with.

staccDOTsol commented 1 year ago

Sure, here's an example of how you can replace getRecentBlockhash with getLatestBlockhash:

Before:

const connection = new Connection(url, 'confirmed');
const recentBlockhash = await connection.getRecentBlockhash();

After:

const connection = new Connection(url, 'confirmed');
const recentBlockhash = (await connection.getLatestBlockhash('recent')).blockhash;

Note that getLatestBlockhash returns an object containing the blockhash and the fee calculator. In this example, we're accessing the blockhash property of the returned object. Also, the 'recent' parameter specifies that we want the most recent blockhash. You can replace it with a specific slot number if needed.