2
votes

I am studying by Mastering Ethereum book, then I am doing an exercise that creates a contract, receive ether there and withdraw it. But I am getting an error, I don't know why, considering I am following all the steps.

The code:


// Version of Solidity compiler this program was written for
pragma solidity ^0.6.0;

// Our first contract is a faucet!
contract Faucet {
    // Accept any incoming amount
    receive () external payable {}
    
    // Give out ether to anyone who asks
    function withdraw(uint withdraw_amount) public {

        // Limit withdrawal amount
        require(withdraw_amount <= 100000000000000000);

        // Send the amount to the address that requested it
        msg.sender.transfer(withdraw_amount);
    }
}

The error after put “100000000000000000” on the withdraw function field:

transact to Faucet.withdraw errored: Error encoding arguments: Error: invalid number value (arg="", coderType="uint256", value="1.0000000000000000", version=4.0.47)

Here my screen:

desktop image

I am just following the exact code description from "Mastering Ethereum" book, here the reason I am using quote marks:

book image

Why it?

1
It appears you are sending a String into the withdraw_amount parameter instead of a uint. Look at your image. value=""100..."" (double double quotes) For your test, click on the down arrow at the right of the function and input an integer value - Emmanuel Collin
I used quote marks because with large numbers it is necessary, Javascript don't handle with unit in larger numbers, I added an image explain that from the book. But I already identified the error, always when I deploy the contract it generates a new address, then I need before send some ether to that address in order to make the test, I just sent on the first time and all the others tests I was doing in a new address without ether. - Márcio

1 Answers

0
votes

Try to entering values without quotes.bcoz if you pass the value within quotes copiler or EVM recognises it is an string.The Numbers are entered without quotes.