aboutsummaryrefslogblamecommitdiffstats
path: root/packages/contract_templates/partials/call.handlebars
blob: 7ac3e1ee3b0544c0766fc8b1dc55ba2938ed7079 (plain) (tree)
1
2
3
4
5
6
7
8
9





                                                      
                                                                          

                                                                                                                                                          
                                      







                                                                          
                                                                            

                                                                                                                        

      
public {{this.name}} = {
    async callAsync(
    {{> typed_params inputs=inputs}}
        defaultBlock?: Web3.BlockParam,
    ): Promise<{{> return_type outputs=outputs}}> {
        const self = this as {{contractName}}Contract;
        const inputAbi = _.find(this.abi, {name: '{{this.name}}'}).inputs;
        [{{> params inputs=inputs}}] = BaseContract._transformABIData(inputAbi, [{{> params inputs=inputs}}], BaseContract._bigNumberToString.bind(this));
        const callDescription = self._ethersInterface.functions.{{this.name}}(
            {{> params inputs=inputs}}
        ) as ethersContracts.CallDescription;
        const callData = await self._applyDefaultsToTxDataAsync(
            {
                data: callDescription.data,
            }
        )
        const rawCallResult = await self._web3Wrapper.callAsync(callData);
        let resultArray = callDescription.parse(rawCallResult);
        const outputAbi = _.find(this.abi, {name: '{{this.name}}'}).outputs;
        resultArray = BaseContract._transformABIData(outputAbi, resultArray, BaseContract._lowercaseAddress.bind(this));
        return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}};
    },
};