Skip to content

Solidity: Premint amounts below 1 with a leading fractional zero generate code that does not compile #893

Open

Description

@RaphaelFakhri
  1. In the Solidity ERC20 tab, set Premint to 0.05.
  2. Compile the generated contract.

Or with the package:

const { erc20 } = require('@openzeppelin/wizard');
console.log(erc20.print({ name: 'MyToken', symbol: 'MTK', premint: '0.05' }));

Actual behavior

The constructor contains:

_mint(recipient, 05 * 10 ** (decimals() - 2));

solc fails with:

ParserError: Octal numbers not allowed.

The same happens for other amounts such as 0.001 or 0.001e1, and for Stablecoin, RWA, and Confidential ERC7984, which share calculatePremint.

Expected behavior

The generated line is _mint(recipient, 5 * 10 ** (decimals() - 2));, which compiles.

Cause

calculatePremint in packages/core/solidity/src/erc20.ts strips leading zeros from the integer part and trailing zeros from the fractional part, then concatenates them. Leading zeros of the fractional part remain at the start of units when the integer part is empty.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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