I want to dynamically call contract functions. The only problem with this is, that all of the functions have a different amount of variables. As of now, the function looks like this:

async call(message: string, args, accountId: string){

    const provider =  new WsProvider(this.providerAddress)
    const api = await ApiPromise.create({ provider })
    const contract = new ContractPromise(api, this.abi, this.contractAddress)

    const gasLimit = this.gasLimit
    const storageDepositLimit = this.storageDepositLimit

    if(args.length == 1) {
         const { gasRequired, storageDeposit, result, output } = await   contract.query[message](
                    return{gasRequired, storageDeposit, result, output}

'args' is an array of the arguments passed to the contract query. Is it possible to loop through all args in the contract call,instead of calling them all individually using their index?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy