前提・実現したいこと
https://github.com/OpenZeppelin/openzeppelin-contracts
上記のOpenZeppelinに準拠したトークンを作成したい
発生している問題・エラーメッセージ
ブロックチェーンアプリケーション開発の教科書という本と
こちらのサイトと http://kojiryo.com/968/ こちらのhttps://qiita.com/yanyansk/items/eb4f71a16302c321e16d 参考に
トークンを作成していったところ下記のようにtruffleのバージョンと
solidityとtruffleバージョンが合わないみたいなエラーメッセージが出てきたので
truffle(develop)> test Compiling your contracts... =========================== > Compiling .\contracts\DappsToken.sol > Compiling .\contracts\Migrations.sol > Compiling openzeppelin-solidity/contracts/token/ERC20/ERC20.sol openzeppelin-solidity/contracts/token/ERC20/ERC20.sol:3:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version pragma solidity ^0.6.0; ^---------------------^ Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.6.0". 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(develop)>
該当のソースコード
solidity
1pragma solidity ^0.5.0; 2import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; 3 4contract DappsToken is ERC20 5{ 6 string public name = "DappsToken"; 7 string public symbol = "DTKN"; 8 uint public decimals = 18; 9 10 constructor(uint initialSupply) public 11 { 12 _mint(msg.sender, initialSupply); 13 } 14 15}
試したこと
トークンコントラクトを下記のように変え
solidity
1pragma solidity ^0.6.0; 2import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol"; 3 4contract DappsToken is ERC20 5{ 6 string public _name = "DappsToken"; 7 string public _symbol = "DTKN"; 8 uint public _decimals = 18; 9 10 constructor(uint initialSupply) public 11 { 12 _mint(msg.sender, initialSupply); 13 } 14 15}
truffleのコンフィグを下記のように変えましたが
javascript
1 compilers: 2 { 3 solc: 4 { 5 version: "0.6.0", // Fetch exact version from solc-bin (default: truffle's version) 6 docker: true, // Use "0.5.1" you've installed locally with docker (default: false) 7 parser: "solcjs", 8 settings: 9 { // See the solidity docs for advice about optimization and evmVersion 10 optimizer: 11 { 12 enabled: true, 13 runs: 200 14 }, 15 evmVersion: "byzantium" 16 } 17 } 18 }
また似たようなエラーが出てしまいました。
truffle(develop)> test Compiling your contracts... =========================== > Compiling .\contracts\DappsToken.sol > Compiling .\contracts\Migrations.sol /C/Users/doria/dapps-token/contracts/DappsToken.sol:1:1: ParserError: Source file requires different compiler version (current compiler is 0.5.16+commit.9c3226ce.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version pragma solidity ^0.6.0; ^---------------------^ Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity ^0.6.0". 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.
補足情報(FW/ツールのバージョンなど)
OS Win10 64bit
テキストエディダ VSCode
truffle(develop)> truffle version
Truffle v5.1.35 (core: 5.1.35)
Solidity v0.5.16 (solc-js)
Node v12.18.2
Web3.js v1.2.1
あなたの回答
tips
プレビュー