Skip to content

Commit e8e3368

Browse files
kien-ngojnsdls
andauthored
Add extension: isERC20 (#2846)
Signed-off-by: Jonas Daniels <jonas.daniels@outlook.com> Co-authored-by: Jonas Daniels <jonas.daniels@outlook.com>
1 parent e1cd07c commit e8e3368

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

.changeset/tidy-zoos-compare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Add isERC20 extension

packages/thirdweb/src/exports/extensions/erc20.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// read
2+
export { isERC20 } from "../../extensions/erc20/read/isERC20.js";
23
export {
34
getBalance,
45
type GetBalanceParams,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { BaseTransactionOptions } from "../../../transaction/types.js";
2+
import { supportsInterface } from "../../erc165/__generated__/IERC165/read/supportsInterface.js";
3+
4+
/**
5+
* Check if a contract supports the ERC20 interface.
6+
* @param options - The transaction options.
7+
* @returns A boolean indicating whether the contract supports the ERC20 interface.
8+
* @extension ERC20
9+
* @example
10+
* ```ts
11+
* import { isERC20 } from "thirdweb/extensions/erc20";
12+
* const result = await isERC20({ contract });
13+
* ```
14+
*/
15+
export function isERC20(options: BaseTransactionOptions) {
16+
return supportsInterface({
17+
contract: options.contract,
18+
interfaceId: "0x36372b07",
19+
});
20+
}

0 commit comments

Comments
 (0)