SimpleAirdrop 合同部署问题甚至编译工作
SimpleAirdrop contract deploy issue even compile is working
我正在尝试制作 Airdrop 智能合约,但 return“此合约可能是抽象的,未完全实现抽象父类的方法或未正确调用继承合约的构造函数。”部署时的消息......虽然编译工作正常。
请检查下面我的代码
pragma solidity ^0.4.18;
contract ERC20 {
function transfer(address _to, uint256 _value)public returns(bool);
function balanceOf(address tokenOwner)public view returns(uint balance);
function transferFrom(address from, address to, uint256 tokens)public returns(bool success);
}
contract SimpleAirdrop is IERC20 {
IERC20 public token;
uint256 public _decimals = 18;
uint256 public _amount = 1*10**6*10**_decimals;
function SimpleAirdrop(address _tokenAddr) public {
token = IERC20(_tokenAddr);
}
function setAirdrop(uint256 amount, uint256 decimals) public {
_decimals = decimals;
_amount = amount*10**_decimals;
}
function getAirdrop(address reff) public returns (bool success) {
require (token.balanceOf(msg.sender) == 0);
//token.transfer(msg.sender, 1000000000000000000000);
//token.transfer(reff , 200000000000000000000);
token.transfer(msg.sender, _amount);
token.transfer(reff , _amount);
return true;
}
}
您的 SimpleAirdrop
继承自 IERC20
(请参阅第一个注释)。 IERC20
是一个抽象合约——它只定义了它的功能,但没有实现它们。这使得 SimpleAirdrop
(IERC20
的子合约)也是一个抽象合约。
Solidity 不允许部署抽象合约。所以你有两个选择让它不抽象:
实现transfer()
、balanceOf()
和transferFrom()
函数(在两个合约中的任何一个)。
或
去掉继承,这样contract SimpleAirdrop is IERC20
就变成了contract SimpleAirdrop
.
假设您的 SimpleAirdrop
的上下文仅在外部 IERC20
地址上执行函数,但本身不充当 ERC-20 令牌,选项 2 足以满足您的需求用例。
备注:
您的问题定义了 ERC20
合同,但其余代码使用 IERC20
。我假设这只是将您的代码复制到问题时的错字,否则您在所有地方都使用相同的命名。
当前的 Solidity 版本(2021 年 6 月)是 0.8.5
。我推荐使用当前版本,有安全和错误修复。
请检查以下代码是否有任何误解
编译没问题,使用参数部署,测试网成功
调用 startAirdrop 函数时出现问题...gas
出现一些问题
请注意
pragma solidity ^0.4.18;
contract ERC20 {
function transfer(address _to, uint256 _value)public returns(bool);
function balanceOf(address tokenOwner)public view returns(uint balance);
function transferFrom(address from, address to, uint256 tokens)public returns(bool success);
}
contract SimpleAirdrop {
ERC20 public token;
uint256 public _decimals = 9;
uint256 public _amount = 1*10**6*10**_decimals;
uint256 public _cap = _amount *10**6;
address public tokenOwner = 0x0;
uint256 public _totalClaimed = 0;
uint256 public _reffPercent = 10;
function SimpleAirdrop(address _tokenAddr ,address _tokenOwner ) public {
token = ERC20(_tokenAddr);
tokenOwner = _tokenOwner;
}
function setAirdrop(uint256 amount, uint256 cap, uint256 decimals ,uint256 reffPercent) public returns (bool success){
require (msg.sender == tokenOwner);
_decimals = decimals;
_amount = amount*10**_decimals;
_cap = cap*10**_decimals;
_reffPercent = reffPercent;
return true;
}
function sendAirdropToken() public returns (bool success){
require (msg.sender == tokenOwner);
token.transferFrom(msg.sender,address(this),_cap);
return true;
}
function returnAirdropToOwner() public returns (bool success){
require (msg.sender == tokenOwner);
token.transferFrom(address(this), msg.sender, address(this).balance);
return true;
}
function getAirdrop(address reff) public returns (bool success){
if(msg.sender != reff && token.balanceOf(reff) != 0 && reff != 0x0000000000000000000000000000000000000000 && _cap >= _amount){
token.transfer(reff , _amount*(_reffPercent/100));
_cap = _cap - (_amount*(_reffPercent/100));
}
if(msg.sender != reff && token.balanceOf(reff) != 0 && token.balanceOf(msg.sender) == 0 && reff != 0x0000000000000000000000000000000000000000 && _cap >= _amount)
{ token.transfer(msg.sender, _amount);
_cap = _cap - _amount;
_totalClaimed ++;
}
return true;
}
}
我正在尝试制作 Airdrop 智能合约,但 return“此合约可能是抽象的,未完全实现抽象父类的方法或未正确调用继承合约的构造函数。”部署时的消息......虽然编译工作正常。 请检查下面我的代码
pragma solidity ^0.4.18;
contract ERC20 {
function transfer(address _to, uint256 _value)public returns(bool);
function balanceOf(address tokenOwner)public view returns(uint balance);
function transferFrom(address from, address to, uint256 tokens)public returns(bool success);
}
contract SimpleAirdrop is IERC20 {
IERC20 public token;
uint256 public _decimals = 18;
uint256 public _amount = 1*10**6*10**_decimals;
function SimpleAirdrop(address _tokenAddr) public {
token = IERC20(_tokenAddr);
}
function setAirdrop(uint256 amount, uint256 decimals) public {
_decimals = decimals;
_amount = amount*10**_decimals;
}
function getAirdrop(address reff) public returns (bool success) {
require (token.balanceOf(msg.sender) == 0);
//token.transfer(msg.sender, 1000000000000000000000);
//token.transfer(reff , 200000000000000000000);
token.transfer(msg.sender, _amount);
token.transfer(reff , _amount);
return true;
}
}
您的 SimpleAirdrop
继承自 IERC20
(请参阅第一个注释)。 IERC20
是一个抽象合约——它只定义了它的功能,但没有实现它们。这使得 SimpleAirdrop
(IERC20
的子合约)也是一个抽象合约。
Solidity 不允许部署抽象合约。所以你有两个选择让它不抽象:
实现
transfer()
、balanceOf()
和transferFrom()
函数(在两个合约中的任何一个)。或
去掉继承,这样
contract SimpleAirdrop is IERC20
就变成了contract SimpleAirdrop
.
假设您的 SimpleAirdrop
的上下文仅在外部 IERC20
地址上执行函数,但本身不充当 ERC-20 令牌,选项 2 足以满足您的需求用例。
备注:
您的问题定义了
ERC20
合同,但其余代码使用IERC20
。我假设这只是将您的代码复制到问题时的错字,否则您在所有地方都使用相同的命名。当前的 Solidity 版本(2021 年 6 月)是
0.8.5
。我推荐使用当前版本,有安全和错误修复。
请检查以下代码是否有任何误解 编译没问题,使用参数部署,测试网成功 调用 startAirdrop 函数时出现问题...gas
出现一些问题请注意
pragma solidity ^0.4.18;
contract ERC20 {
function transfer(address _to, uint256 _value)public returns(bool);
function balanceOf(address tokenOwner)public view returns(uint balance);
function transferFrom(address from, address to, uint256 tokens)public returns(bool success);
}
contract SimpleAirdrop {
ERC20 public token;
uint256 public _decimals = 9;
uint256 public _amount = 1*10**6*10**_decimals;
uint256 public _cap = _amount *10**6;
address public tokenOwner = 0x0;
uint256 public _totalClaimed = 0;
uint256 public _reffPercent = 10;
function SimpleAirdrop(address _tokenAddr ,address _tokenOwner ) public {
token = ERC20(_tokenAddr);
tokenOwner = _tokenOwner;
}
function setAirdrop(uint256 amount, uint256 cap, uint256 decimals ,uint256 reffPercent) public returns (bool success){
require (msg.sender == tokenOwner);
_decimals = decimals;
_amount = amount*10**_decimals;
_cap = cap*10**_decimals;
_reffPercent = reffPercent;
return true;
}
function sendAirdropToken() public returns (bool success){
require (msg.sender == tokenOwner);
token.transferFrom(msg.sender,address(this),_cap);
return true;
}
function returnAirdropToOwner() public returns (bool success){
require (msg.sender == tokenOwner);
token.transferFrom(address(this), msg.sender, address(this).balance);
return true;
}
function getAirdrop(address reff) public returns (bool success){
if(msg.sender != reff && token.balanceOf(reff) != 0 && reff != 0x0000000000000000000000000000000000000000 && _cap >= _amount){
token.transfer(reff , _amount*(_reffPercent/100));
_cap = _cap - (_amount*(_reffPercent/100));
}
if(msg.sender != reff && token.balanceOf(reff) != 0 && token.balanceOf(msg.sender) == 0 && reff != 0x0000000000000000000000000000000000000000 && _cap >= _amount)
{ token.transfer(msg.sender, _amount);
_cap = _cap - _amount;
_totalClaimed ++;
}
return true;
}
}