Dry run failed: could not automatically determine a budget

,

When I try to run a smart contract function I get the error:

Error: Dry run failed, could not automatically determine a budget: VMVerificationOrDeserializationError in command 0

This is my code:

  async sendMail(sendMailDto) {
    const { body, recipient } = sendMailDto

    const tx = new Transaction()

    tx.moveCall({
      target: `${VITE_SUI_MAIL_PACKAGE_ID}::sui_mail::send_mail`,
      arguments: [tx.pure.string(recipient), tx.pure.string(body)],
    })
    
    const keypair = await this.authService.getEd25519Keypair()

    return await suiClient
      .signAndExecuteTransaction({
        signer: keypair,
        transaction: tx,
        options: {
          showEffects: true,
        },
      })
      .then((txRes) => {
        const status = txRes.effects?.status?.status
        if (status !== "success") {
          throw new Error(`Could not send mail ${txRes.effects?.status?.error}`)
        }
        return txRes
      })
      .catch((err) => {
        throw new Error(`Error thrown: Could not send mail!: ${err}`)
      })
  }

Please how do I solve this?

There are a couple of things you can do here:

You can try setting an appropriate gas budget and see if the transaction goes through as it is or gives you a different error code.

If transaction execution still fails, then most likely you are passing an argument in the wrong type format. Make sure to check whether the send_mail function expects recipient to be passed as String or address and whether body is correctly represented as a string indeed