Solidity – VM Exception While Processing Transaction: Revert

soliditytruffleweb3js

So I've customized this handleTransfer function from truffle tutorial,

I receive an error

Error: [ethjs-rpc] rpc error with payload 
{"id":200574...blablabla,"jsonrpc":"2.0","params":
["0xf86f8...blablabla"],"method":"eth_sendRawTransaction"} Error: VM Exception 
while processing transaction: revert

I don't know why. Does someone has an idea.

    handleTransfer: function(event) {
    event.preventDefault();

    var amount = parseInt($('#TTTransferAmount').val());
    var toAddress = $('#TTTransferAddress').val();
    var price = parseInt($('#TTPrice').val())

    console.log('Transfer ' + amount + ' TT to ' + toAddress);

    var tutorialTokenInstance;

    web3.eth.getAccounts(function(error, accounts) {
      if (error) {
        console.log(error);
      }

      var account = accounts[0];

      App.contracts.TutorialToken.deployed().then(function(instance) {
        tutorialTokenInstance = instance;
        var value = web3.toWei(price);
        var owner = tutorialTokenInstance.owner.call().then(console.log);

        return tutorialTokenInstance.sendTransaction({
          from: account,
          to: owner,
          value: value
})
.then(function(receipt){
    return tutorialTokenInstance.transfer(account, amount, {from: owner});
});
      }).then(function(result) {
        alert('Transfer Successful!');
        return App.getBalances();
      }).catch(function(err) {
        console.log(err.message);
      });
    });
  },

If you need some more info let me know

Here comes the contract

pragma solidity ^0.4.17;

import 'zeppelin-solidity/contracts/token/StandardToken.sol';
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';

    contract TutorialToken is StandardToken, Ownable {

        string public name = 'TutorialToken';
        string public symbol = 'TT';
        uint8 public decimals = 2;
        uint public INITIAL_SUPPLY = 12000;

        function TutorialToken() public {
        totalSupply = INITIAL_SUPPLY;
        balances[msg.sender] = INITIAL_SUPPLY;
        owner = msg.sender;
    }

    }

Best Answer

I should have used web.eth and not an instance of the contract.

Related Topic