Solidity

由於編譯器版本太舊,無法導入大多數庫

  • December 2, 2021

我的契約有pragma solidity ^0.8.0;,但我正在使用這個庫來拆分使用pragma solidity ^0.5.0;.

單獨更改這一行不會解決問題,它會創建新的(其他編譯錯誤)。

我能做些什麼?

[1] Compiling your contracts...
[1] ===========================
[1] > Compiling @openzeppelin\contracts\access\Ownable.sol
[1] > Compiling @openzeppelin\contracts\token\ERC721\ERC721.sol
[1] > Compiling @openzeppelin\contracts\token\ERC721\IERC721.sol
[1] > Compiling @openzeppelin\contracts\token\ERC721\IERC721Receiver.sol
[1] > Compiling @openzeppelin\contracts\token\ERC721\extensions\IERC721Metadata.sol
[1] > Compiling @openzeppelin\contracts\utils\Address.sol
[1] > Compiling @openzeppelin\contracts\utils\Context.sol
[1] > Compiling @openzeppelin\contracts\utils\Strings.sol
[1] > Compiling @openzeppelin\contracts\utils\introspection\ERC165.sol
[1] > Compiling @openzeppelin\contracts\utils\introspection\IERC165.sol
[1] > Compiling .\contracts\MyContract.sol
[1] > Compiling solidity-util\lib\Strings.sol
[1] 
[1] ParserError: Source file requires different compiler version (current compiler is 0.8.7+commit.e28d00a7.Emscripten.clang) - note that nightly builds are considered 
to be strictly less than the released version
[1]  --> solidity-util/lib/Strings.sol:1:1:
[1]   |
[1] 1 | pragma solidity ^0.5.0;
[1]   | ^^^^^^^^^^^^^^^^^^^^^^^
[1]
[1]
[1] Error: Truffle is currently using solc 0.8.7, but one or more of your contracts specify "pragma solidity ^0.5.0".
[1] Please update your truffle config or pragma statement(s).
[1] (See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on
[1] configuring Truffle to use a specific solc compiler version.)

您可以嘗試在您在此處稱為“我的契約”的目前契約中使用 pragma solidity <= 0.8.0

如果您使用 truffle 編譯器,您可以嘗試以下步驟

  1. 在 中指定 openzeppelin 版本package.json

“依賴”:{“@openzeppelin/contracts”:“^4.4.0”}, 2. 執行npm install安裝指定的版本依賴。 3. 跑truffle compile

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