# getBlockNumber

Description: getBlockNumber cheatcode documentation

Note: This document was authored using MDX

  Source: https://github.com/NomicFoundation/hardhat-website/tree/main/src/content/docs/docs/reference/cheatcodes/Environment/get-block-number.mdx

{/* This document contains content copied/adapted from the Foundry Book (MIT licensed). See LICENSE in the parent directory. */}

### Signature

```solidity
function getBlockNumber() external view returns (uint256 height);
```

### Description

Gets the current `block.number`. This is useful in cases where `vm.roll` along with `--via-ir` compilation is used, as `block.number` is assumed to be a constant during a transaction. This means that on every test, multiple calls to `block.number` would get optimized to just returning a constant value, instead of actually accessing the current `block.number`. `vm.getBlockNumber()` avoids this optimization and returns the current `block.number`.

### Examples

```solidity
uint256 height = vm.getBlockNumber();
assertEq(height, uint256(block.number));
vm.roll(10);
assertEq(vm.getBlockNumber(), 10);
```
