Skip to content

Commit

Permalink
refactor: use rpc-handler for ENS lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
rndquu committed Oct 9, 2024
1 parent dbe772f commit 098a81a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions static/scripts/rewards/cirip/query-reverse-ens.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { app } from "../app-state";
import { useRpcHandler } from "../web3/use-rpc-handler";
import { useHandler, useRpcHandler } from "../web3/use-rpc-handler";
import { ethers } from "ethers";

const mainnetRpcUrl = "https://eth.drpc.org";

export async function queryReverseEns(address: string, networkId: number) {
// Try to get the ENS name from localStorage
const cachedEnsName = localStorage.getItem(address);
Expand All @@ -20,7 +18,12 @@ export async function queryReverseEns(address: string, networkId: number) {
return cachedEnsName;
} else {
// If the ENS name is not in localStorage, fetch it from the API
const web3Provider = new ethers.providers.JsonRpcProvider(mainnetRpcUrl);
const mainnetProvider = await useHandler(1).getFirstAvailableRpcProvider();
if (mainnetProvider === null) {
console.error("ENS lookup failed: no available mainnet RPC providers");
return "";
}
const web3Provider = new ethers.providers.JsonRpcProvider(mainnetProvider.connection.url);
const ensName = await web3Provider.lookupAddress(address);

if (ensName === null) {
Expand Down

0 comments on commit 098a81a

Please sign in to comment.