I have two coins in binance testnet:
I can send default main coins (BNB) to another account:
web3.eth.sendTransaction({
from: account,
to: '0x64123c0c6cc87a7b96c498D584Db17c6cA55eD6F',
value: '1000000',
}, function (err, transactionHash) {
});
But i don't know how to send other coins (USDT or BUSD).
Also i can check current amount of coins, but only for BNB:
const balance = await this.web3.eth.getBalance(account);
When you transfer tokens, you interact with the token contract invoking its transfer()
function.
Same goes for the token balance - you can get the user token balance by querying the token contract's balanceOf()
function.
These functions are specified in the ERC-20 standard, so each token contract following the standard implements them.
const usdtContract = new this.web3.eth.Contract(abiJson, contractAddress);
// sends a transaction from the `sender` address
// containing the `data` field specifying that you want to execute
// the `transfer()` function, passing it the `recipient` and `amount` arguments
await usdtContract.methods.transfer(recipient, amount).send({from: sender});
// performs a gas-free read-only call, invoking the `balanceOf()` function of the contract
await usdtContract.methods.balanceOf(holder).call();