Truffle: VM Exception while processing transaction: revert

Created on 14 Jan 2018  路  13Comments  路  Source: trufflesuite/truffle

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

When i try to sendTransaction from address to my Contract i get the following error:

VM Exception while processing transaction: revert

Steps to Reproduce from test issue repository

1.Clone this repository http://gitlab.youvolio.com/kristiyan.tachev/truffle-contracts-issue
2.npm i
3.npm run migrate
4(optional). tsc .

  1. Or skip 4 and execute directly npm start it will start index.js which is compiled from index.ts
  2. It should show error like in the title

Steps to Reproduce from scratch

1.npm init

2.truffle init

3.truffle compile

4.truffle migrate

5.Import json file generated from builds

pragma solidity ^0.4.13;

import 'zeppelin-solidity/contracts/token/MintableToken.sol';

contract Coin is MintableToken {
  string public name = "COIN";
  string public symbol = "CTP";
  uint8 public decimals = 18;
}

CONTRACT 
pragma solidity ^0.4.13;

import './Coin.sol';
import 'zeppelin-solidity/contracts/crowdsale/Crowdsale.sol';


contract CoinCrowdsale is Crowdsale {

  function CoinCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet) 
    Crowdsale(_startTime, _endTime, _rate, _wallet) {          
  }

  // creates the token to be sold.
  // override this method to have crowdsale of a specific MintableToken token.
  function createTokenContract() internal returns (MintableToken) {
    return new Coin();
  }
}


import * as CoinCrowdsale from './contracts/CoinCrowdsale';
import * as truffleContract from 'truffle-contract';
import * as Web3 from 'web3';
import { HttpProvider, Personal, Provider, Providers, Account, Eth, Utils} from 'web3/types';

const web3: Web3 = new Web3();
const provider: HttpProvider = new web3.providers.HttpProvider("http://localhost:8545");

let ContractCrowdsaleInstance;
const TruffleContractCrowdsaleInstance = truffleContract(CoinCrowdsale);
TruffleContractCrowdsaleInstance.setProvider(provider);

TruffleContractCrowdsaleInstance.deployed()
.then(async instance => {
     ContractCrowdsaleInstance = instance;
     const transaction = {
           from: "0xf17f52151EbEF6C7334FAD080c5704D77216b732",
           value: web3.utils.toWei(5, "ether")
     }
     const tx = await instance.sendTransaction(transaction);
     console.log(tx);
})

The address generated above is automatically provided by Genache Elektron App
screenshot from 2018-01-14 20-03-10

screenshot from 2018-01-15 01-27-01

When i try to send transaction it breaks with the following error:

screenshot from 2018-01-14 16-09-33

Expected Behavior

When sending transaction from contract to an address there should be no error message and amount of tokens should be transferred to address purchased and ether needs to be transferred to contract owner balance.
Previews week it was working fine and transaction was passing now contract is deployed and again i cannot send transaction to my contract...

Environment

  • Operating System: Linux
  • Truffle version: 4.0.4
  • Ethereum client: Web3
  • node version: 7.9.0 / 8.9.4
  • npm version: 5.6.0
  • genache web app version: 1.0.2

Most helpful comment

Guys this is INSANE!!!!

I just put as a last chance try! PARAMETER GAS to sendTransaction Oh my god and it is fucking working!!!!!!!!!!!!!! I am soo soo happy !!

Anyway if someone have the same problem try to put gas as a parameter with appropriate amount :+1:

this.rawTruffleInstance.sendTransaction({from: address, value: web3.utils.toWei(amount, "ether"), gas: "220000"})

48 Hours to catch this miss understanding i can't believe it really...

All 13 comments

@Stradivario I haven't had a chance to read this fully yet, but I can tell just at a glance that this is a great bug report - thanks! In fact, it looks like the changes I just made to the ganache-cli issue template have some of the same things you've added here.

@Stradivario Ganache 1.0.3 isn't out yet - perhaps you meant 1.0.2?

@Stradivario if you post a link to your project repro or to a throwaway repo containing an example reproduction I'll run it. In the mean time, your migrations file is missing, so I can't go much further.

My best guess at this point is that you haven't set the startTime and/or endTime correctly, per the validPurchase function.

Another tip: you can debug this yourself with truffle debug. This tutorial will show you how it's done.

Also have a look at the truffle testing docs - you shouldn't be using hardcoded addresses, etc, as you've done above.

@benjamincburns give me 1 hour and i will create repository

Anyway my migration code is this

const CoinCrowdsale = artifacts.require("./CoinCrowdsale.sol")

// 1.Init migration

var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};
// 2. Deploy contract migration
module.exports = function(deployer, network, accounts) {
  const startTime = web3.eth.getBlock(web3.eth.blockNumber).timestamp + 1 // one second in the future
  const endTime = startTime + (86400 * 20) // 20 days
  const rate = new web3.BigNumber(1000)
  const wallet = accounts[0]

  deployer.deploy(CoinCrowdsale, startTime, endTime, rate, wallet)
};



md5-05d724db12f6696c16172fd83385341f



Gathering transaction data...

/Users/billy/.nvm/versions/node/v7.2.0/lib/node_modules/truffle/build/cli.bundled.js:333580
      accept(result.result.structLogs);
                          ^

TypeError: Cannot read property 'structLogs' of undefined
    at /Users/billy/.nvm/versions/node/v7.2.0/lib/node_modules/truffle/build/cli.bundled.js:333580:27
    at /Users/billy/.nvm/versions/node/v7.2.0/lib/node_modules/truffle/build/cli.bundled.js:322668:9
    at XMLHttpRequest.request.onreadystatechange (/Users/billy/.nvm/versions/node/v7.2.0/lib/node_modules/truffle/build/cli.bundled.js:324093:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/billy/.nvm/versions/node/v7.2.0/lib/node_modules/truffle/build/cli.bundled.js:71245:18)
    at XMLHttpRequest._setReadyState (/Users/billy/.nvm/versions/node/v7.2.0/lib/node_modules/truffle/build/cli.bundled.js:71535:12)
    at XMLHttpRequest._onHttpResponseEnd (/Users/billy/.nvm/versions/node/v7.2.0/lib/node_modules/truffle/build/cli.bundled.js:71690:12)
    at IncomingMessage.<anonymous> (/Users/billy/.nvm/versions/node/v7.2.0/lib/node_modules/truffle/build/cli.bundled.js:71650:24)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)

About Genache yes you are right ! Version is 1.0.2 not 1.0.3

@benjamincburns Here is a repository where i am facing the bug i created it from scratch like it was working before 6 days :D

http://gitlab.youvolio.com/kristiyan.tachev/truffle-contracts-issue

Also in this repository there is a command inside package.json npm run truffle-fix it will copy lib/truffle-contract/contract.js to ./node_modules/truffle-contract/ this is because of issue with send and sendAsync explained here https://github.com/trufflesuite/truffle-contract/issues/57 if i don't do this it will throw error

TypeError: Cannot read property 'apply' of undefined

Guys this is INSANE!!!!

I just put as a last chance try! PARAMETER GAS to sendTransaction Oh my god and it is fucking working!!!!!!!!!!!!!! I am soo soo happy !!

Anyway if someone have the same problem try to put gas as a parameter with appropriate amount :+1:

this.rawTruffleInstance.sendTransaction({from: address, value: web3.utils.toWei(amount, "ether"), gas: "220000"})

48 Hours to catch this miss understanding i can't believe it really...

@Stradivario glad to hear you've got it working.

Bear in mind that the default gas limit for transactions is 90000 so you'll need to set the gas parameter on anything which consumes more than that. Have a search around for eth_estimateGas or web3.eth.estimateGas and that'll help out a great deal. Also tools like truffle-contract are great for this - they'll automatically call eth_estimateGas for you before running the transaction so that you don't need to worry about finding the exact gas cost ahead of time.

You might also be wondering "why did it revert instead of fail with 'Out of gas?'" The best I can tell is that before running some operations the solidity runtime checks whether or not you've allowed enough gas for that operation to succeed and reverts if not. This saves you the cost of the transaction failure, but makes debugging the problem a little difficult.

At least on .catch needs to throw raw error instead of hard coded error which can come from many different problems when passing wrong parameters to your customized contract for example :)

Regards! :+1:

Hello World!
I faced the same error, but with a different scenario.
The same transaction succeed the first time, but it fails when I executed for the second time.

Contract.deployed().then((instance) => {
  instance.addSkill("python", "github.com", {gas: "4712388"}).then(console.log).catch(console.log);
});

when I run this script twice, the first time it succeed , but the first time it raises VM Exception while processing transaction: revert

I thought web3 would run estimateGas on its own. Once I did it manually and set the gas in the send() all was good

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rjl493456442 picture rjl493456442  路  4Comments

ferittuncer picture ferittuncer  路  3Comments

ripper234 picture ripper234  路  4Comments

hefgi picture hefgi  路  3Comments

bmmpxf picture bmmpxf  路  3Comments