Browse Source

use minContextSlot, get blockhash before sending

Jordan Sexton 3 years ago
parent
commit
9d2652ec8f
1 changed files with 6 additions and 7 deletions
  1. 6 7
      README.md

+ 6 - 7
README.md

@@ -119,15 +119,14 @@ export const SendOneLamportToRandomAddress: FC = () => {
             })
         );
 
-        const signature = await sendTransaction(transaction, connection);
+        const {
+            context: { slot: minContextSlot },
+            value: { blockhash, lastValidBlockHeight }
+        } = await connection.getLatestBlockhashAndContext();
 
-        const latestBlockHash = await connection.getLatestBlockhash();
+        const signature = await sendTransaction(transaction, connection, { minContextSlot });
 
-        await connection.confirmTransaction({
-                blockhash: latestBlockHash.blockhash,
-                lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
-                signature: signature,
-        });
+        await connection.confirmTransaction({ blockhash, lastValidBlockHeight, signature });
     }, [publicKey, sendTransaction, connection]);
 
     return (