datahaven-xyz/datahaven · error

InvalidAmount

InvalidAmount

Error message

InvalidAmount

What it means

transfer_to_ethereum requires a strictly positive transfer amount (amount > Zero::zero() via Zero from sp_arithmetic traits). Zero or negative-overflowing amounts are rejected with InvalidAmount because transferring nothing would be a no-op/fee-only drain and breaks invariants downstream.

Solutions

  1. Ensure amount > 0 before submitting the extrinsic.
  2. Validate the user input in the UI/script and block submission when the parsed amount (after decimal adjustment) is 0.
  3. If the amount became 0 due to rounding, fix the decimals conversion.

Example fix

// before
await api.tx.datahavenNativeTransfer.transferToEthereum(recipient, 0n, fee);
// after
if (amount <= 0n) throw new Error('amount must be greater than zero');
await api.tx.datahavenNativeTransfer.transferToEthereum(recipient, amount, fee);
Defensive patterns

Strategy: validation

Validate before calling

function validateTransfer(amount, fee, recipient) {
  if (amount <= 0n) throw new Error('amount must be greater than zero');
  if (fee <= 0n) throw new Error('fee must be greater than zero');
  if (recipient === '0x' + '00'.repeat(20)) throw new Error('recipient is zero address');
}

Type guard

const isValidAmount = (amount) => typeof amount === 'bigint' && amount > 0n;

Try / catch

try {
  await transferToEthereum(recipient, amount, fee);
} catch (e) {
  if (String(e).includes('InvalidAmount')) showFormError('Amount must be greater than 0');
  else throw e;
}

Prevention

When it happens

Trigger: Calling transfer_to_ethereum with amount == 0 (or any value failing amount > 0), even if the fee is positive and the address is valid.

Common situations: UI defaults leaving amount unset (0) and submitting anyway; automated scripts with empty balance inputs; decimals/unit confusion producing a rounded-down amount of 0.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of datahaven-xyz/datahaven@edcb13dbbc (2026-09-13). Data as JSON: /api/errors/4489d79423b2cc3f. Report an issue: GitHub.

Appendix: source

Thrown at operator/pallets/datahaven-native-transfer/src/lib.rs:185

        /// - `recipient`: The Ethereum address to receive the tokens
        /// - `amount`: The amount of tokens to transfer
        /// - `fee`: The fee to incentivize relayers (in native tokens)
        #[pallet::call_index(0)]
        #[pallet::weight(T::WeightInfo::transfer_to_ethereum())]
        pub fn transfer_to_ethereum(
            origin: OriginFor<T>,
            recipient: H160,
            amount: BalanceOf<T>,
            fee: BalanceOf<T>,
        ) -> DispatchResult {
            let who = ensure_signed(origin)?;

            ensure!(!Paused::<T>::get(), Error::<T>::TransfersDisabled);

            // Get the token ID - fails if not registered
            let token_id = T::NativeTokenId::get().ok_or(Error::<T>::TokenNotRegistered)?;

            ensure!(amount > Zero::zero(), Error::<T>::InvalidAmount);
            ensure!(fee > Zero::zero(), Error::<T>::ZeroFee);
            ensure!(
                recipient != H160::zero(),
                Error::<T>::InvalidEthereumAddress
            );

            // Transfer fee to recipient
            T::Currency::transfer(&who, &T::FeeRecipient::get(), fee, Preservation::Preserve)?;

            // Lock tokens in the sovereign account
            Self::lock_tokens(&who, amount)?;

            // Build and send the message
            let message = Self::build_mint_message(token_id, recipient, amount, fee)?;
            T::OutboundQueue::validate(&message)
                .and_then(|ticket| T::OutboundQueue::deliver(ticket))
                .map_err(|_| Error::<T>::SendMessageFailed)?;

View on GitHub (pinned to edcb13dbbc)