From 9280cf13afc3ebce939fff7b8ead43a2011c40ec Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Wed, 9 Sep 2020 05:34:58 -0700 Subject: [PATCH] increase default gas --- src/exchange/FixedRateExchange.ts | 34 +++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/exchange/FixedRateExchange.ts b/src/exchange/FixedRateExchange.ts index 7b938fe1..2bae8be5 100644 --- a/src/exchange/FixedRateExchange.ts +++ b/src/exchange/FixedRateExchange.ts @@ -15,7 +15,7 @@ export interface FixedPricedExchange { supply: string } -const DEFAULT_GAS_LIMIT = 200000 +const DEFAULT_GAS_LIMIT = 300000 export class OceanFixedRateExchange { /** Ocean related functions */ @@ -58,21 +58,29 @@ export class OceanFixedRateExchange { * @return {Promise} exchangeId */ public async create(dataToken: string, rate: string, address: string): Promise { - const estGas = await this.contract.methods - .create(this.oceanAddress, dataToken, this.web3.utils.toWei(rate)) - .estimateGas(function (err, estGas) { - if (err) console.log('FixedPriceExchange: ' + err) - return estGas - }) - const trxReceipt = await this.contract.methods - .create(this.oceanAddress, dataToken, this.web3.utils.toWei(rate)) - .send({ - from: address, - gas: estGas + 1 - }) + let estGas + try { + estGas = await this.contract.methods + .create(this.oceanAddress, dataToken, this.web3.utils.toWei(rate)) + .estimateGas(function (err, g) { + if (err) { + return DEFAULT_GAS_LIMIT + } else { + return g + } + }) + } catch (e) { + estGas = DEFAULT_GAS_LIMIT + } let exchangeId = null try { + const trxReceipt = await this.contract.methods + .create(this.oceanAddress, dataToken, this.web3.utils.toWei(rate)) + .send({ + from: address, + gas: estGas + 1 + }) exchangeId = trxReceipt.events.ExchangeCreated.returnValues[0] } catch (e) { console.error(e)