Search code examples
ethereumblockchainsoliditysmartcontractsremix

Abstract Contract Error in deploying smart contract in Remix IDE using solidity


I am new to solidity and trying to run the below smart contract to trade carbon credits: '''

// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.8.2 <0.9.0;

interface IERC20 {
    function transfer(address recipient, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

/**
 * @title Storage
 * @dev Store & retrieve value in a variable
 * @custom:dev-run-script ./scripts/deploy_with_ethers.ts
 */
contract CarbonCreditTrade {

    address public buyer;
    address public seller;
    uint public carbonCreditsAvailable;
    uint public creditPointsAwarded;

    IERC20 public token; //Token contract interface
    uint256 public creditPrice; //Price per carbon credit in token units

    constructor(address payable _tokenAddress, uint256 _creditPrice){
        seller = msg.sender;
        carbonCreditsAvailable = 10000; //set the initial number of carbon credits available

        token = IERC20(_tokenAddress);
        creditPrice = _creditPrice;
    }

    function buyCarbonCredits(uint _creditsToBuy) external {
        require(msg.sender != seller, "seller is not buying CC");
        require(_creditsToBuy <= carbonCreditsAvailable, "insufficient carbon credits available");

        uint256 totalCost = _creditsToBuy * creditPrice; //set the cost of each carboncredit

        require(token.balanceOf(msg.sender) >= totalCost,"Insufficient token for desired number of credits");

        buyer = msg.sender;
        carbonCreditsAvailable -= _creditsToBuy;
        creditPointsAwarded += _creditsToBuy / 10;

        //Transfer the purchased carbon credits to the buyer
        require(token.transfer(buyer, _creditsToBuy), "Token transfer failed");
    }

    function getCreditPointsAwarded() external view returns (uint){
        return creditPointsAwarded;
    }

}

'''

However when trying to deploy the IERC20 contract in the remix contract dropdown I get below error: This contract may be abstract, not implement an abstract parent's methods completely or not invoke an inherited contract's constructor correctly

Can anyone please help? The answers on google suggest the correct contract may not be selected to be deployed. However I am selecting the correct contract.


Solution

  • when you compile the file, you will have those

    enter image description here

    when you deploy, you have to make sure CarbonCreditTrade dropdown is selected. you are trying to deploy IERC20 but you cannot deploy interface in to EVM because there is no code implementation. interface just have function signatures