npm solc: AssertionError [ERR_ASSERTION]: Invalid callback specified

前端 未结 10 3025
灰色年华
灰色年华 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:43

    I fixed the error with adding "npm install --save solc@0.4.25" in cmd. Error is the solidity version. you need to install old version of solidity to execute the compile script

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

    If you are using latest version ie. 0.5.9 there is change in how you compile the code.

    const path = require('path');
    const fs = require('fs');
    const solc = require('solc');
    
    
    
    const helloPath = path.resolve(__dirname, 'contracts', 'hello.sol');
    const source = fs.readFileSync(helloPath, 'UTF-8');
    
    var input = {
        language: 'Solidity',
        sources: {
            'hello.sol' : {
                content: source
            }
        },
        settings: {
            outputSelection: {
                '*': {
                    '*': [ '*' ]
                }
            }
        }
    }; 
    console.log(JSON.parse(solc.compile(JSON.stringify(input))));
    
    0 讨论(0)
  • 2021-02-19 07:45

    This is because of version mismatch of solidity compiler installed during solc package installation and the compiler mentioned in the solidity file.To solve this issue try

    install:

    npm install solc@0.4.25

    in solidity file use :

    pragma solidity^0.4.25;

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

    Check your code in Remix first, then check compiler version

    0 讨论(0)
  • 2021-02-19 07:45
    • unistall solidity compiler

    • using - npm uninstall solc

    • then install required version of solidity compiler

    • using - npm install solc@0.4.17

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

    This is because the version mismatch of Solidity compiler. Please note or verify the solidity compiler version in which you want to work. For example: If you are doing work in

    pragma solidity ^0.4.17
    

    then you have to install 0.4.17 solidity compiler version like this:

    npm install solc@0.4.17
    

    in the command prompt or terminal.

    0 讨论(0)
提交回复
热议问题