Ethernaut: Naught Coin (troubles with web3 library)


I solve this challenge on RemixIDE (by using the function increaseAllowance() and then transferFrom(), I then checked that the operation has been successfull by using the function balanceOf()).

However when I try it on Ethernaut it doesn’t work. More precisely, I don’t understand why when I input await contract.INITIAL_SUPPLY() I get an array with several values (that sum up to 99’573’031) see below:

The worst is that when I try use the function transferFrom() my balance seems to increase instead of decreasing…

Does someone has an idea why ?


Hey @Caladay! I’m not familiar with that particular Ethernaut level, but it’d seem like what you are seeing in the console are BigNumber instances. Can you try converting them to a string?

For instance, in your first example, try (await contract.INITIAL_SUPPLY()).toString().

1 Like

Dear @Spalladino,

Thank you for your response. I tried your recommendation and it works (as you can see below):

The issue now is that in order to solve this level I need to get my token balance to 0. However I’m not able to increase my allowance to more than 10^15* (In the above picture I tried 10^24 and 10^16 without success). As I start with 10^24 it’s long way to go.

Do you have any suggestion on what I could do ?

*to be more precise, I can increase it to value between 10^15 and 10^16

1 Like

The problem you are facing now is not with the contract, but with the web3 library itself. It will refuse to encode large numbers as uint256, due to the loss of precision in javascript.

If you want to pass a big number, you can either use a BigNumber instance, or, much easier, just a string. In your example, just change contract.increase(address, 100000000000) to contract.increase(address, '100000000000').

1 Like

Dear Spalladino,

Thank you very much for your explanation. It worked perfectly.