npm solc: AssertionError [ERR_ASSERTION]: Invalid callback specified

前端 未结 10 3026
灰色年华
灰色年华 2021-02-19 07:41

I am trying to compile solidity smart contract using npm solc. I tried to follow different examples. Link to example: https://medium.com/coinmonks/how-to-compile-a-solidity-sma

相关标签:
10条回答
  • 2021-02-19 07:52

    If you have see error like this.You must do following two steps.

    1. Uninstall solc:

      npm uninstall solc

    2. Reinstall one of two versions:

    The version used in the course:

    npm install --save solc@0.4.17
    

    or

    The newest version that will not break:

    npm install --save solc@0.4.25
    

    source - Udemy - Ethereum and Solidity The Complete Developer's Guide

    0 讨论(0)
  • 2021-02-19 07:57

    This is generally the assertion error between the solidity compiler that you have installed and the solidity compiler version that you are using in the solidity contract file. If you are using

    npm install --save solc@0.4.25

    to install solc in your mac then, please use the same version of pragma in your solidity file like the following

    pragma solidity^0.4.25

    0 讨论(0)
  • 2021-02-19 08:03

    with solc 0.7.1:

    
    function compileContract() {
        let voterSOl = fs.readFileSync('./contracts/voter.sol' , 'utf8')
        let complierInput = {
            language: 'Solidity',
            sources:
            {
                'voter.sol': 
                {
                    content: voterSOl
                }
            },
            settings:
            {
                optimizer:
                {
                    enabled: true
                },
                outputSelection:
                {
                    '*':{
                        '*':['*']
                    }
                }
            }
        };
        console.log('compiling contract');
        let compiledContract = JSON.parse(solc.compile(JSON.stringify(complierInput)));
        console.log('Contract Compiled');
        for (let contractName in compiledContract.contracts['voter.sol']) {
            console.log(contractName , compiledContract.contracts['voter.sol'][contractName].abi);      
            let abi = compiledContract.contracts['voter.sol'][contractName].abi;
            fs.writeFileSync(`./contracts/bin/${contractName}_abi.json` , JSON.stringify(abi));
            return compiledContract.contracts['voter.sol'][contractName];
        }
    }
    
    0 讨论(0)
  • 2021-02-19 08:07

    Which version of solc are you using?

    Solc released a breaking version the other day, this error is related to that.

    npm uninstall solc
    npm install solc@0.4.25
    
    0 讨论(0)
提交回复
热议问题