Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

VM Exception while processing transaction: revert #748

Closed
1 task done
Stradivario opened this issue Jan 14, 2018 · 13 comments
Closed
1 task done

VM Exception while processing transaction: revert #748

Stradivario opened this issue Jan 14, 2018 · 13 comments

Comments

@Stradivario
Copy link

Stradivario commented Jan 14, 2018


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 .
5. Or skip 4 and execute directly npm start it will start index.js which is compiled from index.ts
6. 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
@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 15, 2018

@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.

@benjamincburns
Copy link
Contributor

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

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 15, 2018

@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.

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 15, 2018

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.

@Stradivario
Copy link
Author

Stradivario commented Jan 15, 2018

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

When i try to do truffle debug TX from REVERTED transaction i got the following error

From this issue #608

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

@Stradivario
Copy link
Author

Stradivario commented Jan 15, 2018

@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

@Stradivario
Copy link
Author

Stradivario commented Jan 15, 2018

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

@Stradivario
Copy link
Author

Stradivario commented Jan 17, 2018

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 👍

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...

@benjamincburns
Copy link
Contributor

@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.

@benjamincburns
Copy link
Contributor

benjamincburns commented Jan 17, 2018

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.

@Stradivario
Copy link
Author

Stradivario commented Jan 17, 2018

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! 👍

@maroodb
Copy link

maroodb commented Jun 2, 2018

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

lychees added a commit to Andoromeda-Foundation/dapp-examples that referenced this issue Aug 9, 2018
1. Strange test with tradeableToken, testrpc error?trufflesuite/truffle#748

2. Truffle cannot deal with function overload.
@barrard
Copy link

barrard commented Mar 1, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants