Icon SunFilledIcon MoonStars

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 { height: latestBlockNumberBeforeProduce } = block;
 
const amountOfBlocksToProduce = 3;
const latestBlockNumber = await provider.produceBlocks(amountOfBlocksToProduce);
 
expect(latestBlockNumber.toHex()).toEqual(
	latestBlockNumberBeforeProduce.add(amountOfBlocksToProduce).toHex()
);

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);

Was this page helpful?