{"record":{"id":"9746c6ee583571cb","repo":"FuelLabs/fuels-ts","slug":"connection-refused-9746c6","errorCode":"CONNECTION_REFUSED","errorMessage":"Unable to fetch chain and node info from the network","messagePattern":"Unable to fetch chain and node info from the network","errorType":"error_code","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/account/src/providers/provider.ts","lineNumber":858,"sourceCode":"        chain: deserializeChain(data.chain),\n        nodeInfo: deserializeNodeInfo(data.nodeInfo),\n        consensusParametersTimestamp: Date.now(),\n      }))\n      .then((data) => {\n        Provider.setIncompatibleNodeVersionMessage(data.nodeInfo);\n        Provider.chainInfoCache[this.urlWithoutAuth] = data.chain;\n        Provider.nodeInfoCache[this.urlWithoutAuth] = data.nodeInfo;\n        this.consensusParametersTimestamp = data.consensusParametersTimestamp;\n        return data;\n      })\n      .catch((err) => {\n        const error = new FuelError(\n          FuelError.CODES.CONNECTION_REFUSED,\n          'Unable to fetch chain and node info from the network',\n          { url: this.urlWithoutAuth },\n          err\n        );\n        error.cause = { code: 'ECONNREFUSED' };\n\n        throw error;\n      })\n      .finally(() => {\n        delete Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth];\n      });\n\n    // Set the inflight request to the network request\n    Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth] =\n      getChainAndNodeInfoFromNetwork;\n\n    // Return the cached values once the network request resolves\n    return Provider.inflightFetchChainAndNodeInfoRequests[this.urlWithoutAuth].then((data) => {\n      this.consensusParametersTimestamp = data.consensusParametersTimestamp;\n      return {\n        nodeInfo: Provider.nodeInfoCache[this.urlWithoutAuth],\n        chain: Provider.chainInfoCache[this.urlWithoutAuth],\n      };","sourceCodeStart":840,"sourceCodeEnd":876,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/account/src/providers/provider.ts#L840-L876","documentation":"Thrown by Provider's getChainAndNodeInfo flow when the underlying GraphQL operation to fetch chain and node info rejects for any reason. The .catch wraps the original error in a FuelError coded CONNECTION_REFUSED, attaches metadata { url } and sets error.cause = { code: 'ECONNREFUSED' }, then rethrows. Note the cause is hardcoded as ECONNREFUSED regardless of the real underlying error.","triggerScenarios":"Calling any Provider method that triggers getChainAndNodeInfo (e.g. provider.init(), provider.getChain(), or the first operation requiring cached chain/node info) when the GraphQL request to the node fails — network down, wrong URL, node not running, TLS failure, DNS failure, malformed response, or any rejection from this.operations.getChainAndNodeInfo().","commonSituations":"fuel-core node not started or crashed. Wrong provider URL (typo, missing port, http vs https, auth segment malformed). Firewall/network blocking the port. Node still booting when the SDK connects. CORS in browser. Self-signed cert rejected. DNS resolution failure. The hardcoded ECONNREFUSED cause can mislead diagnosis when the real cause differs (e.g. HTTP 404, parse error).","solutions":["Verify the fuel-core node is running and reachable: curl the provider URL's /health or GraphQL endpoint directly.","Double-check the Provider URL (scheme, host, port, optional auth) matches the running node.","Ensure network/firewall/DNS allows the connection; in a browser check CORS and mixed-content.","Inspect err.cause / the wrapped original error (the third FuelError constructor arg) to find the true failure, since cause.code is hardcoded to ECONNREFUSED.","Retry with backoff for transient network blips; implement a reconnection strategy for long-lived clients."],"exampleFix":"// before\nconst provider = new Provider('http://127.0.0.1:4000'); // node not running\nawait provider.getChain(); // throws CONNECTION_REFUSED\n\n// after\n// 1) start fuel-core, then:\nconst provider = new Provider('http://127.0.0.1:4000');\ntry {\n  await provider.getChain();\n} catch (e) {\n  // e.cause.code is hardcoded 'ECONNREFUSED'; read e.metadata and the wrapped error\n  console.error('real cause:', e.metadata, e);\n}","handlingStrategy":"retry","validationCode":"async function assertNodeReachable(url: string) {\n  const res = await fetch(url, { method: 'GET' });\n  if (!res.ok && res.status !== 405) throw new Error(`node not reachable at ${url}`);\n}\nawait assertNodeReachable(providerUrl);\nconst provider = new Provider(providerUrl);","typeGuard":"import { FuelError } from '@fuel-ts/errors';\nconst isConnectionRefused = (e: unknown): boolean =>\n  e instanceof FuelError && e.code === FuelError.CODES.CONNECTION_REFUSED;","tryCatchPattern":"import { FuelError } from '@fuel-ts/errors';\nasync function withRetry<T>(fn: () => Promise<T>, retries = 3): Promise<T> {\n  for (let i = 0; ; i++) {\n    try { return await fn(); }\n    catch (e) {\n      if (e instanceof FuelError && e.code === FuelError.CODES.CONNECTION_REFUSED && i < retries) {\n        await new Promise(r => setTimeout(r, 250 * 2 ** i));\n        continue;\n      }\n      throw e;\n    }\n  }\n}\n// usage:\nconst chain = await withRetry(() => provider.getChain());","preventionTips":["Confirm the node is up and the URL/port is correct before constructing a Provider.","Read the wrapped original error (FuelError's 4th constructor arg / cause chain) since cause.code is hardcoded ECONNREFUSED.","In browsers, ensure CORS and HTTPS/mixed-content rules allow the endpoint.","Use a retry-with-backoff wrapper for transient failures on long-lived clients."],"tags":["provider","network","graphql","connection","fuel-core"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}