英文:
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 carbon credit
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.
英文:
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.
答案1
得分: 1
当您编译文件时,您将会得到以下内容:
当您部署时,您必须确保选择了CarbonCreditTrade
下拉菜单。您正在尝试部署IERC20
,但您不能将接口部署到EVM,因为它没有代码实现。接口只包含函数签名。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论