0

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;
    }

    }
  • The revert is thrown from the contract. You need to post your contract code. – Adam Kipnis Jan 18 '18 at 20:02
  • Ok give me 2 secondes, ok done ! – Ilan Jan 18 '18 at 20:02
  • Does it print the owner address before the error occurs? – willjgriff Jan 18 '18 at 23:00
  • Hey sorry for the delay, yes it does – Ilan Jan 22 '18 at 13:26
  • For me the issue was due to lack of gas. – Volatil3 Mar 8 '18 at 12:12
1

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

0

I got the same error with a similar scenario in truffle, in which I want to set the address from a deployed contract, like the following:

Instance.setContractAddress(_address,{from:account}).then(...);

In the beginning, I put the _address directly with only numbers like 0xb2...

Then I tried to test the same code in Remix, which throw an error "syntax error unexpected token x in json at position 2", so after another round of google I know the _address should be surrounded with quotes, like:

Instance.setContractAddress("0xb2...",{from:account}).then(...);

That works in my case. Hope it help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.