Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ethereum Solidity v^0.5.0编译器错误[指定的回调无效]_Ethereum_Solidity - Fatal编程技术网

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

Ethereum Solidity v^0.5.0编译器错误[指定的回调无效],ethereum,solidity,Ethereum,Solidity,我正在尝试编译合同,但出现以下错误: AssertionError [ERR_ASSERTION]: Invalid callback specified. 一个答案是更改编译器的版本,但我的版本是最新的(0.5.0)。 实际上,我正在尝试使用旧代码(0.4.17)并对其进行升级。尝试了两天,但一直失败 这是我的合同: pragma solidity ^0.5.0; contract Lottery{ address public manager; address payable []

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

AssertionError [ERR_ASSERTION]: Invalid callback specified.
一个答案是更改编译器的版本,但我的版本是最新的(0.5.0)。 实际上,我正在尝试使用旧代码(0.4.17)并对其进行升级。尝试了两天,但一直失败

这是我的合同:

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;
 }  
}
这是我的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"
}
}
这是编译器:

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));
最后,我发现了这个错误消息,但没有得到它:

[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';`

您是否尝试安装此软件包:

npm install @types/solc

以前版本的
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);

下面是0.5.X的单向实现,以及部署代码: 这就是我编译的方式,获取字节码需要进行深层嵌套销毁

const path = require('path');
const fs = require('fs');
const solc = require('solc');

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

const input = {
    language: 'Solidity',
    sources: {
        'yourtemplate.sol': {
            content: source
        }
    },
    settings: {
        outputSelection: {
            '*': {
                '*': ['*']
            }
        }
    }
}

const { abi: interface, evm: { bytecode: { object } } } = JSON.parse(solc.compile(JSON.stringify(input))).contracts['yourtemplate.sol'].Templatename; // 

module.exports = { interface, object }; // object is the actual name of the bytecode

以及部署的代码:

const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const { interface, object: bytecode } = require('../compile'); 
// i've renamed object with bytecode 

const accounts = await web3.eth.getAccounts();
  templatename = await new web3.eth.Contract(interface)
    .deploy({ data: bytecode, arguments: [INPUT_PARAMETER_GOES_HERE] })
    .send({ from: accounts[0], gas: '1000000' });

npm错误!代码E404 npm错误!404未找到:@types/solc@latestnpm错误!此运行的完整日志可在以下位置找到:npm ERR/home/torof/.npm/_logs/2018-12-04T05_40_55_564Z-debug.log
可以在这里尝试以下答案:[哇,谢谢,终于有了一个有用的提示。但是你在哪里找到的?我还没有找到关于如何在0.5.0中编译的任何信息。我自己尝试了代码,发现错误来自调用
solc.compile
,然后阅读自述文件,发现语法不再存在:。