Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
ethers-abitype
Advanced tools
Improves ethers.js with strict ABI typing
Makes ethers.js much better. Adds strict typing for Contract class based on ABI using the abitype library. For those who like this feature in viem, but not viem itself.
npm i ethers-abitype
The library provides a special type for the Contract class and in your code you only need to override the type
Example without ABI typing (your regular ethers.js code):
import { Contract } from "ethers";
const address = "0x...";
const abi = [
/*..*/
];
const contract = new Contract(address, abi);
Example code with ABI typing:
import { Contract } from "ethers";
+ import { TypedContract } from "ethers-abitype";
const address = "0x...";
const abi = [
/*..*/
- ];
+ ] as const;
- const contract = new Contract(address, abi);
+ const contract = new Contract(address, abi) as unknown as TypedContract<typeof abi>;
Congratulations, you now have a typed contract!
Alternatively, the library provides another approach. You can use a small wrapper function for creating an already typed contract:
- import { Contract } from "ethers";
+ import { typedContract } from "ethers-abitype";
const address = "0x...";
const abi = [
/*..*/
- ];
+ ] as const;
- const contract = new Contract(address, abi);
+ const contract = typedContract(address, abi);
Important! Your ABI must be declared using a const assertion. This means that you will not be able to store them in a JSON file, because TypeScript doesn't support importing JSON as const
You can also use Human-Readable ABI using parseAbi
from abitype
:
import { typedContract } from "ethers-abitype";
import { parseAbi } from "abitype";
const address = "0x...";
const abi = parseAbi([
"function symbol() external returns (string)",
"function decimals() external returns (uint256)",
/* ... */
]);
const contract = typedContract(address, abi);
FAQs
Improves ethers.js with strict ABI typing
We found that ethers-abitype demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.