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) => {
e.preventDefault();
const amount = web3.utils.toWei(inputValue);
stakeTokens(amount);
}
Form
<form className="mb-3" onSubmit={stackHandler}>
<div className="balance-section">
<div className="input-group mb-4">
<input
type="text"
className="form-control form-control-lg"
placeholder="0.0"
required
value={inputValue}
onChange={(e)=> setInputValue(e.target.value)}/>
<div className="input-group-append">
<div className="input-group-text">
<img src={dai} height='32' alt=""/>
mDAI
</div>
</div>
</div>
<button type="submit" className="btn btn-primary btn-block btn-lg">STAKE!</button>
</form>
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")
});
};