diff --git a/lib/contracts/code_templates/utils.js.ejs b/lib/contracts/code_templates/utils.js.ejs index b88c7b37b..25bb65fd4 100644 --- a/lib/contracts/code_templates/utils.js.ejs +++ b/lib/contracts/code_templates/utils.js.ejs @@ -34,3 +34,20 @@ function __reduce(arr, memo, iteratee, cb) { }); })(0, memo); }; + +function __isNewWeb3_1() { + return (typeof(web3.version) === "string"); +}; + +function __getAccounts(cb) { + if (__isNewWeb3_1()) { + web3.eth.getAccounts().then(function(accounts) { + cb(null, accounts); + }).catch(function(err) { + cb(err); + }); + return; + } + web3.eth.getAccounts(cb); +}; + diff --git a/lib/contracts/code_templates/web3-connector.js.ejs b/lib/contracts/code_templates/web3-connector.js.ejs index 4e61fb0fb..be3e33519 100644 --- a/lib/contracts/code_templates/web3-connector.js.ejs +++ b/lib/contracts/code_templates/web3-connector.js.ejs @@ -16,7 +16,7 @@ __reduce(<%- connectionList %>,function(prev, value, next) { return next(null, ''); } - web3.eth.getAccounts(function(err, account) { + __getAccounts(function(err, account) { if (err) { next(null, true) } else { @@ -24,7 +24,7 @@ __reduce(<%- connectionList %>,function(prev, value, next) { } }); }, function(err, _result) { - web3.eth.getAccounts(function(err, accounts) { + __getAccounts(function(err, accounts) { web3.eth.defaultAccount = accounts[0]; <%- done %> });