我试图使用ERC20地址发送USDT。但做不到。请指导我如何做..Here是步骤1:使用Web3 3\ contract;$contractAddress = 'ERC-20合同部署地址‘$contract =新合同(’http://localhost:8545‘,$abi);$contractInstance =$contract>at($contractAddress);
第2步:
$amount = 100, $receiver = 'Receiver addresss'第3步:
$contractInstance->call(transfer, [$amount, $receiver], $callback);发布于 2021-09-24 16:02:46
我很高兴能帮助你,因为我几天前就解决了这个问题。
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 = '0xdAC17F958D2ee523a2206206994597C13D831ec7'//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/110485
复制相似问题