diff --git a/src/blockchain/index.ts b/src/blockchain/index.ts index 932565cd..89cdddb0 100644 --- a/src/blockchain/index.ts +++ b/src/blockchain/index.ts @@ -11,11 +11,16 @@ import { ReorgEmitterService, NewBlockEmitterService, ConfirmatorService } from const logger = loggingFactory('blockchain') -export function ethFactory (): Eth { +export async function ethFactory (): Promise { const provider = Eth.givenProvider || config.get('blockchain.provider') logger.info(`Connecting to provider ${provider}`) - - return new Eth(provider) + const eth = new Eth(provider) + try { + await eth.getProtocolVersion() + } catch (e) { + throw new Error(`Can't connect to the node on address ${provider}`) + } + return eth } export async function web3eventsFactory (eth: Eth, sequelize: Sequelize): Promise { @@ -61,7 +66,7 @@ function subscribeAndEmitNewBlocks (app: Application, web3Events: Web3Events): v export default async function (app: Application): Promise { await waitForReadyApp(app) - const eth = ethFactory() + const eth = await ethFactory() app.set('eth', eth) const sequelize = app.get('sequelize') as Sequelize diff --git a/src/cli/precache.ts b/src/cli/precache.ts index 7a61e610..af0960b1 100644 --- a/src/cli/precache.ts +++ b/src/cli/precache.ts @@ -53,7 +53,7 @@ ${formattedServices}` // Init Store await initStore(sequelize) - const eth = ethFactory() + const eth = await ethFactory() const web3events = await web3eventsFactory(eth, sequelize) const tasksDefinition = servicesToPreCache.map( diff --git a/test/integration/utils.ts b/test/integration/utils.ts index 4c8f0547..94c05fd4 100644 --- a/test/integration/utils.ts +++ b/test/integration/utils.ts @@ -183,7 +183,7 @@ export class TestingApp { } private async initBlockchainProvider (): Promise { - this.eth = ethFactory() + this.eth = await ethFactory() const [owner, provider, consumer, ...accounts] = await this.eth.getAccounts() this.contractOwner = owner this.providerAddress = provider