Skip to Content
Playground@core · EspaceClient

EspaceClient

Explore the full EspaceClient read API. EVM_TESTNET ships with @cfxdevkit/core — no separate network config file needed.

network:Testnet· chain 71
import { EspaceClient, EVM_TESTNET, formatUnits } from '@cfxdevkit/core'

// EVM_TESTNET ships with @cfxdevkit/core: id 71, RPC URL, explorer — no config file needed
const rpcUrl  = EVM_TESTNET.rpcUrls.default.http[0]
const chainId = EVM_TESTNET.id

console.log('-- Network: ' + EVM_TESTNET.name + ' --')
console.log('Chain ID : ' + chainId)
console.log('RPC      : ' + rpcUrl)
console.log('Explorer : ' + EVM_TESTNET.blockExplorers?.default.url)

const client = new EspaceClient({ chainId, rpcUrl })

;(async () => {
// Run all read queries in parallel
const [connected, blockNumber, onChainId, gasPrice] = await Promise.all([
  client.isConnected(),
  client.getBlockNumber(),
  client.getChainId(),
  client.getGasPrice(),
])

console.log('-- Live Chain Data --')
console.log('Connected : ' + connected)
console.log('Block #   : ' + blockNumber.toString())
console.log('Chain ID  : ' + onChainId)
console.log('Gas Price : ' + formatUnits(gasPrice, 9) + ' Gwei')

// client.publicClient is the raw viem PublicClient
const block = await client.publicClient.getBlock({ blockTag: 'latest' })
console.log('-- Latest Block --')
console.log('Hash      : ' + (block.hash?.slice(0, 20) ?? 'n/a') + '...')
console.log('Txns      : ' + block.transactions.length)
console.log('Gas Used  : ' + block.gasUsed.toString())
console.log('Timestamp : ' + new Date(Number(block.timestamp) * 1000).toUTCString())
})().catch(console.error)


How it works

  1. EVM_TESTNET is exported by @cfxdevkit/core{ id: 71, rpcUrls, blockExplorers }. No config file needed.
  2. new EspaceClient({ chainId, rpcUrl }) wraps viem’s PublicClient with a simpler typed API.
  3. isConnected, getBlockNumber, getChainId, getGasPrice all run in parallel via Promise.all.
  4. client.publicClient gives raw viem access for getBlock, getLogs, simulateContract, and anything else not wrapped.
import { EspaceClient, EVM_TESTNET } from '@cfxdevkit/core' const client = new EspaceClient({ chainId: EVM_TESTNET.id, rpcUrl: EVM_TESTNET.rpcUrls.default.http[0], })
Last updated on