From e119007f76bad756ee2e4a6da5f4e288ff04a7ac Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 10 Jun 2018 10:22:09 -0400 Subject: [PATCH] clean up, improve setting the web3 object --- js/embark.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/embark.js b/js/embark.js index 7aa335596..19fe6d88b 100644 --- a/js/embark.js +++ b/js/embark.js @@ -19,27 +19,28 @@ EmbarkJS.Contract = function(options) { this.address = options.address; this.code = '0x' + options.code; //this.web3 = options.web3 || web3; - this.web3 = options.web3 || window.web3; + this.web3 = options.web3; + if (!this.web3 && typeof ('web3') !== 'undefined') { + this.web3 = web3; + } else { + this.web3 = window.web3; + } if (EmbarkJS.isNewWeb3()) { - // TODO: - // add default **from** address - // add gasPrice ContractClass = new this.web3.eth.Contract(this.abi, this.address); ContractClass.setProvider(this.web3.currentProvider); ContractClass.options.data = this.code; + ContractClass.options.from = this.from; ContractClass.abi = ContractClass.options.abi; ContractClass.address = this.address; let originalMethods = Object.keys(ContractClass); - let methods = []; ContractClass._jsonInterface.forEach((abi) => { if (originalMethods.indexOf(abi.name) >= 0) { console.log(abi.name + " is a reserved word and cannot be used as a contract method, property or event"); return; } - methods.push(abi.name); if (!abi.inputs) { return;