0
votes

I want to implement a send ERC20 token function in my crypto wallet, and this is the function that I found on the internet shown as below.

 sendToken()
  {
    let toAddress = "0x5077174D79d9491AF15Dcf7D1496638D6062A011";
    this.tokenContractInstance.transfer(toAddress,123, (error, result) => {
      if (error == null) {
        console.log(result)

      } else {
        console.log('Transfer error' + error)
      }
    })
  }

Unfortunately, no luck for me with error message

"Invalid Message"

May I know why is failed? Also, I have seen others example as well to send ERC20 token by generating the rawTransaction with the privateKey sign function. Which approach should I go with?

1

1 Answers

0
votes

Assuming web3 1.0 this is the correct way:

this.tokenContractInstance.methods.transfer(toAddress, 123).send({from: txSenderAddress}, (error, transactionHash) => { ... });