1

I was using React native and the example provided by Phantom: https://github.com/phantom-labs/deep-link-demo-app/blob/20f19f2154e98699f0d5a6b28bc4bb3d5acbcefd/App.tsx

 const createTransferTransaction = async () => {
if (!phantomWalletPublicKey) {
  throw new Error('missing public key from user')
}
console.log('tcreate')
console.log(phantomWalletPublicKey)
let transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: phantomWalletPublicKey,
    toPubkey: phantomWalletPublicKey,
    lamports: 100,
  }),
)
transaction.feePayer = phantomWalletPublicKey
const anyTransaction = transaction
anyTransaction.recentBlockhash = (
  await connection.getLatestBlockhash()
).blockhash
return transaction
}

however, when it comes to getting the recent hash of the transaction, a error appears:

[Unhandled promise rejection: Error: failed to get recent blockhash: TypeError: Network request failed]
at node_modules\@solana\web3.js\lib\index.browser.cjs.js:null in Connection#getLatestBlockhash
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in asyncGeneratorStep
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in _throw
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in tryCallOne
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _allocateCallback$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callReactNativeMicrotasksPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in flushedQueue

Please help to figure out the issue!


Getting recent blockhash

failed to get recent blockhash: TypeError: Network request failed
at node_modules\@solana\web3.js\lib\index.browser.esm.js:null in Connection#getLatestBlockhash
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in asyncGeneratorStep
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in _throw
at node_modules\promise\setimmediate\core.js:null in tryCallOne
at node_modules\promise\setimmediate\core.js:null in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _allocateCallback$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callReactNativeMicrotasksPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in flushedQueue

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '(yield connection.getLatestBlockhash().catch(function (err) {]
at App.tsx:null in Promise$argument_0
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in asyncGeneratorStep
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in _next
at node_modules\promise\setimmediate\core.js:null in tryCallOne
at node_modules\promise\setimmediate\core.js:null in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _allocateCallback$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callReactNativeMicrotasksPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in flushedQueue```
2
  • Hi! It looks like your network request for connection.getLatestBlockhash failed. This could be for a number of reasons. How often is this occurring for you? This code is for demo purposes, so we assumed that connection.getLatestBlockhash would succeed on most occasions. You could try wrapping the request in a try catch block. Nov 18, 2022 at 19:54
  • It always occurs... never succeeds, I also wrapped it into a try-catch block, and the whole log is updated below as an answer
    – Jupiter Yu
    Nov 19, 2022 at 13:05

1 Answer 1

1

Seems like you have some issues with the RPC endpoint that you're using. Could you try switching to some other devnet endpoint and see if it works out?

e.g. https://solana-devnet-rpc.allthatnode.com/

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.