1

This is a contract im trying to deploy and i think its an abstract contract as most of the functions dont seem to be implemented... anyway the issue im facing is that truffle is telling me i cant deploy an abstract contract so can someone tell me what to do in this case? Do i need to deploy all the contracts which implements this contract functions first before i can deploy this as well? Im not sure how the system works.

contract ERC20 {
  function totalSupply() public view returns (uint256);

  function balanceOf(address _who) public view returns (uint256);

  function allowance(address _owner, address _spender)
    public view returns (uint256);

  function transfer(address _to, uint256 _value) public returns (bool);

  function approve(address _spender, uint256 _value)
    public returns (bool);

  function transferFrom(address _from, address _to, uint256 _value)
    public returns (bool);

  function decimals() public view returns (uint256);

  event Transfer(
    address indexed from,
    address indexed to,
    uint256 value
  );

  event Approval(
    address indexed owner,
    address indexed spender,
    uint256 value
  );
}
0

You cannot deploy this contract, because not all declared functions are implemented.

Either you implement them in this contract, or you create a new contract which inherits from this contract, and then implement them in the new contract.

If you choose the latter option, then you will need to deploy the new contract.

  • ok so if i choose the latter option, i would not need to depoly this contract? – Sundeep Kumar Mar 25 at 9:33
  • @SundeepKumar: It's not about "not needing to", it's about "not being able to". – goodvibration Mar 25 at 9:34
0

The contract above cannot be deployed, but can be inherited. Something like an interface. Like this example:

pragma solidity >=0.4.22;

contract ERC20 {
  function totalSupply() public view returns (uint256);

}

contract FixedSupplyToken is ERC20 {

    address public owner;
    uint256 _totalSupply = 1000000;


    // Constructor
    constructor() public {
        owner = msg.sender;
    }

    function totalSupply() public view returns (uint256) {
        return _totalSupply;
    }


}

The contract being deployed is FixedSupplyToken. But it can inherit your ERC20.

  • ok so when we deploy the FixedSupplyToken, do we also deploy ERC20? – Sundeep Kumar Mar 25 at 9:37
  • No, you only deploy FixedSupplyToken (for this particular example). As the ERC20 contract works as if it would be an interface. So ERC20 is a contract that is not deployed or even deployable! Although as it is inherited by another contract, it inherits its function declarations as well. I hope this helps in anyway – João Quintanilha Mar 25 at 10:40
  • thanks i found that very helpful and i think i got an idea of how the system works :) – Sundeep Kumar Mar 25 at 10:42
0

Truffle is right here, you cannot deploy abstract smart contract. You even cannot compile it into byte code: solidity compiler outputs empty byte code for abstract contracts.

Just get some non-abstract contract and deploy it. If you need simple ERC20 token smart contract to play with, try this one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.