以太坊开发时遇到的错误整理

一 、truffle 开发时遇到的

1、migrate部署错误
错误1 :ALERT: Trying to call a function on a non-contract address.
解决:重新truffle migrate --reset
2、compile编译错误

  1. SyntaxError: Functions are not allowed to have the same name as
    the contract. If you intend this to be a constructor, use
    “constructor(…) { … }” to define it.
    版本问题导致构造函数写法发生变化,可以改成
    function Election (…) ——> constructor(…)
  2. TypeError: Data location must be “storage” or “memory” for parameter
    in function, but none was given.
    solidty 版本变化导致的,0.5.0版本对于struct、map、array需要指明数据位置(data location),但是这里为什么要加还没搞清楚。。。
    参见http://www.tryblockchain.org/Solidity-DataLocation-%E6%95%B0%E6%8D%AE%E4%BD%8D%E7%BD%AE.html
    string _name 改成 string memory _name
  3. TypeError: Event invocations have to be prefixed by “emit”.
    版本变化导致
    votedEvent(_candidateId) 换成 emit votedEvent(_candidateId);

3、MetaMask错误
1、 ALERT: [ethjs-rpc] rpc error with payload{…} Error: the tx doesn’t have the correct nonce. account has nonce of: 4 tx has nonce of: 6
好像是钱包计算nonce值崩了??
解决方法:有人说可以切换一些钱包连接的网络再切换回来,或者卸载钱包重新安装。我用的是打开钱包里的设置,里面有个 重设账户,点击一下

另一个整理的网站
https://blog.csdn.net/haojing8312/article/details/80606226
推荐一个网站https://ethereum.stackexchange.com,里面的问题比较全,百度谷歌不到的可以到里面找找,再找不到就只能看官方文档了https://solidity.readthedocs.io/en/v0.5.0/

二、 node.js 开发遇到的问题

1、这次没有通过truffle框架来开发,而实Remix编译部署合约,用node.js +web3开发。参考https://learnblockchain.cn/2018/04/15/web3-html/
遇到的问题是安装web3的时候报错,

gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\zhou\software\NodeJs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Users\\zhou\\software\\NodeJs\\node.exe" "C:\\Users\\zhou\\software\\NodeJs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\zhou\truffleProjects\info\node_modules\scrypt
gyp ERR! node -v v8.10.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN info@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! scrypt@6.0.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the scrypt@6.0.3 install script.

还有很多就不粘贴了,
解决方法是
① 首先可以先通过 npm cache verify 清理下缓存,在进行安装
② 如果还是安装失败可以尝试 — npm install web3@^0.20.0
我是用安装0.20方法解决的。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值