Ethereum 使用solidity创建合同,但不会';不执行 编辑您的合同。。。

Ethereum 使用solidity创建合同,但不会';不执行 编辑您的合同。。。,ethereum,truffle,Ethereum,Truffle,Node v8.9.4在您的块菌配置文件中添加以下内容: Compiling ./contracts/Hello.sol Compiling ./contracts/Migrations.sol /home/mohamed/Projects/Stage/Truffle/contracts/Hello.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+c

Node v8.9.4

在您的块菌配置文件中添加以下内容:

Compiling ./contracts/Hello.sol
Compiling ./contracts/Migrations.sol

/home/mohamed/Projects/Stage/Truffle/contracts/Hello.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.15;
^----------------------^
,/home/mohamed/Projects/Stage/Truffle/contracts/Hello.sol:4:4: SyntaxError: No visibility specified. Did you intend to add "public"?
   function Hello1() {
   ^ (Relevant source part starts here and spans across multiple lines).

Error: Truffle is currently using solc 0.5.0, but one or more of your contracts specify "pragma solidity ^0.4.15".
Please update your truffle config or pragma statement(s).
(See https://truffleframework.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.0.12 (core: 5.0.12)

阅读有关配置的更多信息。所有的Solidity版本都可以找到。

您困惑的是什么?您的代码说它需要0.4.x版本的编译器,但Truffle使用的是0.5.x。要么将代码更新为使用0.5.x,要么将Truffle降级为使用0.4.x。
Compiling ./contracts/Hello.sol
Compiling ./contracts/Migrations.sol

/home/mohamed/Projects/Stage/Truffle/contracts/Hello.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.15;
^----------------------^
,/home/mohamed/Projects/Stage/Truffle/contracts/Hello.sol:4:4: SyntaxError: No visibility specified. Did you intend to add "public"?
   function Hello1() {
   ^ (Relevant source part starts here and spans across multiple lines).

Error: Truffle is currently using solc 0.5.0, but one or more of your contracts specify "pragma solidity ^0.4.15".
Please update your truffle config or pragma statement(s).
(See https://truffleframework.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.0.12 (core: 5.0.12)
module.exports = {
  // your existing config goes here
  // don't forget to put comma on the last element before proceeding to next line

  compilers: {
    solc: {
      version: "0.4.25"
    }
  }
}