@verify-network/local
v0.2.0
Published
A local Verify Network for testing a consumer: deploys the real router to a chain you run, and a node that fulfills its requests with real ECVRF proofs.
Readme
@verify-network/local
A local Verify Network for testing a consumer contract end to end. It deploys the real router to a dev chain you run, registers a node, and fulfills that node's requests with real ECVRF proofs.
Install
npm install --save-dev @verify-network/local viemviem (^2.56.3) is a peer dependency. Node 22 or later.
Use
Start a dev chain such as anvil or npx hardhat node. Then deploy the network and start the node:
import {
depositLocalVrfBalance,
LOCAL_VRF_NODE_PRIVATE_KEY,
setupLocalVerifyNetwork,
startLocalVerifyNetworkNode,
} from "@verify-network/local";
import { createPublicClient, createWalletClient, http, parseEther } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { foundry } from "viem/chains";
const transport = http("http://127.0.0.1:8545");
const publicClient = createPublicClient({ chain: foundry, transport });
const walletClient = createWalletClient({
chain: foundry,
transport,
account: privateKeyToAccount(LOCAL_VRF_NODE_PRIVATE_KEY),
});
const routerAddress = await setupLocalVerifyNetwork({ publicClient, walletClient });
await depositLocalVrfBalance({
publicClient,
walletClient,
routerAddress,
account: "0x…", // your consumer
amount: parseEther("1"),
});
const stop = startLocalVerifyNetworkNode({ publicClient, walletClient, routerAddress });
// Deploy your consumer against `routerAddress` and send it requests. The node fulfills each one.
stop();LOCAL_VRF_NODE_PRIVATE_KEY is account #3 of the test test … junk mnemonic, which Hardhat, Anvil, and EDR dev chains fund. The wallet client must use that key's account, or the key you pass as nodePrivateKey. That one account is the router's admin, the node's operator, and the node's enclave key.
API
setupLocalVerifyNetwork({ publicClient, walletClient, nodePrivateKey? })deploys the router diamond, its facets, the trusted-node attestation verifier, and the ECVRF verifier. Then it trusts and registers the node. It resolves to the router's address.depositLocalVrfBalance({ publicClient, walletClient, routerAddress, account, amount })creditsamounttoaccount's balance on the router.startLocalVerifyNetworkNode({ publicClient, walletClient, routerAddress, nodePrivateKey? })polls the router for requests assigned to the node and fulfills them in order. It returns the function that stops it.fulfillLocalVrfRequest({ publicClient, walletClient, routerAddress, requestId, request?, nodePrivateKey? })fulfills one request and resolves to the receipt. Use it instead of the watcher when a test controls when randomness arrives.findLocalVrfRequest({ publicClient, routerAddress, requestId, fromBlock? })reads a request back from itsRandomnessRequestedlog.
The randomness is a real ECVRF output, so @verify-network/protocol verifies it like a fulfillment from the live network. The node's attestation is a trusted-node stand-in, not an AWS Nitro attestation.
License
MIT
