Error sending a transaction on entry points with no paramters

I have an entry point on my smart contract that takes no parameter and is just called with an amount to fund the contract. when I call wallet.sendTransaction without passing parameters and schema, the Transaction is initiated and goes through but attempting to convert the returned Hash fails

  const payload = {
    amount: CcdAmount.fromMicroCcd(BigInt(microAmount)),
    address: ContractAddress.create(receiverAddress, 0),
    receiveName: ReceiveName.create(
      ContractName.fromString(CCD_CONTRACT),
      EntrypointName.fromString(entryPoint)
    ),
    maxContractExecutionEnergy: Energy.create(res.usedEnergy.value + 100n),
  }

  const hash = await wallet.sendTransaction(
    AccountAddress.toBase58(sender),
    AccountTransactionType.Update,
    payload
    }
  )

  console.log(hash) // hash correctly returned 

  const transactionHash = TransactionHash.toHexString(hash) // fails here

when trying to do this TransactionHash.toHexString(hash) it fails with an error

Uncaught (in promise) TypeError: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
    at from (chunk-RABGB6UD.js?v=5d3d8681:265:15)
    at Buffer.from (chunk-RABGB6UD.js?v=5d3d8681:295:14)
    at Object.toHexString4

But when calling another entry point that takes parameters it works without any issue

  const hash = await wallet.sendTransaction(
    AccountAddress.toBase58(sender),
    AccountTransactionType.Update,
    payload,
    data,
    {
      type: 'parameter',
      value: rawSchema[entryPoint],
    }
  )

  console.log(hash)

  const transactionHash = TransactionHash.toHexString(hash) // works without any issue

One suggestion: When sending a transaction, it can fail/revert (as in your first example). As a result, you should check and handle the error instead of continuing in your code:

  let hash;
try{
   hash = await wallet.sendTransaction(
    AccountAddress.toBase58(sender),
    AccountTransactionType.Update,
    payload
    }
  )
}catch(Exception e) {
  //  Block of code to handle errors
}

1 Like

yeah thanks for the suggestion @Doris Iā€™m calling this with react Query so it automatically catches and returns any error. Any pointers/solution as to wny TransactionHash.toHexString(hash) is failing for hash generated for entry point without parameters?

ooh my Bad, mistake from my end. I removed .then(TransactionHash.fromHexString) ended up with a string instead of a buffer