0

So I am putting together a test for my contract and this is the it() statement:

it('allows one account to enter', async () => {
    await lottery.methods.enter().send({
      from: accounts[0],
      value: web3.utils.toWei('0.02', 'wei')
    });

I am unclear as to why I am getting this error:

Error: [ethjs-unit] while converting number 0.02 to wei, too many decimal places

Does web3.utils no longer take care of the conversion or did I calculate the decimal places wrong?

Here is the snippet of the actual contract that assigns the amount of money:

function enter() public payable {
        require(msg.value > .01 ether);
        players.push(msg.sender);
    }
1

wei is the smallest unit of Ether and cannot be subdivided. This line:

web3.utils.toWei('0.02', 'wei')

says to convert .02 wei to wei, which obviously cannot be done because .02 wei cannot exist to begin with, and it doesn't make sense to convert to and from the same units...

You probably meant to put:

web3.utils.toWei('0.02', 'ether')

Which converts .02 ether to wei which is: 20000000000000000 wei or 20 * 10^15 wei

  • thanks Shawn, I guess I need to take a break from testing, totally missed that. That's why peer review is so important. – Daniel Oct 1 '18 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.