diff options
Diffstat (limited to 'packages/0x.js/src/contract.ts')
-rw-r--r-- | packages/0x.js/src/contract.ts | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/packages/0x.js/src/contract.ts b/packages/0x.js/src/contract.ts index 347f47aa0..6dc0dab66 100644 --- a/packages/0x.js/src/contract.ts +++ b/packages/0x.js/src/contract.ts @@ -5,6 +5,8 @@ import * as Web3 from 'web3'; import {AbiType} from './types'; +const GAS_MARGIN = 30000; + export class Contract implements Web3.ContractInstance { public address: string; public abi: Web3.ContractAbi; @@ -63,21 +65,23 @@ export class Contract implements Web3.ContractInstance { // 1 - method level // 2 - Library defaults // 3 - estimate + const removeUndefinedProperties = _.pickBy; txData = { - ...this.defaults, - ...txData, + ...removeUndefinedProperties(this.defaults), + ...removeUndefinedProperties(txData), }; if (_.isUndefined(txData.gas)) { - const estimatedGas = await estimateGasAsync.apply(this.contract, [...args, txData]); - txData.gas = estimatedGas; - } - const callback = (err: Error, data: any) => { - if (_.isNull(err)) { - resolve(data); - } else { + try { + const estimatedGas = await estimateGasAsync.apply(this.contract, [...args, txData]); + const gas = estimatedGas + GAS_MARGIN; + txData.gas = gas; + console.log('withGas', txData); + } catch (err) { reject(err); + return; } - }; + } + const callback = (err: Error, data: any) => _.isNull(err) ? resolve(data) : reject(err); args.push(txData); args.push(callback); web3CbStyleFunction.apply(this.contract, args); |