Moralis.executeFunction response has no wait function

Hi,

Based on your documentation here I should be able to execute transaction wait function like so:

const transaction = await Moralis.executeFunction(options);
const result = await transaction.wait();

Unfortunately the type you are using in Moralis namespace for executeFunction response looks like this:

type ExecuteFunctionCallResult = EthersResult;
type ExecuteFunctionSendResult = EthersTransaction;
type ExecuteFunctionResult = ExecuteFunctionCallResult | ExecuteFunctionSendResult;
...
type EthersTransaction = import('ethers').Transaction; // <- this is the issue
...
let executeFunction: (options: ExecuteFunctionOptions) => Promise<ExecuteFunctionResult>;

The Transaction type in ethers.js doesn’t include wait() fn, but when checking the actual executeFunction response I can see that it includes it.

So what you actually return (I think) is TransactionResponse from ethers.js.

I think you are using a wrong type in your typings, and because of that it’s impossible to access wait() function in Typescript projects.

My temporary solution to this is to force-cast like this:

import { TransactionResponse } from '@ethersproject/abstract-provider';
...
const transaction = await Moralis.executeFunction(options) as unknown as TransactionResponse;
const result = await transaction.wait();

Only this way I can access wait() in a Typescript project.

Thanks

Moralis SDK version: 1.8.0

3 Likes

+1 here and thank you for the workaround.

Moralis should address this issue though, its pretty core

there is a new version of the SDK that the team is working on: The future of the Javascript SDK

1 Like