Solidity v^0.5.0 编译器错误 [指定的回调无效]

Tor*_*rof 2 ethereum solidity

我正在尝试编译我的合同,但出现此错误:

AssertionError [ERR_ASSERTION]: Invalid callback specified.
Run Code Online (Sandbox Code Playgroud)

一种答案是更改编译器的版本,但我的版本是最新的(0.5.0)。我实际上正在尝试使用旧代码(0.4.17)并升级它。尝试了2天,一直失败。

这是我的合同:

pragma solidity ^0.5.0;

contract Lottery{
 address public manager;
 address payable [] public players;

 modifier restricted {
     require(msg.sender == manager);
     _;
 }

 constructor() public {
     manager = msg.sender;
 }

 function participate() public payable {
     require(msg.value > .01 ether);
     players.push(msg.sender);
 }

 function pseudoRandom() private view returns(uint){
     return uint(keccak256(abi.encodePacked(block.difficulty, now, players)));
 }

 function pickWinner() public restricted {
     require(msg.sender == manager);
     uint index = pseudoRandom() % players.length;
     address(players[index]).transfer(address(this).balance);
     (players) = new address payable[](0);
 }

 function getPlayers() public view returns(address payable[] memory){
     return players;
 }  
}
Run Code Online (Sandbox Code Playgroud)

这是我的 package.json:

{
 "name": "lottery",
 "version": "1.0.0",
 "description": "lottery contract with Solidity",
 "main": "compile.js",
 "directories": {
   "test": "test"
 },
 "scripts": {
   "test": "mocha"
 },
 "author": "Torof",
 "license": "ISC",
 "dependencies": {
   "ganache-cli": "^6.2.1",
  "mocha": "^5.2.0",
  "save": "^2.3.2",
  "solc": "^0.5.0",
  "tar": "^4.4.8",
  "truffle": "^4.1.14",
  "truffle-hdwallet-provider": "0.0.6",
  "web3": "^1.0.0-beta.36"
}
}
Run Code Online (Sandbox Code Playgroud)

这是编译器:

const path = require('path');
const fs = require('fs');
const solc = require('solc');            //Could the error be here ?

const lotteryPath = path.resolve(__dirname, 'contracts', 'Lottery.sol');
const source = fs.readFileSync( lotteryPath, 'utf8');

module.exports = solc.compile(source, 1).contracts[':Lottery'];


console.log(solc.compile(source, 1));
Run Code Online (Sandbox Code Playgroud)

最后我发现了这个错误消息但没有明白:

[ts]
Could not find a declaration file for module 'solc'. 
'/home/torof/desk/coding/Udemy/ETH-stephenGrider/lottery/node_modules/solc/index.js'  
implicitly has an 'any' type.
Try `npm install @types/solc` if it exists or add a new declaration (.d.ts) file containing `declare module 'solc';`
Run Code Online (Sandbox Code Playgroud)

use*_*559 6

以前的版本solc支持您正在使用的编译样式,但看起来新版本仅支持标准 JSON 输入和输出。你可能想要这样的东西:

console.log(JSON.parse(solc.compile(JSON.stringify({
  language: 'Solidity',
  sources: {
    'lottery.sol': {
      content: source,
    },
  },
  settings: {
    outputSelection: {
      '*': {
        '*': ['evm', 'bytecode'],
      },
    },
  },
}))).contracts['lottery.sol'].Lottery);
Run Code Online (Sandbox Code Playgroud)