-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTokenName.js
46 lines (39 loc) · 1.47 KB
/
getTokenName.js
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
43
44
45
46
const fs = require('fs');
const path = require('path');
const ethers = require("ethers");
require('dotenv').config()
const provider = new ethers.JsonRpcProvider(process.env.GETH_API)
const getTokenName = async (tokenAddress) => {
// ERC20 ABI (minimal for name/symbol)
const erc20Abi = [
"function name() external view returns (string)",
"function symbol() external view returns (string)",
];
const tokenContract = new ethers.Contract(tokenAddress, erc20Abi, provider);
try {
const name = await tokenContract.name();
const symbol = await tokenContract.symbol();
console.log(`Token ${tokenAddress} Name: ${name}, Symbol: ${symbol}`);
} catch (error) {
console.error('ERC20 token error:', error);
}
}
const getSwapPair = async (swapAddress) => {
// Contract address and ABI (minimal ABI for the public variables)
const contractAddress = swapAddress;
const abi = [
"function token0() external view returns (address)",
"function token1() external view returns (address)",
];
// Create the contract instance
const contract = new ethers.Contract(contractAddress, abi, provider);
try {
const token0 = await contract.token0();
const token1 = await contract.token1();
getTokenName(token0);
getTokenName(token1);
} catch (error) {
console.error('Swap pair error:', error);
}
};
getSwapPair("0x10358Db0e8532455d3374FB09cF3fbeC631B1914")