aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract_templates/partials/callAsync.handlebars
blob: a6f4abdf268516987b21ba9bfc77e98f26421d91 (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 = self._lookupAbi('{{this.functionSignature}}').inputs;
    [{{> params inputs=inputs}}] = BaseContract._formatABIDataItemList(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(self));
    const encodedData = self._lookupEthersInterface('{{this.functionSignature}}').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}}