From e2ab4c4fa394b01d381f89dd9b44967969aa6fbf Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 21 Jun 2018 21:03:23 -0400 Subject: [PATCH] use EmbarkJS to initialize ens contracts and set ens contract only when embark is ready --- lib/modules/ens/embarkjs.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/modules/ens/embarkjs.js b/lib/modules/ens/embarkjs.js index 09286a1a..010cea42 100644 --- a/lib/modules/ens/embarkjs.js +++ b/lib/modules/ens/embarkjs.js @@ -154,7 +154,10 @@ __embarkENS.resolverInterface = [ ]; __embarkENS.setProvider = function (config) { - this.ens = new web3.eth.Contract(config.abi, config.address); + const self = this; + EmbarkJS.onReady(() => { + self.ens = new EmbarkJS.Contract({abi: config.abi, address: config.address}); + }); }; __embarkENS.resolve = function (name) { @@ -165,7 +168,7 @@ __embarkENS.resolve = function (name) { let node = namehash.hash(name); return self.ens.methods.resolver(node).call().then((resolverAddress) => { - let resolverContract = new web3.eth.Contract(self.resolverInterface, resolverAddress); + let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress}); return resolverContract.methods.addr(node).call(); }).then((addr) => { return addr; @@ -184,7 +187,7 @@ __embarkENS.lookup = function (address) { let node = namehash.hash(address.toLowerCase() + ".addr.reverse"); return self.ens.methods.resolver(node).call().then((resolverAddress) => { - let resolverContract = new web3.eth.Contract(self.resolverInterface, resolverAddress); + let resolverContract = new EmbarkJS.Contract({abi: self.resolverInterface, address: resolverAddress}); return resolverContract.methods.name(node).call(); }).catch(err => err); };