Registry / web-framework / eth-adapter

eth-adapter

JSON →
library1.0.7jsnpmunverified

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.

npm install eth-adapter
INSTALL
IMPORT
SIG · ETH-ADAPTER
E
eth-adapter
web-frameworkjavascriptv1.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import ethAdapter from 'eth-adapter'
const ethAdapter = require('eth-adapter')
Package is ESM-first; CJS requires setting ETH_ADAPTER_USE_CJS='TRUE' in .env before transpilation.
ethAdapter
const ethAdapter = require('eth-adapter')
import { ethAdapter } from 'eth-adapter'
Default export only; named import is incorrect. CJS require works only if transpiled to CJS.
types (TypeScript)
import type { EthAdapter, ContractMethods } from 'eth-adapter'
TypeScript types are bundled; use 'import type' for type-only imports. The exact type names depend on internal types.

Shows setup steps (install, artifacts, ethpst), two ways to connect (wallet/JSON RPC), and calling a generated contract method with error handling.

// Setup: npm install eth-adapter, create artifacts/ folder with compiled ABI JSON, set CONTRACT_ADDRESS_STORAGE in .env // Run npx ethpst before starting app (e.g., in script: "start": "npx ethpst; react-scripts start") import ethAdapter from 'eth-adapter'; // Connect to injected wallet (MetaMask) or use JSON RPC provider await ethAdapter.connectToWeb3Wallet(); // OR: ethAdapter.setJsonRpcProvider('https://localhost:8545'); // Call a generated contract method const result = await ethAdapter.contractMethods.STORAGE.retrieve_view_IN0_OUT1(); if (result.error) { console.error('Contract call error:', result.error); } else { console.log('Stored value:', result); }
ethpst --version
Debug
Known issues
breakingContract methods require deconstructed parameter objects {paramName: value}, not positional arguments.
fix
Call methods with an object: contractMethods.CONTRACT.foo_IN1_OUT1({param: val}) instead of contractMethods.CONTRACT.foo_IN1_OUT1(val).
affects: >=1.0.0
gotchaEnvironment variable naming: CONTRACT_ADDRESS_{UPPERCASE_CONTRACT_NAME} (e.g., CONTRACT_ADDRESS_STORAGE). For React, REACT_APP_ prefix variations are also parsed.
fix
Ensure .env keys follow pattern CONTRACT_ADDRESS_{NAME} where {NAME} matches artifact filename without .json, uppercased.
affects: >=1.0.0
gotchaethpst CLI must be run whenever ABIs change; otherwise, generated methods may be stale.
fix
Run npx ethpst before starting dev server. For React, prepend scripts with npx ethpst;.
affects: >=1.0.0
deprecatedethAdapter.ethers is exposed but direct ethers usage is discouraged; use generated methods instead.
fix
Prefer ethAdapter.contractMethods over raw ethers calls.
affects: >=1.0.0
breakingCJS support requires explicit .env setting: ETH_ADAPTER_USE_CJS='TRUE'. Without it, default is ESM only.
fix
Add ETH_ADAPTER_USE_CJS='TRUE' to .env and re-run ethpst for CJS output.
affects: >=1.0.0
Errors
Common errors & fixes
ethAdapter.contractMethods.STORAGE is undefined
ethpst hasn't been run or .env address missing/incorrect; artifact file not found or named incorrectly.
fix
Ensure artifact JSON is in /artifacts, .env has CONTRACT_ADDRESS_STORAGE=0x..., and run npx ethpst.
TypeError: contractMethods.STORAGE.retrieve_view_IN0_OUT1 is not a function
Method called before connecting to provider or function name mismatch (wrong IN/OUT count).
fix
Call await ethAdapter.connectToWeb3Wallet() or setJsonRpcProvider() first. Check the generated method signature; ensure parameter object is passed.
Cannot find module 'eth-adapter' or its corresponding type declarations
Package not installed, or missing TypeScript types (though types are bundled).
fix
Run npm install eth-adapter. For TS, ensure tsconfig.json includes 'node_modules/@types' or 'moduleResolution': 'node'.
ethpst: command not found
eth-adapter not installed globally or npx not used.
fix
Use npx ethpst or install as devDependency and run via npm scripts.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies
ethersrequiredCore dependency for all Ethereum interaction; eth-adapter wraps ethers internally.
dotenvoptionalUsed to parse .env files for contract addresses and configuration.
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
eth-adapter — npm install eth-adapter · libregistry