Skip to content

Validate: Add client-side validation for invalid token amounts #165

@Aamir377300

Description

@Aamir377300

Description of problem

While reviewing the FungibleTokenClient implementation, I noticed that token amount validation is currently handled mostly by the Hiero network itself rather than being validated earlier on the client side.

For example, methods like:

long mintToken(@NonNull TokenId tokenId, long amount)

appear to accept invalid values such as 0 or negative amounts. The request is still built and submitted, and only then rejected by the network.

This means applications may end up:

  • making unnecessary network calls
  • receiving lower-level protocol errors for simple validation issues
  • handling failures later than necessary

My solution

I propose introducing basic client-side validation for fungible token operations so these kinds of invalid requests fail fast with a clearer error message.

We can add checks inside FungibleTokenClientImpl and throw a HieroValidationException before the transaction is even built or submitted. This will handle validation cases like:

  • mint amounts must be greater than zero
  • burn amounts must be greater than zero
  • transfer amounts must not be negative
    Example Implementation:
public long mintToken(@NonNull TokenId tokenId, long amount) throws HieroBaseException {
    if (amount <= 0) {
        throw new HieroValidationException("Token amount must be strictly positive. Provided: " + amount);
    }
    
    // ... existing logic to build and send transaction ...
}

I think this would improve the developer experience quite a bit by making validation failures more predictable and easier to debug, while also avoiding unnecessary transaction submissions.

I’d be happy to work on this small code addition if the maintainers think it would be a useful improvement.

@Ndacyayisenga-droid @aceppaluni please assign this issue to me.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions