Vik*_*age 4 ethereum solidity truffle
我牢固地编写了一个简单的智能合约,并尝试用松露迁移它。
$ truffle migrate
Compiling .\contracts\Election.sol...
Compiling .\contracts\Migrations.sol...
/D/ethereum/electiondemo/contracts/Migrations.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.24;
^----------------------^
Compilation failed. See above.`enter code here`
Truffle v5.0.0 (core: 5.0.0)
Node v8.11.1
Run Code Online (Sandbox Code Playgroud)
实体版本为0.5.0。请找到以下智能合约代码:
pragma solidity ^0.5.0;
contract Election {
// Read/write candidate
string public candidate;
// Constructor
constructor ( ) public {
candidate = "Candidate 1";
}
}
Run Code Online (Sandbox Code Playgroud)
得到了解决方案:在truffle.js中。您需要指定实体版本
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
}
},
compilers: {
solc: {
**version: "0.4.24"** // ex: "0.4.20". (Default: Truffle's installed solc)
}
}
};
Run Code Online (Sandbox Code Playgroud)
智能合约中也需要同样的条件
将下面的行添加到 truffle-config.js
{
compilers: {
solc: {
version: "0.4.24" // ex: "0.4.20". (Default: Truffle's installed solc)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4346 次 |
| 最近记录: |