diff --git a/README.mdown b/README.mdown index 88d16af..6da0c61 100644 --- a/README.mdown +++ b/README.mdown @@ -81,11 +81,15 @@ At some point these should be moved into a real nice CLI. To run these scripts use `truffle exec`. For example: `truffle exec scripts/add-proposal.js` ### cli.js - Call any function on any contract: $ truffle exec scripts/cli.js +### repl.js +Similar to cli.js but only provides a REPL with an initialized `kredits` instance. + + $ truffle exec scripts/repl.js + ### add-contributor.js Adds a new core contributor, creates a proposal for the new contributor and votes for that one. diff --git a/scripts/repl.js b/scripts/repl.js new file mode 100644 index 0000000..9019e18 --- /dev/null +++ b/scripts/repl.js @@ -0,0 +1,25 @@ +const REPL = require('repl'); +const promptly = require('promptly'); + +const ethers = require('ethers'); +const Kredits = require('../lib/kredits'); + +module.exports = function(callback) { + const Registry = artifacts.require('./Registry.sol'); + Registry.deployed().then(async (registry) => { + const networkId = parseInt(web3.version.network); + const provider = new ethers.providers.Web3Provider( + web3.currentProvider, { chainId: networkId } + ); + const kredits = await Kredits.setup(provider, provider.getSigner()); + console.log(`defined variables: kredits, web3`); + let r = REPL.start(); + r.context.kredits = kredits; + r.context.web3 = web3; + + r.on('exit', () => { + console.log('Bye'); + callback(); + }); + }); +}