1

I am trying to make Airdrop smartcontract but it return "This contract may be abstract, not implement an abstract parent's methods completely or not invoke an inherited contract's constructor correctly." message when deployed.....The compile works fine though. Please check my code below

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;
        }
} 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

Your SimpleAirdrop inherits from IERC20 (see the first note). IERC20 is an abstract contract - it only defines its functions, but it doesn't implement them. Which makes SimpleAirdrop (the child contract of IERC20) an abstract contract as well.

Solidity doesn't allow deploying abstract contracts. So you have two options to make it not abstract:

  1. Implement the transfer(), balanceOf() and transferFrom() functions (in any of the two contracts).

    OR

  2. Remove the inheritance, so that contract SimpleAirdrop is IERC20 becomes only contract SimpleAirdrop.

Assuming by the context of your SimpleAirdrop, which only executes functions on an external IERC20 address, but doesn't act as an ERC-20 token itself, option 2 is sufficient for your use case.


Notes:

  • Your question defines ERC20 contract but the rest of the code uses IERC20. I'm assuming this is just a typo while copying your code to the question, and that otherwise you're using the same naming in all places.

  • The current Solidity version (in June 2021) is 0.8.5. I recommend using the current version, there are security and bug fixes.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
0

Please check for any misconception in codes below No problem in compiling , Deployed using parameters and success in testnet Problem rise when calling startAirdrop function...some problem with gas

Please be advised

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;
            
        }
        
        
    

    
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459