Dapp uses a smart contract that receives ERC20 tokens. At the front end, I want to allow users to approve a smart contract to use their funds. Do I have to have an ABI and an address for each token and create contracts instances or can I somehow call via the IERC20 standard e.g. IERC20(tokenAddress).approve(..)?


ABI and an interface are pretty much the same thing, in different format.

You didn't specify which web3 library you use, but in any case the basic ABI is the same for all ERC20 contracts. It doesn't matter if the ABI doesn't have some of the extra functionality, it's enough if it contains the functions you want to use. So you can either get the ABI from any ERC20 contract or even write the few (one?) function you want manually into an ABI.

In any case, I guess you need to use an ABI, so you need to get it in some fashion. In theory you could just use an interface, but I'm not sure if some library allows you to use a Solidity interface instead of an ABI.

  • Sorry for the confusion, I use web3.js. Specifically, if I want to receive USDC, BNB, USDT, BUSD, TETHER, do I create an instance of the contract for each token? ABI can be common, while the address is different? Because if i want to recieve 30 tokens for example, I need 30 instances. So i was wondering is there some better way. Thanks! Aug 8 at 19:06
  • You need an instance for each contract. But it's not a big thing and you can for example loop it, unless you need special treatment for some contracts. Aug 8 at 19:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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