松露错误:错误:处理事务时VM异常:还原

时间:2017-12-16 12:30:39

标签: blockchain ethereum truffle

我正在使用松露:

truffle(development)> var hw  
undefined 
truffle(development)> HelloWorld.deployed().then(function(deployed){hw=deployed;}); 
undefined 
truffle(development)> hw.SayHello.call() 

我在松露中遇到错误

***Error: VM Exception while processing transaction: revert 
    at Object.InvalidResponse (C:\Users\dell\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:41484:16) 
    at C:\Users\dell\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:328866:36 
    at C:\Users\dell\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:324536:9 
    at XMLHttpRequest.request.onreadystatechange (C:\Users\dell\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:327565:7) 
    at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\dell\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:176407:18)  
    at XMLHttpRequest._setReadyState (C:\Users\dell\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:176697:12) 
    at XMLHttpRequest._onHttpResponseEnd (C:\Users\dell\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:176852:12) 
    at IncomingMessage.<anonymous> (C:\Users\dell\AppData\Roaming\npm\node_modules\truffle\build\cli.bundled.js:176812:24) 
    at emitNone (events.js:111:20) 
    at IncomingMessage.emit (events.js:208:7) ***

1)我的HelloWorld.sol
`

pragma solidity ^0.4.8;
contract HelloWorld { 
   function SayHello() public returns (string) { 
        return ("SomeHello"); 
    } 
} 

2)我的2_deploy_contracts.js

var ConvertLib = artifacts.require("./ConvertLib.sol");
var MetaCoin = artifacts.require("./MetaCoin.sol");
var HelloWorld = artifacts.require("./HelloWorld.sol");
var second = artifacts.require("./second.sol");

module.exports = function(deployer) { 
  deployer.deploy(ConvertLib);
  deployer.link(ConvertLib, MetaCoin); 
  deployer.deploy(MetaCoin); 
  deployer.deploy(HelloWorld);
  deployer.deploy(second);
}; 

3)我的松露.js

module.exports = { 
  networks: { 
    development: { 
      host: "localhost", 
      port: 8545, 
      network_id: "*" // Match any network id 
    } 
  } 
};

请告诉我如何解决上述错误?

`

1 个答案:

答案 0 :(得分:0)

我刚刚运行了你的例子,它工作正常。我做的唯一改变是我从2_deploy_contracts中删除了其他不使用的智能合约。在启动松露控制台之前,请确保运行compilemigrate命令并且testrpc正在运行。此外,如果您在Windows上运行,请将truffle.js重命名为truffle-config.js

$ truffle compile 
Compiling .\contracts\HelloWorld.sol... 
Writing artifacts to .\build\contracts

$ truffle migrate 
Using network 'development'.

Running migration: 2_deploy_contracts.js   
Deploying HelloWorld...   
... 0xef7e895758805a3c3c9aaed7dc7c97fe7b2278b0c0d6ee8105192183a86188c9 
HelloWorld: 0x54329ff919efda7920408084590d7480a6c88243 
Saving successful migration to network...   
... 0x0954625bf66275469c9475ca21f5db20bc4667efb716c5e19bfd98a9553f4a83 
Saving artifacts...

$ truffle console 
truffle(development)> var hw 
undefined 
truffle(development)> HelloWorld.deployed().then(function(deployed){hw=deployed;}); 
undefined 
truffle(development)> hw.SayHello.call() 
'SomeHello' 
truffle(development)>

2_deploy_contracts.js

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

module.exports = function(deployer) {   deployer.deploy(HelloWorld); };
相关问题