Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#toWei breaks for decimal inputs of "wei" and "noether" #1

Open
1 of 2 tasks
RyanRHall opened this issue Jun 11, 2019 · 3 comments · May be fixed by #3
Open
1 of 2 tasks

#toWei breaks for decimal inputs of "wei" and "noether" #1

RyanRHall opened this issue Jun 11, 2019 · 3 comments · May be fixed by #3

Comments

@RyanRHall
Copy link

RyanRHall commented Jun 11, 2019

Issue Type

Description

#toWei breaks for decimal inputs of "wei" and "noether"

Steps to reproduce

// these *should* throw errors
unit.toWei(0.1, 'noether') // 1
unit.toWei(0.1, 'wei') // 1

Note that larger denominations work fine

// these work as expected
unit.toWei(0.1, 'kwei') // 100
unit.toWei(0.001, 'kwei') // 1
unit.toWei(0.0001, 'kwei') // throws error
@junderw
Copy link

junderw commented Dec 3, 2020

const baseLength = unitMap[unit].length - 1 || 1;

wei and noether are treated the same as if the unit was '10'

imo noether should always return BN(0) and wei should just return the formatted input and throw if the input is not an integer.

@junderw junderw linked a pull request Dec 4, 2020 that will close this issue
@junderw
Copy link

junderw commented Dec 4, 2020

Fixed in #3

@SilentCicero
Copy link
Member

@junderw will review the PR. Thank you. In future, if you want a better maintained lib for this, I would use ethers JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants