hemi-viem
v2.8.0
Published
Viem extension for the Hemi network
Downloads
2,357
Readme
Hemi Viem
Viem extension for the Hemi network. It includes:
- Chain definitions!
- Bitcoin finality helper!
- Bitcoin Kit wrappers!
Installation
npm install viem hemi-viemExample
// example.js
import { createPublicClient, http } from "viem";
import {
hemiPublicBitcoinKitActions,
hemiPublicOpNodeActions,
hemiSepolia,
} from "hemi-viem";
const parameters = { chain: hemiSepolia, transport: http() };
const client = createPublicClient(parameters)
.extend(hemiPublicOpNodeActions())
.extend(hemiPublicBitcoinKitActions());
const blockNumber = await client.getBlockNumber();
const block = await client.getBlock({ blockNumber: blockNumber - 100n });
const btcFinality = await client.getBtcFinalityByBlockHash(block);
console.log(btcFinality);
const bitcoinKitAddress = "0x0000000000000000000000000000000000000000"; // example address
const btcHeader = await client.getLastHeader({ bitcoinKitAddress });
console.log(btcHeader);Output:
$ node example.js
{
l2_keystone: {
version: 1,
l1_block_number: 5868140,
l2_block_number: 596350,
parent_ep_hash: '3fe407f9eec38ce9fa0f6d159adca4ac8739013d380e1d7215b721c7e345ae88',
prev_ep_keystone_hash: '6b65018eb33048494f2e21ffdd081ae376b125f12e62ab88e77b1461503540fb',
state_root: 'b3b9f5b810038466290a7c4bff08a260a472d67fed230a27d89de1322490fb51',
ep_hash: 'd186c2da80f2c79490f644e4af714ee1f5790a4e806028cac0e64a2010a41974'
},
btc_pub_height: 2814228,
btc_pub_header_hash: '1a262fa78618f4b7fa8d5d37eed32f3a0bb67ab09d808e035500000000000000',
btc_finality: 8
}
{
height: 2814236,
blockHash: '0x00000000f71ba71af42fb2a356affa1439bc2adea0bf67880fc30f28237622e7',
version: 536870912,
previousBlockHash: '0x000000000000002f3cc7a5f9ed589b734808fff6d67c0f8a9385f6146c80297b',
merkleRoot: '0x1799d4002cd58d15a764cee0919edf358bf36ace4fa4c6e78250336eafe12184',
timestamp: 1715273381,
bits: 486604799,
nonce: 4137790000
}Development
This project uses pnpm as its package manager. The exact version is pinned in the packageManager field of package.json.
Enabling pnpm with corepack
Corepack ships with Node.js and manages the pnpm version for you, so it always matches the one pinned in this repo. Just enable it once:
corepack enableFrom then on, running any pnpm command inside the project automatically uses the pinned version—no manual install needed.
Common commands
pnpm install # install dependencies
pnpm run build # build ESM, CJS and type declarations
pnpm test # run unit tests
pnpm run test:e2e # run end-to-end tests
pnpm run lint # lint with ESLint
pnpm run format:check # check formatting with Prettier
pnpm run tsc # type-check without emitting