{"id":25552,"library":"eth-adapter","title":"eth-adapter","description":"A high-level Ethereum abstraction layer that auto-generates typed contract methods from ABI/artifact files, reducing boilerplate over ethers.js or web3.js. Version 1.0.7 supports both injected wallets (e.g., MetaMask) and JSON RPC providers. It includes a CLI transpiler (ethpst) that pre-processes ABI files and exposes environment-based contract address configuration. Ships TypeScript types. Notable differentiator: generates per-contract methods with IN/OUT naming to handle overloaded functions automatically.","status":"active","version":"1.0.7","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install eth-adapter","lang":"bash","label":"npm"},{"cmd":"yarn add eth-adapter","lang":"bash","label":"yarn"},{"cmd":"pnpm add eth-adapter","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for all Ethereum interaction; eth-adapter wraps ethers internally.","package":"ethers","optional":false},{"reason":"Used to parse .env files for contract addresses and configuration.","package":"dotenv","optional":true}],"imports":[{"note":"Package is ESM-first; CJS requires setting ETH_ADAPTER_USE_CJS='TRUE' in .env before transpilation.","wrong":"const ethAdapter = require('eth-adapter')","symbol":"default","correct":"import ethAdapter from 'eth-adapter'"},{"note":"Default export only; named import is incorrect. CJS require works only if transpiled to CJS.","wrong":"import { ethAdapter } from 'eth-adapter'","symbol":"ethAdapter","correct":"const ethAdapter = require('eth-adapter')"},{"note":"TypeScript types are bundled; use 'import type' for type-only imports. The exact type names depend on internal types.","wrong":"","symbol":"types (TypeScript)","correct":"import type { EthAdapter, ContractMethods } from 'eth-adapter'"}],"quickstart":{"code":"// Setup: npm install eth-adapter, create artifacts/ folder with compiled ABI JSON, set CONTRACT_ADDRESS_STORAGE in .env\n// Run npx ethpst before starting app (e.g., in script: \"start\": \"npx ethpst; react-scripts start\")\n\nimport ethAdapter from 'eth-adapter';\n\n// Connect to injected wallet (MetaMask) or use JSON RPC provider\nawait ethAdapter.connectToWeb3Wallet();\n// OR: ethAdapter.setJsonRpcProvider('https://localhost:8545');\n\n// Call a generated contract method\nconst result = await ethAdapter.contractMethods.STORAGE.retrieve_view_IN0_OUT1();\nif (result.error) {\n  console.error('Contract call error:', result.error);\n} else {\n  console.log('Stored value:', result);\n}","lang":"typescript","description":"Shows setup steps (install, artifacts, ethpst), two ways to connect (wallet/JSON RPC), and calling a generated contract method with error handling."},"warnings":[{"fix":"Call methods with an object: contractMethods.CONTRACT.foo_IN1_OUT1({param: val}) instead of contractMethods.CONTRACT.foo_IN1_OUT1(val).","message":"Contract methods require deconstructed parameter objects {paramName: value}, not positional arguments.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure .env keys follow pattern CONTRACT_ADDRESS_{NAME} where {NAME} matches artifact filename without .json, uppercased.","message":"Environment variable naming: CONTRACT_ADDRESS_{UPPERCASE_CONTRACT_NAME} (e.g., CONTRACT_ADDRESS_STORAGE). For React, REACT_APP_ prefix variations are also parsed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Run npx ethpst before starting dev server. For React, prepend scripts with npx ethpst;.","message":"ethpst CLI must be run whenever ABIs change; otherwise, generated methods may be stale.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer ethAdapter.contractMethods over raw ethers calls.","message":"ethAdapter.ethers is exposed but direct ethers usage is discouraged; use generated methods instead.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Add ETH_ADAPTER_USE_CJS='TRUE' to .env and re-run ethpst for CJS output.","message":"CJS support requires explicit .env setting: ETH_ADAPTER_USE_CJS='TRUE'. Without it, default is ESM only.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure artifact JSON is in /artifacts, .env has CONTRACT_ADDRESS_STORAGE=0x..., and run npx ethpst.","cause":"ethpst hasn't been run or .env address missing/incorrect; artifact file not found or named incorrectly.","error":"ethAdapter.contractMethods.STORAGE is undefined"},{"fix":"Call await ethAdapter.connectToWeb3Wallet() or setJsonRpcProvider() first. Check the generated method signature; ensure parameter object is passed.","cause":"Method called before connecting to provider or function name mismatch (wrong IN/OUT count).","error":"TypeError: contractMethods.STORAGE.retrieve_view_IN0_OUT1 is not a function"},{"fix":"Run npm install eth-adapter. For TS, ensure tsconfig.json includes 'node_modules/@types' or 'moduleResolution': 'node'.","cause":"Package not installed, or missing TypeScript types (though types are bundled).","error":"Cannot find module 'eth-adapter' or its corresponding type declarations"},{"fix":"Use npx ethpst or install as devDependency and run via npm scripts.","cause":"eth-adapter not installed globally or npx not used.","error":"ethpst: command not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}