This makes it easier to handle truffle arguments which we for example need to specify the network. So we ask the user for input instead on using the argv array which might change.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
const REPL = require('repl');
|
|
const promptly = require('promptly');
|
|
|
|
module.exports = function(callback) {
|
|
const Registry = artifacts.require('./Registry.sol');
|
|
Registry.deployed().then(async (registry) => {
|
|
let contractName = await promptly.prompt('Contract Name: ');
|
|
let method = await promptly.prompt('Function: ');
|
|
let argumentInput = await promptly.prompt('Arguments (comma separated): ', { default: '' });
|
|
let args = [];
|
|
if (argumentInput !== '') {
|
|
args = argumentInput.split(',').map(a => a.trim());
|
|
}
|
|
|
|
let contractAddress = await registry.getProxyFor(contractName);
|
|
console.log(`Using ${contractName} at ${contractAddress}`);
|
|
let contract = await artifacts.require(`./${contractName}`).at(contractAddress);
|
|
|
|
if (!contract[method]) {
|
|
callback(new Error(`Method ${method} is not defined on ${contractName}`));
|
|
return;
|
|
}
|
|
console.log(`Calling ${method} with ${JSON.stringify(args)}`);
|
|
|
|
contract[method](...args).then((result) => {
|
|
console.log("\nResult:");
|
|
console.log(result);
|
|
|
|
console.log("\nStartig a REPL. (type .exit to exit)");
|
|
console.log(`defined variables: result, ${contractName}, web3`);
|
|
let r = REPL.start();
|
|
r.context.result = result;
|
|
r.context[contractName] = contract;
|
|
r.context.web3 = web3;
|
|
|
|
r.on('exit', () => {
|
|
console.log('Bye');
|
|
callback();
|
|
})
|
|
}).catch((error) => {
|
|
console.log("Call failed. Probably the contract raised an error?\n");
|
|
console.log("...");
|
|
callback(error);
|
|
});
|
|
|
|
})
|
|
|
|
}
|