智慧合約學習 truffle編譯問題
阿新 • • 發佈:2018-11-03
Q1:compile時遇到錯誤提示
contracts/Migrations.sol: ParsedContract.sol:7:14: ParserError: Expected identifier, got 'LParen'
constructor() public {
^
Compilation failed. See above.
~/eth-hunt/
初步判斷為js的編譯器版本不和,即[email protected],與pragma solidity ^x.x.y 不一樣造成,
嘗試:
npm uninstall -g truffle npm install -g truffle
再重複truffle develop ---> compile.問題解決!!!
Q2:compile時提示
Warning: No visibility specified. Defaulting to "public".
function test() pure returns (string) {
^ (Relevant source part starts here and spans across multiple lines).
將contract裡的function中的constant 改為 pure public,即可
Q3:呼叫migrate時不成功遇到Using network 'develop'/n Network up to date.可以試試重新部署 migrate --reset
S1:truffle(develop)> contract = HelloWorld.deployed().then(instance => contract = instance) :instance是引數,()裡為函式。
migrate受阻,檢查後仍通不過,重新truffle develop >compile > migrate
contract裡有pure public console裡可以直接 contarct.test(); 呼叫函式。沒有pure只能contarct.test.call(); 呼叫函式。