以太坊開發時遇到的錯誤整理

一 、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 [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.

還有很多就不粘貼了,
解決方法是
① 首先可以先通過 npm cache verify 清理下緩存,在進行安裝
② 如果還是安裝失敗可以嘗試 — npm install web3@^0.20.0
我是用安裝0.20方法解決的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章