detect web3 version and get accounts correctly
This commit is contained in:
parent
6824c17ed3
commit
81e0c9ce77
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
@ -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 %>
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue