diff --git a/packages/plugins/ethereum-blockchain-client/src/api.js b/packages/plugins/ethereum-blockchain-client/src/api.js index 7ee8f14900..ecd680beff 100644 --- a/packages/plugins/ethereum-blockchain-client/src/api.js +++ b/packages/plugins/ethereum-blockchain-client/src/api.js @@ -293,8 +293,8 @@ export default class EthereumAPI { this.requestManager.send({method: 'web3_clientVersion', params: []}, cb); } - getNetworkId() { - return this.web3.eth.net.getId(); + getNetworkId(cb) { + return this.web3.eth.net.getId(cb); } getTransaction(hash, cb) { diff --git a/packages/stack/blockchain/src/api.ts b/packages/stack/blockchain/src/api.ts index 716546d1c9..eb2c45a859 100644 --- a/packages/stack/blockchain/src/api.ts +++ b/packages/stack/blockchain/src/api.ts @@ -109,9 +109,9 @@ export default class BlockchainAPI { getGasPrice(cb); }); - this.events.setCommandHandler("blockchain:networkId", async (cb) => { - const getNetworkId = await this.getRequestForBlockchain(blockchainName, "getNetworkId"); - cb(getNetworkId); + this.events.setCommandHandler("blockchain:networkId", (cb) => { + const getNetworkId = this.getRequestForBlockchain(blockchainName, "getNetworkId"); + getNetworkId(cb); }); this.events.setCommandHandler("blockchain:getTransaction", async (txId, cb) => { diff --git a/packages/stack/blockchain/src/index.js b/packages/stack/blockchain/src/index.js index 067ba458d0..8114c540ad 100644 --- a/packages/stack/blockchain/src/index.js +++ b/packages/stack/blockchain/src/index.js @@ -178,38 +178,45 @@ export default class Blockchain { return web3.currentProvider; } - addArtifactFile(_params, cb) { + async addArtifactFile(_params, cb) { if (!this.blockchainConfig.enabled) { cb(); } - this.events.request("config:contractsConfig", (_err, contractsConfig) => { - async.map(contractsConfig.dappConnection, (conn, mapCb) => { - if (conn === '$EMBARK') { - // Connect to Embark's endpoint (proxy) - return this.events.request("proxy:endpoint:get", mapCb); - } - mapCb(null, conn); - }, (err, results) => { - if (err) { - this.logger.error(__('Error getting dapp connection')); - return cb(err); - } - const config = { - provider: contractsConfig.library || 'web3', - dappConnection: results, - dappAutoEnable: contractsConfig.dappAutoEnable, - warnIfMetamask: this.blockchainConfig.isDev, - blockchainClient: this.blockchainConfig.client - }; - this.events.request("pipeline:register", { - path: [this.embarkConfig.generationDir, 'config'], - file: 'blockchain.json', - format: 'json', - content: config - }, cb); + try { + const networkId = await this.events.request2('blockchain:networkId'); + this.events.request("config:contractsConfig", (_err, contractsConfig) => { + async.map(contractsConfig.dappConnection, (conn, mapCb) => { + if (conn === '$EMBARK') { + // Connect to Embark's endpoint (proxy) + return this.events.request("proxy:endpoint:get", mapCb); + } + mapCb(null, conn); + }, (err, results) => { + if (err) { + this.logger.error(__('Error getting dapp connection')); + return cb(err); + } + const config = { + provider: contractsConfig.library || 'web3', + dappConnection: results, + dappAutoEnable: contractsConfig.dappAutoEnable, + warnIfMetamask: this.blockchainConfig.isDev, + blockchainClient: this.blockchainConfig.client, + networkId + }; + + this.events.request("pipeline:register", { + path: [this.embarkConfig.generationDir, 'config'], + file: 'blockchain.json', + format: 'json', + content: config + }, cb); + }); }); - }); + } catch (e) { + cb(e); + } } registerConsoleCommands() {