Reputation: 15
I'm working on a Dutch Auction style ICO contract and I'm currently trying to migrate an early stage of my ERC20 contract to test the basic features (does it have the correct name, symbol, and decimals). The contract compiles but I can't migrate it since it is an "abstract contract". My token contract inherits from ERC20Detailed, the Open Zeppelin contract, which in turn inherits from the IERC20 interface contract. What can I do to fix this? I tried having my Token contract also inherit from ERC20 the base contract but it said the identifier was already declared. I see the possible responses from the Truffle terminal output but I'm curious why my implementation won't work and would love some more help understanding Solidity interfaces and abstract contracts.
What can I do to fix this? I tried having my Token contract also inherit from ERC20 the base contract but it said the identifier was already declared.
pragma solidity ^0.5.8;
import "node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
contract Token is ERC20Detailed{
constructor(string memory _name, string memory _symbol, uint8 _decimals)
ERC20Detailed(_name, _symbol, _decimals)
public
{
}
}
Output from Bash terminal
"Token" is an abstract contract or an interface and cannot be deployed. * Import abstractions into the '.sol' file that uses them instead of deploying them separately. * Contracts that inherit an abstraction must implement all its method signatures exactly. * A contract that only implements part of an inherited abstraction is also considered abstract.
Upvotes: 1
Views: 3783
Reputation: 9365
If you look closer at ERC20Detailed contract, you will notice ERC20Detailed is IERC20
. In simple English, it says "this ERC20Detailed inherits all functionalities from IERC20".
Now, take a look at IERC20 contract. You will notice all functions there were terminated with ;
with no logic. This is what we call as Abstract Contracts in Solidity.
Your front-end contract (Token) wants to use all functions from:
That's why you are getting This contract does not implement all functions and thus cannot be created
error.
To solve this problem, try this approach:
pragma solidity ^0.5.8;
import "path-to/ERC20/ERC20.sol";
import "path-to/ERC20/ERC20Detailed.sol";
contract Token is ERC20, ERC20Detailed {
constructor(string memory name, string memory symbol, uint8 decimals)
ERC20Detailed(name,symbol,decimals)
public {
// TODO
}
}
The ERC20 contract has all implementations for IERC20 contract. You can give it a try in Remix first this code below:
pragma solidity ^0.5.8;
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
contract Token is ERC20, ERC20Detailed {
constructor(string memory name, string memory symbol, uint8 decimals)
ERC20Detailed(name,symbol,decimals)
public {
// TODO
}
}
Upvotes: 5