npm solc: AssertionError [ERR_ASSERTION]: Invalid callback specified

前端 未结 10 2992
灰色年华
灰色年华 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 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];
        }
    }
    

提交回复
热议问题