Hardhat plugin
@bkc-network-lib/hardhat makes hardhat run, hardhat test, Hardhat Ignition and hardhat verify work against BKC without changing your scripts.
Install
The plugin targets Hardhat 2. On that line, several Nomic packages have released majors that require Hardhat 3 and npm picks those by default, so pin the versions:
npm i -D hardhat@^2.26.0 "@nomicfoundation/hardhat-ethers@^3.0.8" ethers@^6
npm i -D @bkc-network-lib/hardhat
npm i -D @nomicfoundation/hardhat-verify # for hardhat verify
npm i -D "@nomicfoundation/hardhat-ignition-ethers@^0.15.0" # only if you use IgnitionConfigure
// hardhat.config.js
require("@nomicfoundation/hardhat-ethers");
require("@bkc-network-lib/hardhat");
require("dotenv").config();
module.exports = {
solidity: { version: "0.8.24", settings: { optimizer: { enabled: true, runs: 200 } } },
sourcify: { enabled: false }, // BKC is not on Sourcify
networks: {
bkc: {
url: process.env.BKC_EVM_RPC, // https://rpc.bkc.network — reads
chainId: 262144,
bkc: {
cosmosRpcUrl: process.env.BKC_COSMOS_RPC, // https://comet-rpc.bkc.network — writes
seed: process.env.BKC_SEED, // 32-byte hex ML-DSA-65 seed
gasPrice: "5000000bkc",
explorerUrl: process.env.BKC_EXPLORER, // https://explorer.bkc.network
},
},
},
};| Field | Required | Meaning |
|---|---|---|
url | yes | EVM JSON-RPC |
chainId | recommended | 262144 |
bkc.cosmosRpcUrl | yes | CometBFT RPC, where writes are broadcast |
bkc.seed | one of | 32-byte ML-DSA-65 seed, hex, 0x optional |
bkc.mnemonic | one of | BIP-39 phrase, derived with BKC's HKDF scheme |
bkc.hdPath | no | default m/44'/118'/0'/0/0 |
bkc.bech32Prefix | no | default bkc |
bkc.gasPrice | no, but set it | 5000000bkc. Unset, the SDK default applies (66,666,666,667 per gas, ~13,000× the minimum) — bkc-doctor flags it |
bkc.baseGasLimit | no | Cosmos gas for the signature envelope, before the EVM budget |
bkc.explorerUrl | no | Blockscout URL — enough for hardhat verify |
bkc.explorerApiUrl | no | when the API is not at <explorerUrl>/api |
Nothing about the chain is compiled into the package: endpoints, chain id, gas price and explorer all come from your config, so a testnet reset or a moved node is an .env edit, not a plugin release. The published package reads no environment variables itself.
TypeScript configs (hardhat.config.ts) work and the bkc block is typed; Hardhat 2 loads them through ts-node, which needs TypeScript 5.
Tasks
npx hardhat bkc-new-account # a development account: seed + addresses
npx hardhat bkc-doctor --network bkc # checks endpoints, account, balance, gas price
npx hardhat bkc-account --network bkc # the account in use, balance and nonceRun bkc-doctor first on a new machine; every failing line says what to fix.
What the plugin does
eth_sendTransactionis wrapped inMsgExecuteEvmCall, signed and broadcast; the EVM hash comes back sotx.wait()resolves against a real receipt.- Accounts come from the chain. The network is forced to
accounts: "remote"andeth_accountsreturns the ML-DSA account, soethers.getSigners()works. A private key innetworks.<name>.accountsis ignored with a warning. - Writes are serialised.
call_noncemust equal the Cosmos sequence exactly, so concurrent writes would reject each other;Promise.all([...])in a script is queued instead. - Reads are untouched —
eth_call,eth_getLogs, receipts and gas estimation go straight to the EVM endpoint. hre.network.bkc.address()returns{ bech32, evm }.
const factory = await hre.ethers.getContractFactory("Storage");
const storage = await factory.deploy();
await storage.waitForDeployment();
await (await storage.set(42)).wait();Hardhat Ignition
Works, with two adjustments:
module.exports = {
// …
ignition: { requiredConfirmations: 1 }, // blocks are under a second
};npx hardhat ignition deploy ignition/modules/Storage.js --network bkcIgnition refuses to start while earlier transactions from the same account are still settling (IGN403); let a block or two pass after a script that sent some.
Limits
- No local signing:
eth_sign,personal_sign,eth_signTypedData_v4fail with an explanation. eth_sendRawTransactionis not supported, and never will be.- One account per network.
See What does not work for Foundry, Remix and other tools.
