首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在混合中编译错误并不能使事情变得清晰

在混合中编译错误并不能使事情变得清晰
EN

Ethereum用户
提问于 2018-03-01 21:20:16
回答 2查看 81关注 0票数 1

在这里做第5课,如何编写智能合同,第5课,我在混合中得到了编译错误。它说:

browser/ballot.sol:40:2: ParserError:预期的实用化、导入指令或契约/接口/库定义。函数批准(address _spender,uint _value)公共常量返回(bool成功){

完整的代码是:

代码语言:javascript
复制
pragma solidity ^0.4.18;

contract SimpleTokenCoin{

string public constant name = "Simple Coin Token";

string public constant symbol = "SCT";

uint32 public constant decimals = 18;

uint public totalSupply = 0;

mapping (address => uint) balances;

function balanceOf(address _owner) public constant returns (uint balance){ return balances[_owner]; }

function transfer(address _to, uint _value) public returns (bool success){ if(balances[msg.sender] >= _value && balances[_to] + _value >= balances[_to]){ balances[msg.sender] -=_value; balances[_to] += value; Transfer(msg.sender, _to, _value); return true; } return false; }

function transferFrom(address _from, address _to, uint _value) public returns (bool success){ if(balances[_from] >= _value && balances[_to] + _value >= balances[_to]){
balances[_from] -=_value; balances[_to] += value; Transfer(_from, _to, _value); return true; } return false; } }

function approve(address _spender, uint256 _value) public constant returns (bool success){ return false; }

function allowance(address _owner, address _spender) public constant retuns (uint256 remaining){ return 0; }

function mint(address _to, uint _value) public { assert(totalSupply + _value >= totalSupply && balances[_to] +_value >= balances[_to]); balances[_to] += _value; totalSupply += _value;
}

event Transfer(address indexed _from, address indexed _to, uint value);

event Approval(address indexed _owner, address indexed _spender, uint _value); 
} 
EN

回答 2

Ethereum用户

回答已采纳

发布于 2018-03-01 21:38:06

您必须与我们共享您的完整代码才能确定,但我的猜测是您没有定义合同。您的代码应该如下所示:

代码语言:javascript
复制
contract MyContract {
    function approve(address _spender, uint256 _value) public constant returns (bool success) {
        return false;
    }
}

这也可能是因为你提前结束了合同。通常,错误可能意味着您试图在契约之外定义一个函数。

票数 0
EN

Ethereum用户

发布于 2018-03-05 01:57:43

r函数的returns部分上缺少一个allowance

对于未来的问题,我还建议使用像Remix这样的IDE来识别语法和几乎所有其他错误(当然,不包括逻辑错误)。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/41391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档