ethers.js v6¶
Not executed for this release
Pin the version you test (e.g. npm install ethers@6.13.4 --save-exact). The JSON-RPC behaviour it relies on is
verified in the reference.
pqwerai.ts
import { JsonRpcProvider, Wallet, Contract, parseEther } from "ethers";
const provider = new JsonRpcProvider(process.env.PQWERAI_RPC ?? "http://127.0.0.1:8545", 77240, { staticNetwork: true });
if ((await provider.getNetwork()).chainId !== 77240n) throw new Error("not PQWERAI testnet");
console.log("head", await provider.getBlockNumber());
// Load an encrypted keystore (never a raw key in source code)
const wallet = (await Wallet.fromEncryptedJson(keystoreJson, password)).connect(provider);
const tx = await wallet.sendTransaction({ to: "0x000000000000000000000000000000000000dEaD", value: parseEther("0.01") });
const receipt = await tx.wait();
// PQWERAI finality (do not use provider.getBlock("finalized"): it errors on PQWERAI)
async function isFinal(blockNumber: number, blockHash: string) {
const s = await provider.send("g4_status", []);
return s.finalized_height >= blockNumber && (await provider.getBlock(blockNumber))?.hash === blockHash;
}
const counter = new Contract(address, ["function get() view returns (uint256)", "function increment()"], wallet);
await (await counter.increment()).wait();
console.log(await counter.get());
staticNetwork: trueavoids repeatedeth_chainIdpolling.- Event subscriptions use polling (HTTP only); keep ranges within 5000 blocks.
Sources at 72057fe3ec: testnet/release/network/network.json
Found a problem? Report a documentation issue · Build testnet-rc1+72057fe3ec