8000 feat: add .loadc command · protofire/eth-cli@44b6906 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 44b6906

Browse files
fvictorioFranco Victorio
authored andcommitted
feat: add .loadc command
1 parent 9f2d300 commit 44b6906

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/helpers/startRepl.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ export async function startRepl(
3434

3535
const loadedContracts: { [name: string]: string } = {}
3636

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)
4039

4140
const transactionConfirmationBlocks = 3
4241
const options = {
4342
transactionConfirmationBlocks,
4443
}
4544
const Contract: any = web3.eth.Contract // ts hack: transactionConfirmationBlocks is not a valid option
4645

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('.')
4948

5049
let contractNameCamelCased = camelCase(contractName)
5150

@@ -58,7 +57,12 @@ export async function startRepl(
5857
}
5958

6059
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)
6266
}
6367

6468
const accounts = await web3.eth.getAccounts()
@@ -77,4 +81,14 @@ export async function startRepl(
7781
this.displayPrompt()
7882
},
7983
})
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+
})
8094
}

0 commit comments

Comments
 (0)
0