安装openzeppelin可能遇到的问题

环境:

Ubuntu 16.04

Node 10.16.0

什么是OpenZeppelin

OpenZeppelin是一套命令行工具,可在以太坊以及所有其他由EVM和eWASM支持的区块链上开发,部署和运营智能合约项目。包含一些已经写好的经过安全验证的智能合约,以及提供了编写可升级智能合约的方案。

简单点就是类似脚手架。

1
npm install --global @openzeppelin/cli

官方网站: https://openzeppelin.com/

官方Github: https://github.com/OpenZeppelin/openzeppelin-sdk

官方文档: https://docs.openzeppelin.com/


执行部分命令时可能会遇到一些问题:

Node版本

使用10.x或者12.x

https://docs.openzeppelin.com/learn/setting-up-a-node-project#installing_node

一定要在空目录里面进行 unpack ,否则出现下面的错误

1
2
3
# 在非空目录执行 openzeppelin unpack starter
# 这个错误信息有点不符合
Failed to verify https://github.com/openzeppelin/starter-kit.git at branch stable. Details: read ECONNRESET

python 版本不对

报python语法错误,使用了python3.6,应当使用python2.7

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:198:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
gyp ERR! System Linux 4.4.0-171-generic

python2.7安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 添加源
sudo add-apt-repository ppa:deadsnakes/ppa
# 安装python2.7
sudo apt-get update
sudo apt-get install python2.7
# 验证版本
python -V
# 如果输出版本号不对,或者提示没有python
# 先看python安装位置
whereis python
# 找到python2.7路径,如/usr/bin/python2.7
# 测试是否可执行
/usr/bin/python2.7 -V
# 添加环境变量,此处参考了 https://blog.csdn.net/lzzyok/article/details/77413968
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
# 测试,如果输出2.7版本就是可以的了
python -V
# 如果有多个可以用这个命令调整优先级
sudo update-alternatives --config python3

sha3@x.x.x 安装失败

1
2
3
4
5
# 类似如下错误
npm ERR! sha3@1.2.0 install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sha3@1.2.0 install script 'node-gyp rebuild'.

ubuntu:

1
sudo apt-get install build-essential

参考:

https://github.com/provable-things/ethereum-bridge/issues/36

https://github.com/phusion/node-sha3/issues/27