Icon HelpCircleForumIcon Link

⌘K

Icon HelpCircleForumIcon Link
Tweaking the Blockchain

Icon LinkProducing Blocks

You can force-produce blocks using the produceBlocks helper to achieve an arbitrary block height. This is especially useful when you want to do some testing regarding transaction maturity.

const provider = await Provider.create(FUEL_NETWORK_URL);
 
const block = await provider.getBlock('latest');
if (!block) {
	throw new Error('No latest block');
}
const { time: timeLastBlockProduced } = block;
 
const amountOfBlocksToProduce = 3;
const producedBlockHeigh = await provider.produceBlocks(amountOfBlocksToProduce);
 
const producedBlock = await provider.getBlock(producedBlockHeigh.toNumber());
 
expect(producedBlock).toBeDefined();
 
const oldest = new Date(fromTai64ToDate(timeLastBlockProduced || ''));
const newest = new Date(fromTai64ToDate(producedBlock?.time || ''));
 
expect(newest >= oldest).toBeTruthy();

Icon LinkProducing Blocks With Custom Timestamps

You can also produce blocks with a custom block time using the produceBlocks helper by specifying the second optional parameter.

	const lastBlockTimestamp = fromTai64ToUnix(latestBlock.time);
	const latestBlockNumber = await provider.produceBlocks(3, lastBlockTimestamp + 1000);