When we're asking a user to approve()
the spending of a proprietary ERC20 Token for the first time (like say DAI
, or SUSHI
, etc.), the user has to enter the amount they're willing to approve - like say 100 tokens, or 100,000 tokens - or they can just tap on "MAX VALUE".
But how do we then pass that value along as an argument to the approve()
method we're already calling?
It feels a bit like a chicken-egg type thing.
Here's what I mean:
// Here we call `approve()` to prompt the user to enter the AMOUNT of Tokens
// they're willing to spend, except this call is also *already* requiring us to
// pass-in some value for token-amount - *before* we know what the User entered:
CustomERC20Token.approve(contractAddress, 1000).then((approvalStatus) => {
console.log(">Back from ERC20 'approve()' --> 'approvalStatus' = ", approvalStatus);
}).catch(theError => {
console.log("'approve()' - 'catch()' --> Here's the error: ");
console.log(theError);
});
As you can see, I hard-coded a value of 1000 Tokens - cause the function call is already looking for *some* value to be passed-in. But 1000 is not necessarily what the user entered...
So how do I get the value the user actually enters?