Web3: could not detect network (event="noNetwork", code=NETWORK_ERROR)
ethers asks the endpoint for its chain id before it will do anything else, and that call failed, so the provider never finished starting. A wrong URL is only one cause: a missing key in the path, a rate limited key, a browser CORS rejection and an http endpoint on an https page all look identical from here.
Quick fix
Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.
# Prove the endpoint answers before blaming the library
curl -s -X POST $RPC -H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_chainId","params":[]}'
// Skip the detection round trip when the chain is known
const provider = new ethers.JsonRpcProvider(RPC_URL, 1, { staticNetwork: true });
// A 401 or 429 from the provider also reads as noNetwork, so log the detail
provider.on('error', (e) => console.error(e.info ?? e));
// In the browser the wallet already knows its network
const browserProvider = new ethers.BrowserProvider(window.ethereum);
// Env vars that never reached the bundle are the usual local cause
console.log(process.env.RPC_URL ?? 'undefined'); // Vite needs a VITE_ prefix
# A local node that is not up yet: wait for it rather than constructing early
cast block-number --rpc-url http://127.0.0.1:8545
How to diagnose Web3 errors
Web3 errors are unusually terse because the EVM reports failure without explanation by default. execution reverted means a require or revert triggered. The reason string is present in the return data but most libraries discard it. Nonce errors reflect the strict sequential ordering of transactions per account, so a stuck transaction blocks every one behind it.
If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.
- Simulate before sending:
eth_callagainst the same block returns the revert reason string that a submitted transaction hides. - Use a transaction tracer (Tenderly, Foundry's
cast run, or a node'sdebug_traceTransaction) to see the exact opcode and contract where execution reverted. - For nonce errors, query the account's pending nonce (
eth_getTransactionCountwith thependingtag) rather than tracking it locally. - To replace a stuck transaction, resend with the same nonce and a materially higher gas price: most nodes require at least a 10% increase.
- Check the chain ID matches the network you intend. Signing for the wrong chain produces confusing rejection messages.
Tools worth reaching for
cast (Foundry)eth_call simulationTenderly / block explorer tracerdebug_traceTransaction
Authoritative references
Primary documentation for this error, worth reading before applying any fix in production.
Related Web3 errors
- ethers v6: Cannot read properties of undefined (reading 'Web3Provider')ethers v6 removed the providers, utils and constants namespaces, so v5 code such as…
- MetaMask Tx Signature: User denied transaction signature (4001)Code 4001 is the EIP-1193 "user rejected" error: the person clicked Reject or closed the…
- Solidity: CompilerError: Stack too deep. Try compiling with --via-irThe EVM can only reach the top 16 slots of its stack, and the function the error points at…
- Web3: already known / ALREADY_EXISTS when sending a transactionThe node already holds a transaction with this exact hash in its pool, so the resend is…
- Web3: cannot estimate gas; transaction may fail or may require manual gas limitThe node ran the transaction against current state and it reverted, so no gas figure could be…
- Web3: execution revertedThe smart contract reverted. Solidity custom errors or revert strings often explain the exact…
- Web3: gas required exceeds allowance (0)The node simulated the transaction and found the sender cannot cover it, so the allowance it…
- Web3: insufficient funds for gas * price + valueThe wallet lacks enough native token to pay transaction value plus gas. This is separate from…
Browse other categories
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Python 35Imports, virtual environments, encoding, concurrency and dependency conflicts.
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
Something missing or wrong?
This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.