From cf3cfe51ca6a78b89193617a22edc5264e233f79 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 9 Aug 2016 20:50:12 -0400 Subject: [PATCH] generate an abi file compatible with mist and metamask --- lib/deploy.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 = "";