blockchain - 源文件需要不同的编译器版本: Truffle

标签 blockchain ethereum solidity smartcontracts truffle

我已经用 Solidity 编写了一份简单的智能合约,并尝试使用 truffle 来迁移它。

$ truffle migrate
Compiling .\contracts\Election.sol...
Compiling .\contracts\Migrations.sol...

    /D/ethereum/electiondemo/contracts/Migrations.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
    pragma solidity ^0.4.24;
    ^----------------------^

Compilation failed. See above.`enter code here`
Truffle v5.0.0 (core: 5.0.0)
Node v8.11.1

Solidity 版本为 0.5.0。 请在下面找到智能合约的代码:

pragma solidity ^0.5.0;

contract Election {
    // Read/write candidate
    string public candidate;

    // Constructor
    constructor ( ) public {
        candidate = "Candidate 1";
    }
}

最佳答案

得到解决方案: 在 truffle.js 中。您需要指定 Solidity 版本

module.exports = {
   // See <http://truffleframework.com/docs/advanced/configuration>
   // for more about customizing your Truffle configuration!
   networks: {
       development: {
           host: "127.0.0.1",
           port: 7545,
           network_id: "*" // Match any network id
       }
   },
   compilers: {
       solc: {
           **version: "0.4.24"** // ex:  "0.4.20". (Default: Truffle's installed solc)
       }
   }
};

在您的智能合约中给出同样的需要

关于blockchain - 源文件需要不同的编译器版本: Truffle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53976057/

相关文章:

hyperledger-fabric - 在 Hyperledger Fabric CA 中注册和注册证书有什么区别

blockchain - 坚固性 : Getting error as Member “balance” not found or not visible after argument-dependent lookup

blockchain - 使用 interface 和 delegateCall 调用外部 Solidity 合约

solidity - 无法将 Uniswap V2 Periphery 作为包添加到 Brownie

node.js - 币安测试网部署错误 : Could not create addresses from your mnemonic or private key(s)

performance - Hyperledger Fabric可扩展性

python - 尝试从 chainlink 导入时 brownie-config 重新映射错误

blockchain - 警告 : SPDX license identifier not provided in source file

blockchain - 如何从 NEAR 协议(protocol)中的私钥和/或帐户 ID 获取公钥?

ethereum - 如何从区 block 链获取智能合约调用的交易