aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract_templates/partials/callAsync.handlebars
blob: 8de69203eb53b5adb2f164d213807b3ccb9b839a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{{#hasReturnValue}}
async callAsync(
{{> typed_params inputs=inputs}}
    callData: Partial<CallData> = {},
    defaultBlock?: BlockParam,
): Promise<{{> return_type outputs=outputs}}> {
    const self = this as any as {{contractName}}Contract;
    const inputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).inputs;
    [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self));
    const encodedData = self._ethersInterface.functions.{{this.name}}(
        {{> params inputs=inputs}}
    ).data;
    const callDataWithDefaults = await self._applyDefaultsToTxDataAsync(
        {
            data: encodedData,
        }
    )
    const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
    const outputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).outputs;
    const outputParamsTypes = _.map(outputAbi, 'type');
    let resultArray = ethersContracts.Interface.decodeParams(outputParamsTypes, rawCallResult) as any;
    resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this));
    resultArray = BaseContract._formatABIDataItemList(outputAbi, resultArray, BaseContract._bnToBigNumber.bind(this));
    return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}};
},
{{/hasReturnValue}}