初入DApp——配置环境到差点放弃的辛酸血泪

本文没有干货,只是一个记录(防止以后……),并且通过写一篇水文发泄我心中积郁的情绪!!!!!

前言

阻挡我学习脚步的不是技术有多难,而是配环境,配环境要了命,这次是最要命的!!!!
想上手做个dapp,一方面自己初学,一方面看的白嫖教程太旧,导致很多坑!!!!

虚假的顺畅过程

首先最终完整版的truffle配置过程
我的最后环境:
Kali linux 2020
Node 8.11.3
Npm 5.6.0
Truffle 4.1.12
ganache-cli 6.10.1
全程我是在root权限下操作

  • 安装node

apt-get install nodejs

  • 安装npm

apt-get install npm

  • 配置npm源为国内源,加快下载速度:

npm config set registry http://registry.npm.taobao.org

  • 安装指定的node 版本
npm install -g n
n v8.11.3
  • 安装指定版本的truffle

npm install -g truffle@4.1.12

  • 安装ganache-cli

npm install -g ganache-cli

进入验证环节

  • 新建目录

mkdir test

  • 进入目录

cd test

  • 拉取一个模板

truffle unbox webpack

  • 启动

ganache-cli

  • 修改项目中的truffle.js
形如:
module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*" // Match any network id
    }
  }
};
  • 然后编译

Truffle compile

  • 部署

truffle migrate

  • 进入控制台

truffle console

真实的辛酸

然后回顾我这惨烈的两天
以前了解点区块链,也看了一点以太坊的书,然后翻了solidity的文档
https://learnblockchain.cn/docs/solidity/installing-solidity.html#id4
因为下学期要做一个项目,思来想去决定跟着视频做一个dapp,边学遍配,然后噩梦开始了


先在我的windows上
安装ganache,我想安装图形化的,结果下载半天没反应,就找到别人下载好的资源,发现打开,半天没反应,放弃,下载Ganache命令行版的吧


在拉取truffle unbox webpack时,大概有这样的错误

D:\truffle\my_dapp>truffle unbox webpack

Starting unbox...
=================

√ Preparing to download box
× Downloading
Unbox failed!
× Downloading
Unbox failed!
RequestError: Error: getaddrinfo ENOENT raw.githubusercontent.com
    at new RequestError (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\request-promise-core\lib\errors.js:14:1)
    at Request.plumbing.callback (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\request-promise-core\lib\plumbing.js:87:1)
    at Request.RP$callback [as _callback] (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\request-promise-core\lib\plumbing.js:46:1)
    at self.callback (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\request\request.js:185:1)
    at Request.emit (events.js:223:5)
    at Request.onRequestError (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\request\request.js:881:1)
    at ClientRequest.emit (events.js:223:5)
    at TLSSocket.socketErrorListener (_http_client.js:415:9)
    at TLSSocket.emit (events.js:223:5)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
Truffle v5.1.39 (core: 5.1.39)
Node v12.15.0

解决

通过https://www.ipaddress.com   查询 raw.githubusercontent.com 的地址。
配置host文件  C:\Windows\System32\drivers\etc\host   增加地址
199.232.68.133  raw.githubusercontent.com
我是直接就加了上面这个
Linux是进入/etc/hosts 中添加
199.232.68.133  raw.githubusercontent.com

Truffle compile时有如下错误,然后噩梦就开始了

× Fetching solc version list from solc-bin. Attempt #1
× Fetching solc version list from solc-bin. Attempt #2
× Fetching solc version list from solc-bin. Attempt #3
Error: Could not find a compiler version matching 0.5.16. Please ensure you are specifying a valid version, constraint or build in the truffle config. Run `truffle compile --list` to see available versions.
    at VersionRange.errors (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\compilerSupplier\loadingStrategies\LoadingStrategy.js:66:1)
    at VersionRange.getSatisfyingVersionFromCache (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\compilerSupplier\loadingStrategies\VersionRange.js:81:1)
    at VersionRange.load (C:\Users\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\compile-solidity\compilerSupplier\loadingStrategies\VersionRange.js:197:1)
Truffle v5.1.39 (core: 5.1.39)
Node v12.15.0
  • 尝试一

在项目下truffle-config.js中指定编译版本

  compilers: {
    solc: {
      version: "0.4.23",           
    },
  },

各种版本都试了,不行
然后又有说权限问题

  • 尝试二,三,四……

我就在ubuntu上重复,还是不行
然后又有说重试几次就好了,重试了无数次,无用
又有说网络问题,我就换热点,甚至学会了上外网,还是不行

  • 冷静分析

然后凭我多年被配环境折磨支配的大脑的冷静的思考,我觉得可能是版本问题,然后就准备换node npm等版本,但是一顿卸载,重装胡乱操作,把我原本的node,npm也弄没了,装也装不了
呜呜呜呜呜呜


我怎么可能被打败!!!!!

我又掏出新环境,我的kali 2018来配,结果发现npm有问题

没办法我又装了kali 2020

先把科大的源写入vim /etc/apt/sources.list
再 apt-get update
apt-get upgrade
然后安装以上环境,终于成功了,就是拉取模板truffle unbox webpack时

ownloading...
Error: Truffle Box at URL https://github.com/truffle-box/webpack-box doesn't exist. If you believe this is an error, please contact Truffle support.
    at Request._callback (/usr/local/lib/node_modules/truffle/build/webpack:/.-box/lib/utils/unbox.js:50:1)
    at Request.self.callback (/usr/local/lib/node_modules/truffle/build/webpack:/Users/gnidan/src/work/truffle/~/request/request.js:185:1)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/Users/gnidan/src/work/truffle/~/request/request.js:1157:1)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/Users/gnidan/src/work/truffle/~/request/request.js:1079:1)
    at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)

直接通过git clone +报错中的Url就好了

后记

当看到成功时,已经连续两天半1点半睡,7点多起,今天中午饭没吃,已经连续坐了好几个小时的我,激动地干呕,想哭,太不容易了,呜呜呜呜呜

期间还遇到很多错误,但因为cup爆到90%,并且心烦意乱,很多都没有记录

最后是我的部分参考链接,很多找不到了

https://blog.csdn.net/luoluobaby/article/details/104462863
https://blog.csdn.net/zxs9999/article/details/107079329
https://blog.csdn.net/TurkeyCock/article/details/79165602?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
https://blog.csdn.net/qq_20513027/article/details/85041353
https://www.cnblogs.com/liaozhenghan/p/12484398.html
https://zhuanlan.zhihu.com/p/83253046

posted @ 2020-08-14 19:35  启林O_o  阅读(752)  评论(0)    收藏  举报