I Have a form with an input and a button with a type of submit, I want to submit a number from the input and convert it toWei unit using web3 that will be passed into a function that will allow the user to stake some DaiToken, I've tried this method web3.utils.toWei(amount, "ether") that I found on web3 documentation but when I clicked submit it gave me this error "Unhandled Rejection (TypeError): address.toLowerCase is not a function" and metaMask doesn't pop up to confirm the transaction of staking;

I've spent a lot of time researching but I got no answer. Thank you

state value of the input

const [inputValue, setInputValue] = useState("");

submit function

const stackHandler = (e) => {

        const amount = web3.utils.toWei(inputValue);


<form className="mb-3" onSubmit={stackHandler}>

                <div className="balance-section">
                <div className="input-group mb-4">
                    className="form-control form-control-lg"
                    onChange={(e)=> setInputValue(e.target.value)}/>

                  <div className="input-group-append">
                    <div className="input-group-text">
                      <img src={dai} height='32' alt=""/>
                      &nbsp;&nbsp;&nbsp; mDAI

                <button type="submit" className="btn btn-primary btn-block btn-lg">STAKE!</button>

stakeTokens Function

const stakeTokens = async (amount) => {
    await dTokens.methods.approve(fTokens._address, amount)
    .send({ from : investorAccount})
    .on("transitionsHash", (hash)=> {
      fTokens.methods.stakeTokens(amount).send({from : investorAccount})
    }).on("transitionsHash", (hash)=> {
      console.log("stacking has been validated")

1 Answer 1


The error is probably the address you pass to the approve method. If fTokens is a web3js contract you need to use fTokens.options.address to get the address (see https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#options-address)

It is not a direct answer to the usage of toWei but that one looks correct and the error indicates that an invalid address is passed somewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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