@@ -34,18 +34,17 @@ export async function startRepl(
34
34
35
35
const loadedContracts : { [ name : string ] : string } = { }
36
36
37
- // Add contracts into context
38
- for ( let contract of contracts ) {
39
- const abi = loadABI ( contract . abiPath )
37
+ const addContract = ( abiPath : string , address : string , replContext : any ) => {
38
+ const abi = loadABI ( abiPath )
40
39
41
40
const transactionConfirmationBlocks = 3
42
41
const options = {
43
42
transactionConfirmationBlocks,
44
43
}
45
44
const Contract : any = web3 . eth . Contract // ts hack: transactionConfirmationBlocks is not a valid option
46
45
47
- const contractInstance = new Contract ( abi , contract . address , options )
48
- let [ contractName ] = path . basename ( contract . abiPath ) . split ( '.' )
46
+ const contractInstance = new Contract ( abi , address , options )
47
+ let [ contractName ] = path . basename ( abiPath ) . split ( '.' )
49
48
50
49
let contractNameCamelCased = camelCase ( contractName )
51
50
@@ -58,7 +57,12 @@ export async function startRepl(
58
57
}
59
58
60
59
replContext [ contractNameCamelCased ] = contractInstance
61
- loadedContracts [ contractNameCamelCased ] = contract . address
60
+ loadedContracts [ contractNameCamelCased ] = address
61
+ }
62
+
63
+ // Add contracts into context
64
+ for ( let contract of contracts ) {
65
+ addContract ( contract . abiPath , contract . address , replContext )
62
66
}
63
67
64
68
const accounts = await web3 . eth . getAccounts ( )
@@ -77,4 +81,14 @@ export async function startRepl(
77
81
this . displayPrompt ( )
78
82
} ,
79
83
} )
84
+
85
+ r . defineCommand ( 'loadc' , {
86
+ help : 'Load a contract using the specified ABI and address' ,
87
+ action ( abiAndAddress : string ) {
88
+ this . clearBufferedCommand ( )
89
+ const [ abiPath , address ] = abiAndAddress . split ( '@' )
90
+ addContract ( abiPath , address , r . context )
91
+ this . displayPrompt ( )
92
+ } ,
93
+ } )
80
94
}
0 commit comments