I need to send erc20 tokens from one address to another, provided that the token balance is not empty. I check the balance as follows:
const balance = contractInstance.methods.balanceOf (walletAddress) .call (function (err, result) {
//console.log(err)
if (result> 0) {
console.log ("result")
}
If there are 3 tokens on the account, then the result variable is 3000000000000000000 After that, I want to send all tokens from this account to my other account:
web3.eth.getTransactionCount (fromAddress)
.then ((count) => {
let rawTransaction = {
'from': walletAddress,
'gasPrice': web3.utils.toHex (20 * 1e9),
'gasLimit': web3.utils.toHex (41000),
'to': tokenAddress,
'value': '0x' + result.toString('hex'),
'data': contract.methods.transfer (fromAddress, amount) .encodeABI (),
'nonce': web3.utils.toHex (count)
}
But in the end I get the error insufficient funds for gas * price + value, how do I correctly convert the result variable to send tokens?