-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
Copy patherc20.ts
42 lines (37 loc) · 1.08 KB
/
erc20.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as chains from "viem/chains"
import { parseArgs } from "node:util"
import { raise } from "../src/utilities/index.ts"
import { createPublicClient, erc20Abi, fallback, getAddress, http } from "viem"
const { values } = parseArgs({
args: process.argv.slice(2),
options: {
"chain-id": { type: "string" },
address: { type: "string" }
}
})
const chainId = values["chain-id"] ?? raise("Chain ID is required")
const address = getAddress(values["address"] ?? raise("Address is required"))
const chain = Object.values(chains).find(chain => chain.id === Number(chainId))
const client = createPublicClient({
transport: fallback([http(chain?.rpcUrls.default.http.at(0))])
})
const [name, symbol, decimals] = await Promise.all(
[
{
abi: erc20Abi,
address,
functionName: "name"
} as const,
{
abi: erc20Abi,
address,
functionName: "symbol"
} as const,
{
abi: erc20Abi,
address,
functionName: "decimals"
} as const
].map(contract => client.readContract(contract))
)
console.info({ address, name, symbol, decimals })