Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
ethers-abitype
Advanced tools
Readme
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
The npm package ethers-abitype receives a total of 18 weekly downloads. As such, ethers-abitype popularity was classified as not popular.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.