Skip to content

Improve DevEx when env().transfer fails due to DecimalPrecisionLoss #2530

@AlexD10S

Description

@AlexD10S

While working with a simple ink! contract that uses env().transfer, I ran into an unexpected error when using small transfer values like 1 or 10:

Contract Reverted! "DecimalPrecisionLoss"   "Failed to convert an EVM balance to a native balance."

Minimal Example

#[ink(message)]
pub fn transfer(&mut self, to: H160, value: U256) {
    self.env().transfer(to, value);
}

Calling this method with value = 1 or 10 triggers the revert, while using a larger amount (e.g., 1_000_000) works fine.

The issue seems to stem from a mismatch between the EVM 18 decimal format (U256) and the Substrate-based chain’s native balance (Tested with ink-node). Smaller values are likely too low to be accurately converted, triggering a DecimalPrecisionLoss error.

DevEx concern

This error is not obvious to developers, especially when testing or writing basic contract logic. How can we improve the DevEx of this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions