Skip to content

Commit be35797

Browse files
committed
fix(ens): correct default mainnet registry checksum and require explicit registry on non-mainnet
- Correct default ENS registry address checksum (mainnet) - If ENS_REGISTRY_ADDRESS not provided and chainId != 1, fail with clear guidance - Normalize provided address via ethers.getAddress(lowercase) to avoid mixed-case checksum errors
1 parent e7d0623 commit be35797

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

scripts/update-ens.mjs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Requires: ETHEREUM_RPC_URL, ENS_PRIVATE_KEY, ENS_NAME, IPFS_CID
44
// Optional: ENS_REGISTRY_ADDRESS (defaults to mainnet registry)
55

6-
import { Contract, JsonRpcProvider, Wallet, keccak256, toUtf8Bytes, getBytes, concat } from 'ethers'
6+
import { Contract, JsonRpcProvider, Wallet, keccak256, toUtf8Bytes, getBytes, concat, getAddress } from 'ethers'
77
import contentHash from 'content-hash'
88

99
function requiredEnv(name) {
@@ -29,11 +29,21 @@ async function main() {
2929
const IPFS_CID = requiredEnv('IPFS_CID')
3030
const ETHEREUM_RPC_URL = requiredEnv('ETHEREUM_RPC_URL')
3131
const ENS_PRIVATE_KEY = requiredEnv('ENS_PRIVATE_KEY')
32-
const ENS_REGISTRY_ADDRESS = process.env.ENS_REGISTRY_ADDRESS || '0x00000000000C2E074eC69A0dFb2997Ba6C7d2e1e'
32+
// Default to mainnet ENS registry only if connecting to mainnet; otherwise require explicit address
33+
const RAW_REGISTRY = process.env.ENS_REGISTRY_ADDRESS || '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e'
3334

3435
const provider = new JsonRpcProvider(ETHEREUM_RPC_URL)
3536
const signer = new Wallet(ENS_PRIVATE_KEY, provider)
3637

38+
const network = await provider.getNetwork()
39+
const isMainnet = (network?.chainId === 1n)
40+
if (!process.env.ENS_REGISTRY_ADDRESS && !isMainnet) {
41+
throw new Error(`ENS_REGISTRY_ADDRESS not set for chainId=${network?.chainId}. Provide the registry address for your network (e.g., Holesky).`)
42+
}
43+
44+
// Normalize and checksum address (accept lower/upper/mixed by forcing lowercase then checksumming)
45+
const ENS_REGISTRY_ADDRESS = getAddress(RAW_REGISTRY.toLowerCase())
46+
3747
const REGISTRY_ABI = [
3848
'function resolver(bytes32 node) view returns (address)'
3949
]
@@ -70,4 +80,3 @@ main().catch((err) => {
7080
console.error(err)
7181
process.exit(1)
7282
})
73-

0 commit comments

Comments
 (0)