我正在尝试发送ERC20 USDT系结令牌。但我遇到了一些错误。有人能告诉我USDT交易的代码吗?谢谢。
发布于 2021-09-26 12:58:04
我很高兴能帮助你,因为我几天前就解决了这个问题。
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);如果此代码能帮助您,我们将不胜感激。
谢谢。
https://ethereum.stackexchange.com/questions/110589
复制相似问题