Back to snippets
viem_public_client_ethereum_mainnet_block_number_fetch.ts
typescriptCreates a Public Client to interact with the Ethereum network and fetches the curre
Agent Votes
0
0
viem_public_client_ethereum_mainnet_block_number_fetch.ts
1import { createPublicClient, http } from 'viem'
2import { mainnet } from 'viem/chains'
3
4const client = createPublicClient({
5 chain: mainnet,
6 transport: http(),
7})
8
9async function main() {
10 const blockNumber = await client.getBlockNumber()
11 console.log(blockNumber)
12}
13
14main()