This code works - taken from Wiki -

pragma solidity ^0.4.18;

contract ERC20Interface {
    function transfer(address to, uint tokens) public returns (bool success);


contract FixedSupplyToken is ERC20Interface {

    function transferAnyERC20Token(address tokenAddress, uint tokens) public  returns (bool success) {
        return ERC20Interface(tokenAddress).transfer(tokenAddress, tokens);

This code does not - fails on the deploy -

pragma solidity ^0.4.18;

contract d8 {
    function myBalance() public  returns (uint myNumber);


contract d15 is d8  {
    function getBalance(address addr)  public returns (uint myNumber) {
    return d8(addr).myBalance();

Can anyone see why the first one works and the second does not?

>   Replacing Migrations...   ...
> 0x43d0c7631ba73dfe0066f6d7101f5b1bce97d0af35f6c8b19f53c49991b3ae31  
> Migrations: 0x1fdad1a831e98a507541c3a3c12f0e5b5487e144 Saving
> successful migration to network...   ...
> 0xad2d902e40c3cdc80e84d08e6cf3af4529cd26a787e8d5b79157236ba1c6236e
> Saving artifacts... Running migration: 2_deploy_contracts.js  
> Deploying d15...   ...
> 0x555a8028d89388bd18d83af0ccefe5f6c88e375f0bbf1b4a43b370457f00cb93
> Error encountered, bailing. Network state unknown. Review successful
> transactions manually.

For x1 (first one) -

> Running migration: 1_initial_migration.js   Replacing Migrations...  
> ... 0xdc004595e2c2c566b1e10f5ff6a630cffdcf7d64a66a35e1c6f3173dd7143710
> Migrations: 0x20a04f7f8b64ecd154987cb47e10315f8309fb86 Saving
> successful migration to network...   ...
> 0xd105819a9c182415155e2e7999868eb0919fea3ea4bd8096a21d59a1aab9baf9
> Saving artifacts... Running migration: 2_deploy_contracts.js  
> Replacing x1...   ...
> 0x90b6d94d4013b69d7b2fbb25bc195ef5b1ca56ca7969ed33e3e20a8e0451a600  
> x1: 0xe2a7bacc61fc1cf994e1d5cc148cb95830ff843c Saving successful
> migration to network...   ...
> 0x7a6737f653ff9a82c5d28472d5a79764683c216bb31a395bbcc51102770b2f2e
> Saving artifacts...

You aren't trying to inherit the interface, you're just trying to use the interface. Just remove is d8 from the contract declaration.

  • That works but I want to test the example given for ERC20Interface. – Trevor Lee Oakley Mar 13 '18 at 14:55
  • The given example for ERC20Interface should fail as well. If you inherit an interface with unimplemented functions and don't implement them, then deployment will fail. – natewelch_ Mar 13 '18 at 14:58
  • It deploys. Maybe it fails when running it. I am using elimination to find out why one works and one does not. – Trevor Lee Oakley Mar 13 '18 at 14:59
  • The code extract I posted does deploy. – Trevor Lee Oakley Mar 13 '18 at 14:59
  • 1
    I found out what is happening. This is the way truffle works. I deployed the ERC20 once and then slowly eliminated lines. It kept deploying because the original once had worked. When I changed the filename on the sol file for the ERC20 it stopped deploying saying - Error: Could not find artifacts for ./x2 from any sources. I am unsure what that means but that is why I could deploy and you could not. – Trevor Lee Oakley Mar 13 '18 at 15:35

As of Solidity version 0.5.10,

Contracts can inherit interfaces as they would inherit other contracts.

See the docs.

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.