瀏覽代碼

use minContextSlot, get blockhash before sending

Jordan Sexton 3 年之前
父節點
當前提交
9d2652ec8f
共有 1 個文件被更改,包括 6 次插入7 次删除
  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 (