aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract_templates/partials/callAsync.handlebars
blob: 2d9028ad5168f2500dd162a290c33fd7c719433d (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
{{#hasReturnValue}}
async callAsync(
{{> typed_params inputs=inputs}}
    callData: Partial<CallData> = {},
    defaultBlock?: BlockParam,
): Promise<{{> return_type outputs=outputs}}> {
    const self = this as {{contractName}}Contract;
    const inputAbi = (_.find(self.abi, {name: '{{this.name}}'}) as MethodAbi).inputs;
    [{{> params inputs=inputs}}] = BaseContract._transformABIData(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 as DataItem[];
    const outputParamsTypes = _.map(outputAbi, 'type');
    let resultArray = ethersContracts.Interface.decodeParams(outputParamsTypes, rawCallResult) as any;
    resultArray = BaseContract._transformABIData(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this));
    return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}};
},
{{/hasReturnValue}}