Skip to content

Commit 7e26098

Browse files
make indexer work for either hardhat or base based on PONDER_CHAIN_ID
1 parent 686d8d8 commit 7e26098

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

packages/indexer/ponder.config.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
import { createConfig } from "ponder";
22
// Use deployed ABIs to avoid drift with contracts
33
import { easGetAttestationAbi } from "./abis/EASAbi";
4-
import MarketplaceDeployment from "../hardhat/deployments/base/Marketplace.json" assert { type: "json" };
4+
import MarketplaceDeploymentBase from "../hardhat/deployments/base/Marketplace.json" assert { type: "json" };
5+
import MarketplaceDeploymentHardhat from "../hardhat/deployments/localhost/Marketplace.json" assert { type: "json" };
56
import EASConfig from "./src/easConfig.json" assert { type: "json" };
67
import { Abi } from "viem";
78

9+
const CHAIN_ID = Number(process.env.PONDER_CHAIN_ID ?? 8453);
10+
const CHAIN_NAME = CHAIN_ID === 31337 ? "hardhat" : "base";
11+
const EASConfigForChain = EASConfig[String(CHAIN_ID) as keyof typeof EASConfig];
12+
const MarketplaceDeploymentForChain = CHAIN_ID === 31337 ? MarketplaceDeploymentHardhat : MarketplaceDeploymentBase;
13+
814
export default createConfig({
915
chains: {
10-
base: {
11-
id: 8453,
12-
rpc: process.env.PONDER_RPC_URL_8453 ?? "https://base.llamarpc.com",
16+
[CHAIN_NAME]: {
17+
id: Number(process.env.PONDER_CHAIN_ID ?? 8453),
18+
rpc: process.env[`PONDER_RPC_URL_${process.env.PONDER_CHAIN_ID}`] ?? "https://base.llamarpc.com",
1319
},
1420
},
1521
contracts: {
1622
Marketplace: {
17-
chain: "base",
18-
abi: MarketplaceDeployment.abi as Abi,
19-
address: MarketplaceDeployment.address as `0x${string}`,
20-
startBlock: MarketplaceDeployment.receipt.blockNumber,
23+
chain: CHAIN_NAME,
24+
abi: MarketplaceDeploymentForChain.abi as Abi,
25+
address: MarketplaceDeploymentForChain.address as `0x${string}`,
26+
startBlock: MarketplaceDeploymentForChain.receipt.blockNumber,
2127
},
2228
// Index EAS core contract using the deployed ABI to match emitted events
2329
EAS: {
24-
chain: "base",
30+
chain: CHAIN_NAME,
2531
abi: easGetAttestationAbi,
26-
address: EASConfig["8453"].eas as `0x${string}`,
27-
startBlock: MarketplaceDeployment.receipt.blockNumber,
32+
address: EASConfigForChain.eas as `0x${string}`,
33+
startBlock: MarketplaceDeploymentForChain.receipt.blockNumber,
2834
},
2935
},
3036
});

packages/indexer/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ import easConfig from "./easConfig.json" assert { type: "json" };
66
import { easGetAttestationAbi } from "../abis/EASAbi";
77

88
// Reuse one public client for reads
9+
const rpcUrl =
10+
process.env[`PONDER_RPC_URL_${process.env.PONDER_CHAIN_ID}`] ??
11+
"https://base.llamarpc.com";
912
const publicClient = createPublicClient({
10-
transport: http(process.env.PONDER_RPC_URL_8453 ?? "https://base.llamarpc.com"),
13+
transport: http(rpcUrl),
1114
});
1215

1316
// --- IPFS helpers (resilient multi-gateway JSON fetch) ---
14-
const PREFERRED_GATEWAY = process.env.PONDER_IPFS_GATEWAY || "https://ipfs.io/ipfs/";
17+
const PREFERRED_GATEWAY =
18+
process.env.PONDER_IPFS_GATEWAY || "https://ipfs.io/ipfs/";
1519

1620
function toIpfsPath(cidOrUrl: string | null | undefined): string {
1721
if (!cidOrUrl) return "";

0 commit comments

Comments
 (0)