I am new to all this and would be thankful if anyone could direct me to a place I can read a bit more in depth about this and give me an explanation why this doesn't work and why the solutions work. Thanks a lot.
const USDT2 = new ethers.Contract(contract address, abi,wallet);//The wallet itself works fine
async function geterc20(){
const options = {
gasLimit: 150000,
gasPrice: ethers.utils.parseUnits('10.0', 'gwei')
};
await USDT2.transfer(ACCOUNT2_PUBLIC_KEY,ethers.BigNumber.from(100),options).then(res=>{
console.log(res);
}).catch(error=>{
console.log(ethers.utils.toUtf8String(Object.values(error.body)));
});
}
Best Answer
When you transfer
ethers.BigNumber.from(100)
value on USDT contract, which use a decimal value of 6, you are actually transferring 0.0001 USDT.You should use
ethers.utils.parseUnits('100', 6)
to generate a proper value that represents 100 USDT.Now even though technically you sent 0.0001 USDT, but depending on the user interface you are using to view the balance, it might be rounding to 2 fractional digits.
If you want to verify that you can use
USDT2.balanceOf(ACCOUNT2_PUBLIC_KEY)
to view the exact balance.