import * as _ from "lodash" ; import * as Web3 from "web3" ; import { TxData , TxDataPayable } from "./common" ; export class BaseContract { public address : string ; public abi : Web3 . AbiDefinition [ ] ; public web3ContractInstance : Web3 . ContractInstance ; protected defaults : Partial < TxData > ; constructor ( web3ContractInstance , defaults ) { this . web3ContractInstance = web3ContractInstance ; this . address = web3ContractInstance . address ; this . abi = web3ContractInstance . abi ; this . defaults = defaults ; } protected async applyDefaultsToTxDataAsync < T extends TxData | TxDataPayable > ( txData , estimateGasAsync ? ) { const removeUndefinedProperties = _ . pickBy ; const txDataWithDefaults = { ... removeUndefinedProperties ( this . defaults ) , ... removeUndefinedProperties ( txData as any ) , } ; if ( _ . isUndefined ( txDataWithDefaults . gas ) && ! _ . isUndefined ( estimateGasAsync ) ) { const estimatedGas = await estimateGasAsync ( txData ) ; txDataWithDefaults . gas = estimatedGas ; } return txDataWithDefaults ; } }