@@ -77,6 +77,9 @@ export default class AddCommand extends Command {
77
77
const manifest = await Subgraph . load ( manifestPath , { protocol } ) ;
78
78
const network = manifest . result . getIn ( [ 'dataSources' , 0 , 'network' ] ) as any ;
79
79
const result = manifest . result . asMutable ( ) ;
80
+ const isLocalHost = network === 'localhost' ; // This flag prevent Etherscan lookups in case the network selected is `localhost`
81
+
82
+ if ( isLocalHost ) this . warn ( '`localhost` network detected, prompting user for inputs' ) ;
80
83
81
84
let startBlock = startBlockFlag ;
82
85
let contractName = contractNameFlag ;
@@ -96,10 +99,44 @@ export default class AddCommand extends Command {
96
99
} else if ( network === 'poa-core' ) {
97
100
ethabi = await loadAbiFromBlockScout ( EthereumABI , network , address ) ;
98
101
} else {
99
- ethabi = await loadAbiFromEtherscan ( EthereumABI , network , address ) ;
102
+ try {
103
+ if ( isLocalHost ) throw Error ; // Triggers user prompting without waiting for Etherscan lookup to fail
104
+
105
+ ethabi = await loadAbiFromEtherscan ( EthereumABI , network , address ) ;
106
+ } catch ( error ) {
107
+ // we cannot ask user to do prompt in test environment
108
+ if ( process . env . NODE_ENV !== 'test' ) {
109
+ const { abi : abiFromFile } = await prompt . ask < { abi : EthereumABI } > ( [
110
+ {
111
+ type : 'input' ,
112
+ name : 'abi' ,
113
+ message : 'ABI file (path)' ,
114
+ initial : ethabi ,
115
+ validate : async ( value : string ) => {
116
+ try {
117
+ EthereumABI . load ( contractName , value ) ;
118
+ return true ;
119
+ } catch ( e ) {
120
+ this . error ( e . message ) ;
121
+ }
122
+ } ,
123
+ result : async ( value : string ) => {
124
+ try {
125
+ return EthereumABI . load ( contractName , value ) ;
126
+ } catch ( e ) {
127
+ return e . message ;
128
+ }
129
+ } ,
130
+ } ,
131
+ ] ) ;
132
+ ethabi = abiFromFile ;
133
+ }
134
+ }
100
135
}
101
136
102
137
try {
138
+ if ( isLocalHost ) throw Error ; // Triggers user prompting without waiting for Etherscan lookup to fail
139
+
103
140
startBlock ||= Number ( await loadStartBlockForContract ( network , address ) ) . toString ( ) ;
104
141
} catch ( error ) {
105
142
// we cannot ask user to do prompt in test environment
@@ -122,6 +159,8 @@ export default class AddCommand extends Command {
122
159
}
123
160
124
161
try {
162
+ if ( isLocalHost ) throw Error ; // Triggers user prompting without waiting for Etherscan lookup to fail
163
+
125
164
contractName = await loadContractNameForAddress ( network , address ) ;
126
165
} catch ( error ) {
127
166
// not asking user to do prompt in test environment
0 commit comments