I am trying to send the ERC20 USDT tether token. But I faced some errors. Could anyone let me know the code about the transaction USDT? Thanks.
1 Answer
I'm happy to be able to help you as I fixed this a few days ago.
const sendERC20Transaction = async (receiver, amount) => {
var Tx = require('ethereumjs-tx')
const Web3 = require('web3')
const web3 = new Web3('https://mainnet.infura.io/v3/your-project-id')
web3.eth.accounts.wallet.add('privateKey of fromwallet');
var contractAbi =[];
var tokenAddress = ''//Tether token(USDT)
var fromAddress = '0x3df...'
var tokenInst = new web3.eth.Contract(contractAbi,tokenAddress);
tokenInst.methods.transfer(receiver, amounts).send({from: fromAddress, gas: 100000},function (error, result){ //get callback from function which is your transaction key
if(!error){
console.log(result);
handleSuccessTrue();
} else{
console.log(error);
web3.eth.getBalance(fromAddress, (err,bal) => { alert('Your account has ' + web3.utils.fromWei(bal, 'ether') + ', Insufficient funds for gas * price + value on your wallet')});
handleSuccessFalse();
}
});
//Finally, you can check if usdt tranaction success through this code.
tokenInst.methods.balanceOf(receiver).call().then(console.log)
.catch(console.error);
It would be appreciated if this code help you.
Thanks.