gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 00:27:01 33 4
gpt4 key购买 nike

    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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com