[Ethereum] How to approve user to spend all the ERC20 tokens

erc-20erc-20-approvetokenstransfertransferfrom

In ERC20 we approve a user to spend our token and then they can spend as much allowed using transferFrom, but if the allowance limit exceed then I have to approve again, is there any way to allow them to spend all tokens? I mean have to approve a account only once

Best Answer

What is usually done (you can see such cases on decentralized exchanges) is to approve a very large number of tokens (greater than the total supply). A library such as bignumber.js can help you to work with this kind of numbers in javascript.

Note that this approach may involve security concerns. If the smart contract has a weakness and is "hacked", the attacker could potentially steal all of the users' tokens. One can reduce this risk in their dApp by implementing a "disapprove" feature which is an approval of 0. Indeed, each call of the approve method overrides the previous value.