ethereum - 使用solidity创建合约但不执行

标签 ethereum truffle

    I'am building a local blockchain using etherium.I wrote a smart contract   "Hello" that allows to display a phrase. when I execute truffle.compile an error occurs:  No visibility specified. Did you intend to add "public"?

    pragma solidity ^0.4.15;
    contract Hello{
       string public message;
       function Hello() {
       message = "Hello, World : This is a Solidity Smart Contract on the Private Ethereum Blockchain ";
       }
    }

编译你的契约(Contract)...

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)

节点 v8.9.4

最佳答案

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

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"
    }
  }
}

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

关于ethereum - 使用solidity创建合约但不执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55637302/

相关文章:

blockchain - 以太坊协议(protocol)如何与 geth 协同工作

azure - 无法在 Microsoft Azure 中部署以太坊 PoA 模板

javascript - web3.personal.ecRecover 没有返回正确的公共(public)地址

javascript - Web3 不将 web3.eth.Contract 视为构造函数

python - 使用本地私钥通过 web3.py 发送 ERC20 token

node.js - 测试RPC/Ganache : the tx doesn't have the correct nonce

node.js - 安装松露时出现 npm 错误 "Keccak bindings compilation fail."

javascript - 如何在 javascript/truffle 中为每个测试创建新的 ethereum/solidity 合约

javascript - 松露毛毛雨错误 "TypeError: Cannot read property ' 地址'未定义”

currency - 销毁智能合约中的代币/硬币