智能合约学习 truffle编译问题

Q1:compile时遇到错误提示 

contracts/Migrations.sol: ParsedContract.sol:7:14: ParserError: Expected identifier, got 'LParen'
  constructor() public {
             ^
Compilation failed. See above.
~/eth-hunt/

初步判断为js的编译器版本不和,即solcjs@x.x.x.,与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(); 调用函数。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值