UNPKG

hardhat

Version:

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

29 lines (22 loc) 747 B
import type { NewUtilsTaskActionFunction } from "../../types.js"; import { assertHardhatInvariant } from "@nomicfoundation/hardhat-errors"; import { hexStringToBigInt } from "@nomicfoundation/hardhat-utils/hex"; const fetchBlockNumberAction: NewUtilsTaskActionFunction = async ( _taskArguments, hre, ) => { const connection = await hre.network.create(); try { const blockNumber = await connection.provider.request({ method: "eth_blockNumber", }); assertHardhatInvariant( typeof blockNumber === "string", "eth_blockNumber should return a string", ); console.log(hexStringToBigInt(blockNumber).toString()); } finally { await connection.close(); } }; export default fetchBlockNumberAction;