Skip to content

Commit 66aa0b3

Browse files
committed
feat: add network validation for subgraph contract addresse
Signed-off-by: Harsh Dev Pathak <[email protected]>
1 parent 921c014 commit 66aa0b3

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

.changeset/rare-falcons-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': minor
3+
---
4+
5+
Network validation for subgraph contract addresses

packages/cli/src/commands/deploy.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,32 @@ export default class DeployCommand extends Command {
268268
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
269269

270270
protocol = Protocol.fromDataSources(dataSourcesAndTemplates);
271+
for (const ds of dataSourcesAndTemplates.dataSources) {
272+
const address = ds.source.address;
273+
if (!address) continue;
274+
275+
try {
276+
await client.request(
277+
'eth_getTransactionCount',
278+
[address, 'latest'],
279+
(requestError, jsonRpcError, res) => {
280+
if (jsonRpcError) {
281+
const message = jsonRpcError?.message;
282+
deployDebugger('message: %O', message);
283+
} else if (requestError) {
284+
deployDebugger('HTTP requestError: %O', requestError);
285+
} else if (res === '0x0') {
286+
print.warning(
287+
`Warning: Contract ${address} does not appear to exist on network ${ds.network}. ` +
288+
`Subgraph may index no events.`,
289+
);
290+
}
291+
},
292+
);
293+
} catch (e) {
294+
print.warning(`Could not check contract ${address}: ${e}`);
295+
}
296+
}
271297
} catch (e) {
272298
this.error(e, { exit: 1 });
273299
}

0 commit comments

Comments
 (0)