browser/Test.sol:5:21: TypeError: Definition of base has to precede definition of derived contract contract test is owned ^---^
browser/Test.sol:5:21: TypeError: Definition of base has to precede definition of derived contract contract test is owned ^---^
我遇到了一个我真的不知道如何解决的问题,我正在做一个关于在 solidity 上制作智能合约的教程,以便在以太坊上为未来的大学项目启动。我得到的错误是标题上面的错误。我将复制代码,以便您可以看到我拥有的内容并突出显示错误的代码行。我无法弄清楚问题出在哪里,因为我对类型错误感到模棱两可,而且我是 solidity 的新手。
pragma solidity ^0.4.24;
contract NLtoken is owned
{
uint public totalSupply;
string public name;
string public symbol;
uint8 public decimals = 18;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowence;
event Transfer (address indexed _from, address indexed _to, uint tokens);
event Approval (address indexed _tokenOwner, address indexed _spender, uint tokens);
constructor (string tokenName, string tokenSymbol, uint initialSupply) public {
totalSupply = initialSupply*10**uint256(decimals);
balanceOf[msg.sender] = initialSupply;
name = tokenName;
symbol = tokenSymbol;
}
function _transfer (address _from, address _to, uint256 _value) internal returns(bool success){
require(_to != 0x0);
require(balanceOf[_from] >= _value);
require(balanceOf[_to] + _value >= balanceOf[_to]);
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
return true;
}
function transfer (address _to, uint256 _value) public returns (bool success)
{
_transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
{
require(_value <= allowence[_from][msg.sender]);
allowence[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool success)
{
allowence[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function mintToken (address _target, uint256 _mintedAmount) onlyOwner {
balanceOf[_target] += _mintedAmount;
totalSupply += _mintedAmount;
emit transfer(0, owner, _mintedAmount);
emit transfer (owner, _target,_mintedAmount);
}
function burn (uint256 _value) onlyOwner returns (bool succes)
{
require (balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] -= _value;
totalSupply -= _value;
emit burn(msg.sender, _value);
return true;
}
}
contract owned {
address public owner;
constructor ()
{
owner = msg.sender;
}
modifier onlyOwner
{
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner {
owner = newOwner;
}
}
在NLtoken合约之前声明拥有合约。
请记住,事件名称区分大小写:
emit Transfer(0, owner, _mintedAmount);
emit Transfer (owner, _target,_mintedAmount);
对于遇到此问题的任何其他人,我找到的 none 个答案都特别清楚地说明了问题所在,但上面的 Mad Jackal post 足以让我弄清楚。
在我的例子中,我试图继承的合同引用了另一个合同,该合同导入了第三个单独的合同,在第三个合同中,我也试图继承同样的东西,创建循环依赖查找。
我遇到了一个我真的不知道如何解决的问题,我正在做一个关于在 solidity 上制作智能合约的教程,以便在以太坊上为未来的大学项目启动。我得到的错误是标题上面的错误。我将复制代码,以便您可以看到我拥有的内容并突出显示错误的代码行。我无法弄清楚问题出在哪里,因为我对类型错误感到模棱两可,而且我是 solidity 的新手。
pragma solidity ^0.4.24;
contract NLtoken is owned
{
uint public totalSupply;
string public name;
string public symbol;
uint8 public decimals = 18;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowence;
event Transfer (address indexed _from, address indexed _to, uint tokens);
event Approval (address indexed _tokenOwner, address indexed _spender, uint tokens);
constructor (string tokenName, string tokenSymbol, uint initialSupply) public {
totalSupply = initialSupply*10**uint256(decimals);
balanceOf[msg.sender] = initialSupply;
name = tokenName;
symbol = tokenSymbol;
}
function _transfer (address _from, address _to, uint256 _value) internal returns(bool success){
require(_to != 0x0);
require(balanceOf[_from] >= _value);
require(balanceOf[_to] + _value >= balanceOf[_to]);
balanceOf[_from] -= _value;
balanceOf[_to] += _value;
emit Transfer(_from, _to, _value);
return true;
}
function transfer (address _to, uint256 _value) public returns (bool success)
{
_transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)
{
require(_value <= allowence[_from][msg.sender]);
allowence[_from][msg.sender] -= _value;
_transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool success)
{
allowence[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function mintToken (address _target, uint256 _mintedAmount) onlyOwner {
balanceOf[_target] += _mintedAmount;
totalSupply += _mintedAmount;
emit transfer(0, owner, _mintedAmount);
emit transfer (owner, _target,_mintedAmount);
}
function burn (uint256 _value) onlyOwner returns (bool succes)
{
require (balanceOf[msg.sender] >= _value);
balanceOf[msg.sender] -= _value;
totalSupply -= _value;
emit burn(msg.sender, _value);
return true;
}
}
contract owned {
address public owner;
constructor ()
{
owner = msg.sender;
}
modifier onlyOwner
{
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) onlyOwner {
owner = newOwner;
}
}
在NLtoken合约之前声明拥有合约。 请记住,事件名称区分大小写:
emit Transfer(0, owner, _mintedAmount);
emit Transfer (owner, _target,_mintedAmount);
对于遇到此问题的任何其他人,我找到的 none 个答案都特别清楚地说明了问题所在,但上面的 Mad Jackal post 足以让我弄清楚。
在我的例子中,我试图继承的合同引用了另一个合同,该合同导入了第三个单独的合同,在第三个合同中,我也试图继承同样的东西,创建循环依赖查找。