1

I just learned how to send BNB from one wallet to another in Binance Smart Chain.

It looks like

const account = web3.eth.accounts.privateKeyToAccount('xxxxxxx')
web3.eth.accounts.wallet.add(account);
web3.eth.sendTransaction({
    from: address1,
    to: address2,
    value: '100000000000',
    gas: 5000000,
    gasPrice: 18e9,
}, callback)

And this code sends BNB from one account to another one

But how to do the same with USDT? Maybe, do I have to include USDT's contractAbi?

Fixer
  • 11
  • 1
  • 3

1 Answers1

1

Need to work with ERC20 standard through contract ABI.

See some examples:

This one: https://piyopiyo.medium.com/how-to-send-erc20-token-with-web3-js-99ed040693ce

This one: How to send ERC20 token using Web3 API?

Keep asking for questions, and if this answer was enough, please choose it as correct.

Ether Man
  • 56
  • 8
  • Thank you so much, but I met some problems. Maybe my version of web3 is newer then in your articles, but I haven't got ".at(...)" method (using in web3.eth.contract(minABI).at(tokenAddress)) Also I have no .transfer(...) method. I can only call it by contract.methods.transfer(...) – Fixer Apr 24 '22 at 13:35
  • Yes, Web3 versions of articles are older. However, you can refer to the updated functions: https://web3js.readthedocs.io/en/v1.7.3/ But basically you need to call the ABI of the token contract you have.. Please choose it answer as correct. – Ether Man Apr 26 '22 at 13:48