Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.