0

i am trying to send USDT using the ERC20 address . But not able to do. Can anyone please guide me how to do ..Here is the steps Step 1: use Web3\Contract; $contractAddress = 'ERC-20 contract deployed address' $contract = new Contract('http://localhost:8545', $abi); $contractInstance = $contract->at($contractAddress);

Step 2:

$amount = 100, $receiver = 'Receiver addresss'

Step 3:

$contractInstance->call(transfer, [$amount, $receiver], $callback);
1

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 = '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);

Have a nice day!

1
  • You are using the API from mainnet.infura.io/v3/your-project-id ..I installed the Ethereum node on my Server. I am able to generate address there ..Able to send transaction from there.. Is it possible to to do with it??
    – Vikas
    Sep 25 '21 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.