EDIT:
The error you're getting is being thrown by this check. The instruction to create a lookup table requires the client to pass in a recent slot as an argument, and checks that that slot is valid(contained in the slot-hashes cache). The definition of "valid" here is a slot during which a block was actually produced.
Hence you should get your recentSlot parameter with:
const currentSlot = await connection.getSlot();
console.log('currentSlot:', currentSlot);
const slots = await connection.getBlocks(currentSlot - 200);
if (slots.length < 100) {
throw new Error(`Could find only ${slots.length} ${slots} on the main fork`);
}
const recentSlot = slots[0];
OR just specify a finalized
commitment for your getSlot()
rpc call.
const recentSlot = await provider.connection.getSlot("finalized"); // note the commitment
INITIAL:
Address Lookup Tables usually need a cooldown period
after being created, before which they are considered unactivated and cannot be used. You can either try waiting an arbitrary amount of time, for example: