Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify the solidity version in truffle

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to modify the solidity version in truffle". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to modify the solidity version in truffle.

One of the problems you often encounter when using truffle to develop ethernet solidity contracts is that the compiler version required by your solidity contract code does not match the pre-installed solitiy compiler version of truffle.

1. Problem recurrence

As solidity is relatively new and the syntax is still changing, the demonstration source code you find online may no longer be able to be compiled by the latest version of the solidity compiler. For example, when you compile an earlier version 0.4 contract with a new version of truffle, the compiler is prompted for a mismatch:

$truffle migrateCompiling.\ 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

Of course, the original solidity contract code can be modified to meet the requirements of the new solidity compiler. However, if there is a large amount of historical legacy code, this solution will bring a huge amount of work, and there is a great possibility to introduce a new bug.

Therefore, it is better to specify the version of the Solidity compiler for the Truffle project.

2. Set the solidity compiler version of the truffle project

Fortunately, truffle allows us to specify which version of the compiler to use in the project, simply by setting the compiler option in the configuration file truffle.js of the truffle project. For example, the following configuration file sets the solidity compiler for the current project to version 0.4.24:

Module.exports = {networks: {... Etc...}, compilers: {solc: {version: "0.4.24"}

You only need to specify the solidity compiler version to be enabled at compilers.solc.version, and truffle will automatically pull the corresponding version of the compiler from the official, without the need for you to download the configuration manually.

Thank you for your reading, the above is the content of "how to modify the solidity version in truffle". After the study of this article, I believe you have a deeper understanding of how to modify the solidity version in truffle, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report