@@ -39,7 +39,8 @@ export async function sendTransactionWithLookupTable(
3939
4040 // Submit the ALT creation transaction
4141 await web3 . sendAndConfirmTransaction ( connection , new web3 . Transaction ( ) . add ( lookupTableInstruction ) , [ sender ] , {
42- skipPreflight : true , // Avoids recent slot mismatch in simulation.
42+ commitment : "confirmed" ,
43+ skipPreflight : true ,
4344 } ) ;
4445
4546 // Extend the ALT with all accounts making sure not to exceed the maximum number of accounts per transaction.
@@ -52,12 +53,16 @@ export async function sendTransactionWithLookupTable(
5253 } ) ;
5354
5455 await web3 . sendAndConfirmTransaction ( connection , new web3 . Transaction ( ) . add ( extendInstruction ) , [ sender ] , {
55- skipPreflight : true , // Avoids recent slot mismatch in simulation.
56+ commitment : "confirmed" ,
57+ skipPreflight : true ,
5658 } ) ;
5759 }
5860
59- // Avoids invalid ALT index as ALT might not be active yet on the following tx.
60- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
61+ // Wait for slot to advance. LUTs only active after slot advance.
62+ const initialSlot = await connection . getSlot ( ) ;
63+ while ( ( await connection . getSlot ( ) ) === initialSlot ) {
64+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
65+ }
6166
6267 // Fetch the AddressLookupTableAccount
6368 const lookupTableAccount = ( await connection . getAddressLookupTable ( lookupTableAddress ) ) . value ;
@@ -76,5 +81,12 @@ export async function sendTransactionWithLookupTable(
7681 versionedTx . sign ( [ sender ] ) ;
7782 const txSignature = await connection . sendTransaction ( versionedTx ) ;
7883
84+ // Confirm the versioned transaction
85+ let block = await connection . getLatestBlockhash ( ) ;
86+ await connection . confirmTransaction (
87+ { signature : txSignature , blockhash : block . blockhash , lastValidBlockHeight : block . lastValidBlockHeight } ,
88+ "confirmed"
89+ ) ;
90+
7991 return { txSignature, lookupTableAddress } ;
8092}
0 commit comments