-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.ts
36 lines (32 loc) · 1.09 KB
/
wallet.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
import { ethers, Network } from "@dhedge/v2-sdk";
import { poolAddress } from "./config";
console.log('load env');
require("dotenv").config();
export const wallet = (network: Network): ethers.Wallet => {
let url;
switch (network) {
case "arbitrum":
url = `https://arbitrum-mainnet.infura.io/v3/${process.env.INFURA_PROJECT_ID}`;
break;
default:
throw new Error("network not supported");
}
return new ethers.Wallet(process.env.PRIVATE_KEY as string, new ethers.providers.JsonRpcProvider(url));
};
export const checkPoolExistence = async (poolAddress: string, network: Network) => {
try {
const mywallet = wallet(network);
const provider = mywallet.provider;
const code = await provider.getCode(poolAddress);
// console.log("code ",code)
if (code === '0x') {
console.log('No contract found at address:', poolAddress);
} else {
console.log('Contract found at address:', poolAddress);
}
} catch (error) {
console.error('Failed to check pool existence:', error);
}
};
// Example usage:
checkPoolExistence(poolAddress, Network.ARBITRUM);