当我尝试在控制台中执行时

node compile.js


我得到这个错误。


  RangeError:尝试在Solidity中进行编译时,超出了最大调用堆栈大小


Invox.sol:

pragma solidity  ^0.4.25;

contract Invox {
    string public message;

    function Invox (string initialmessage) public {
        message = initialmessage;
    }
    function setMessage(string _message) public {
        message = _message;
    }
}


compile.js:

const path = require('path');
const fs = require('fs');
const solc = require('solc');
const invoxPath = path.resolve(__dirname, 'contracts', 'invox.sol');
const source = fs.readFileSync(invoxPath, 'utf8');
//We have replaced the following line, but the issue persists
module.compile = solc.compile(source, 1).contracts[':Invox'];
//console.log(solc.compile(source, 1));


package.json:

{
  "name": "invox",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "solc": "^0.4.25"
  }
}

最佳答案

npm install-保存[email protected]

运行上面的命令并更改invox.sol中的solidity版本

语用强度^ 0.4.25; ->实用性坚固度^ 0.4.17;

09-25 16:46