5

truffle | truffle 版本差异

 2 years ago
source link: https://benpaodewoniu.github.io/2022/05/24/truffle5/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

truffle 的版本区别非常大,而且,目前我并没有找到相关的资料,明确的介绍不同版本的差异,所以,目前,我也只能根据自己所使用过的版本来做介绍。

不过,很多版本我都是浅尝辄止,因为我的目的是找到一个高度可用的版本,而不是探索各个版本。

测试的版本

  • 5.0.7
  • 5.0.22
  • 5.4.12

5.0.7

npm install [email protected]
truffle init

使用 5.0.7 进行 init 会出现下面的错误

Preparing to download
✖ Downloading
Error: Error: Error: Error making request to https://raw.githubusercontent.com/truffle-box/bare-box/master/truffle-box.json. Got error: connect ECONNREFUSED 0.0.0.0:443. Please check the format of the requested resource.
at Object.unbox (/Users/licong/solidity/test/node_modules/truffle/build/webpack:/packages/truffle-box/box.js:65:1)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Truffle v5.0.7 (core: 5.0.7)

解决方案如下

If anyone encounter the same problem, just add the following line in the /etc/hosts:
151.101.56.133 raw.githubusercontent.com
It will work.
edit: update hosts filename: /etc/hosts

注意,我的环境时 MBP

truffle version
Truffle v5.0.7 (core: 5.0.7)
Solidity v0.5.0 (solc-js)
Node v13.14.0

这里可以看出 solidity 的编译器是 0.5.0 版本的。

solc 编译器

truffle 最关键的就是看 solc 该怎么处理,而 solc 因为多次资源链接更换,现在想要通过

truffle compile

下载对应版本已经不行了。「目前,我还没找到在线相关的下载 solc 对应版本的方法」

而,5.0.7 版本,是通过把 solc 下载到 node_module 中,进行编译的,请看下面图片

5_0.png

所以,如果你改变 truffle-config.js 的 solc 版本后,会进行下载,但是,大概率下载不下来。

所以,这个版本最终放弃。

5.0.22

npm install [email protected]
Truffle v5.0.22 (core: 5.0.22)
Solidity v0.5.0 (solc-js)
Node v13.14.0
Web3.js v1.0.0-beta.37

solc 编辑器

5.4.12

目前使用这个版本,推荐。

ps: 这个版本,我重复安装了十几次,每次都会有新的意外发生,究其原因就是网络的问题,非常烦躁。

安装 xcode

我的环境是 MBP,首先我们要安装 xcode,如果通过 app store 安装的话,将会有十几个G,所以,我们这里仅安装一些简单的。

xcode-select --install
npm: '8.1.2',
node: '16.13.1',

另外,我的源是 淘宝源,可以从上面的博文中找到。试了一下其他版本,没下载下来,不知道是真的下不下来,还是网或者其他原因。

这里有一个非常奇怪的点,就是,我的 nvm 使用后,只在当前的命令行窗口有用,开了新的窗口就又变成其他版本了。但是,好在其他版本可以正常编译。

安装 truffle

npm install [email protected]

这里会遇到很多情况

  • 卡在某一个包停下来了
  • 卡在了最后一步

卡在某一个包停下来了

idealTree:multiaddr: sill fetch manifest varint@^5.0.2
idealTree:abstract-leveldown: sill placeDep ROOT [email protected] OK for: @consento/[email protected] want: ^3.0.5

可以单独安装这个包

"seedrandom": "3.0.5",
"varint": "^5.0.2"

上面两个包都是下不下来,然后单独安装的。

另外,如果你 ctrl + c 再次安装某一个单独包的时候出错了,请使用

rm -rf node_modules
npm cache clean -f

卡在了最后一步

reify:faker: timing reifyNode:node_modules/truffle Completed in 6873ms
或者
reify:truffle: http fetch GET 200 https://cdn.npmmirror.com/packages/truffle/5.4.12/truffle-5.4.12.tgz 14992ms (cache miss)

只能等待了。我个人怀疑,这次下载下来的包会在本地进行编译等工作,所以,最后一步的速度会非常慢。

  • 我试了公司的网还有家里的网都不行,最后连接了手机热点才能下下来
    • 后来经过测试,即便是没有翻墙,借助淘宝源也是可以安装的,只不过需要耗费的时间非常多,但是,其他我安装了十几次,最终找到了这个行之有效的方法

solc 编辑器

值得庆幸的是,这一版本的 trufflesolc-bin 是可以通过 truffle compile 下下来的,看来这个版本的 url 指向 solc 对了。

另外,5.4.12 版本和上面 5.0.22 版本最终 solc 存放的地方也不一样,具体是哪里,目前,我还没找到,所以,现阶段只能在线下载。

下载还是蛮快的,但是,需要看好版本号。

  • 0.8.1
  • 0.8.11

我下载都很快。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK