Truffle

兼容性問題:Truffle 版本是 0.5.16 但 Solidity 文件需要 0.8.3

  • December 5, 2021

我的智能合約 (SC) 文件包含以下行:

pragma solidity ^0.8.3;

當我用松露編譯它時,我收到以下錯誤:

Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.8.3".
Please update your truffle config or pragma statement(s).
(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)

Compilation failed. See above.
Truffle v5.1.67 (core: 5.1.67)
Node v10.23.3

我的配置文件的內容是:

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
   },
   develop: {
     port: 8545
   }
 }
};

有人請指導我如何解決這個兼容性問題。

祖爾菲。

您必須在 truffle-config 文件中將所需的版本添加到編譯器部分,有關更多詳細資訊,請參閱文件

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
   },
   develop: {
     port: 8545
   }
 },
 compilers: {
   solc: {
     version: "0.8.3"
   }
 }
};

引用自:https://ethereum.stackexchange.com/questions/114984