【发布时间】:2021-08-16 14:37:00
【问题描述】:
对此感到非常困扰,尝试编写 ERC21 收藏品,当我使用 truffle compile 编译我的项目时......我收到一个错误
Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.8.0"
我觉得这很奇怪,因为我已经在我的合同和 package.lock.json 中编辑了版本,尝试删除我的包锁,更改了合同中的版本,然后尝试再次运行 npm install 但无论如何我都会遇到同样的错误我用的是什么版本
我之前在其他项目中遇到过这个错误,但只是通过更正版本来修复它......但这一次不起作用:(
我已经尝试了 pragma solidity >=0.4.21
希望有人能解释我做错了什么?
合约示例
pragma solidity >=0.4.21 <0.6.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract color is ERC721 {
constructor() ERC721("color", "COLOR") {
}
}
truffle.config
require('babel-register');
require('babel-polyfill');
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*" // Match any network id
},
},
contracts_directory: './src/contracts/',
contracts_build_directory: './src/abis/',
compilers: {
solc: {
optimizer: {
enabled: true,
runs: 200
}
}
}
}
package-lock.json
"truffle": {
"version": "5.0.5",
"resolved": "https://registry.npmjs.org/truffle/-/truffle-5.0.5.tgz",
"requires": {
"app-module-path": "^2.2.0",
"mocha": "^4.1.0",
"original-require": "1.0.1",
"solc": "^0.8.0"
}
},
【问题讨论】: