diff --git a/lib/deploy.js b/lib/deploy.js index 7b2e6c0b..49a91427 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -193,16 +193,20 @@ Deploy.prototype.execute_cmds = function(cmds) { console.log("executing: " + cmd); eval(cmd); } -} +}; Deploy.prototype.generate_provider_file = function() { var result = ""; - result += "var web3 = new Web3();"; - result += "web3.setProvider(new web3.providers.HttpProvider('http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort + "'));"; + + result += "if (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {"; + result += 'web3 = new Web3(web3.currentProvider);'; + result += "} else if (typeof Web3 !== 'undefined') {"; + result += 'web3 = new Web3(new Web3.providers.HttpProvider("http://' + this.blockchainConfig.rpcHost + ':' + this.blockchainConfig.rpcPort + '"));'; + result += '}'; result += "web3.eth.defaultAccount = web3.eth.accounts[0];"; return result; -} +}; Deploy.prototype.generate_abi_file = function() { var result = "";