import * as Web3 from "web3" ; import ethjsABI = require ( "ethjs-abi" ) ; import { TxData } from "../../../types/common" ; function filterMethodABI ( abi ) { return abi . filter ( ( abiDef ) => abiDef . type === "function" ) ; } function findMethod ( abi , name , inputTypes ) { const methodAbi = filterMethodABI ( abi ) . find ( ( abiDef ) => { const methodArgs = abiDef . inputs . map ( ( input ) => input . type ) . join ( "," ) ; return abiDef . name === name && methodArgs === inputTypes ; } ) ; if ( methodAbi ) { return methodAbi ; } throw new Error ( `Method: ${ name } with input types: ${ inputTypes } is not found` ) ; } param contract param methodName param inputTypes param inputVals param txData return export function sendTransaction ( contract , methodName , inputTypes , inputVals , txData = { } ) { const abiMethod = findMethod ( contract . abi , methodName , inputTypes ) ; const encodedData = ethjsABI . encodeMethod ( abiMethod , inputVals ) ; return contract . sendTransaction ( { data : encodedData , ... txData , } ) ; }