-
I have the following function. This function successfully transfers ERC20's, however, if the token is USDC the transaction fails. If I don't specify a gasLimit I get , Cannot Estimate Gas error, if I do specify the gasLimit, as I am doing below, I simply get Transaction Failed. I know that USDC uses the proxy pattern, the abi I'm passing in is an ERC20 abi. But I believe a normal ERC20 abi should work with USDC? Has anyone encountered this before? I'm on Polygon. On the explorer it says Fail with error 'ERC20: transfer amount exceeds balance,'. For this transaction I transferred $0.01 and I have a balance of $1.86. Tx : https://polygonscan.com/tx/0xc808feb904017f34a8ee37430bfe650e679fcdcb00edc967bfa265297afe7bda And here's a successful tx using the same function but when the user selects an ERC20 that's not USDC https://polygonscan.com/tx/0x6b938e6616f29404de1530e3feb550c73bf85ba359de1eeec41fe022d01fc397 Thanks!
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @rvmelkonian, when you are working with various ERC20 tokens, you have to see if you are using proper decimals of an ERC20 token. Usually most of ERC20 tokens have decimals as 18. Hence the If you mention 6 as decimals (or dynamically query the decimals) then your tx should success.
|
Beta Was this translation helpful? Give feedback.
Hey @rvmelkonian, when you are working with various ERC20 tokens, you have to see if you are using proper decimals of an ERC20 token. Usually most of ERC20 tokens have decimals as 18. Hence the
const amount = ethers.utils.parseUnits(amountToSend);
defaults to 18. However USDC is having decimals as 6. So unknowingly you are trying to send0.1 * 10**18
while you should be doing0.1 * 10**6
.If you mention 6 as decimals (or dynamically query the decimals) then your tx should success.