forked from ethereum-attestation-service/eas-is-true
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
58 lines (48 loc) · 2.13 KB
/
config.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { JsonRpcProvider, Contract, FunctionFragment } from "ethers";
export const POAP_CONTRACT_ADDRESS = '0x22C1f6050E56d2876009903609a2cC3fEf83B415';
export const rpc_url: string = process.env.NEXT_PUBLIC_RPC_URL || 'https://rpc.ankr.com/eth';
// POAP ABI (including necessary functions for POAP interaction)
export const POAP_ABI = [
'function balanceOf(address owner) view returns (uint256)',
'function tokenOfOwnerByIndex(address owner, uint256 index) view returns (uint256)',
'function tokenURI(uint256 tokenId) view returns (string)',
'function ownerOf(uint256 tokenId) view returns (address)',
'function name() view returns (string)',
'function symbol() view returns (string)',
] as const;
// Create a provider
export const provider = new JsonRpcProvider(rpc_url);
// Create a contract instance
export const poapContract = new Contract(
POAP_CONTRACT_ADDRESS,
POAP_ABI,
provider
);
// Define the type for POAP_ABI keys
export type POAPContractMethod = (typeof POAP_ABI)[number];
// Function to safely interact with the POAP contract
export const safePoapContractCall = async <T>(
method: POAPContractMethod,
args: any[]
): Promise<T | null> => {
try {
const fragment = FunctionFragment.from(method);
if (fragment && typeof poapContract[fragment.name as keyof typeof poapContract] === 'function') {
const result = await (poapContract[fragment.name as keyof typeof poapContract] as Function)(...args);
return result as T;
}
throw new Error(`Method ${method} is not a function`);
} catch (error) {
console.error(`Error calling ${method}:`, error);
return null;
}
};
// Export necessary ethers components for use in other parts of the application
export { JsonRpcProvider, Contract };
// TODO: Update other files using ethers to v6 API
// 1. Identify all files using ethers
// 2. Update imports to use named imports where necessary
// 3. Update provider creation (JsonRpcProvider instead of providers.JsonRpcProvider)
// 4. Update contract interactions (no need for .connect() in most cases)
// 5. Update event listeners and error handling
// 6. Update transaction sending and waiting for confirmations