Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

No Bytecode Generated for Compiled Contract #2951

Closed
mudgen opened this issue Apr 13, 2020 · 3 comments
Closed

No Bytecode Generated for Compiled Contract #2951

mudgen opened this issue Apr 13, 2020 · 3 comments

Comments

@mudgen
Copy link

mudgen commented Apr 13, 2020

Issue

The command truffle compile will fail to generate the bytecode in .json files for contracts that have their interface defined in other contracts that are also being compiled.

Steps to Reproduce

Step 1. Create two very simple contracts. Let's call them TestA.sol and TestB.sol.
Step 2. TestB.sol contains an interface definition of the TestA.sol contract.

Here is what TestA.sol looks like:

pragma solidity ^0.6.2;

contract TestA {
    function doSomething() external pure returns (address) {
        return address(0);
    }
}

Here is what TestB.sol looks like:

pragma solidity ^0.6.2;

interface TestA {
    function doSomething() external pure returns (address);
}

contract TestB {
    function get_id() public pure returns (uint256) {
        return 25;
    }
}

Step 3. Put these two contracts in a directory called "contracts". Then execute "truffle compile".

Step 4. Look at the generated bytecode for contract TestA.json that should exist in the TestA.json file. It does not exist. Here is a screenshot:

no bytecode

Expected Behavior

I expected the bytecode for contract TestA.sol to be in TestA.json.

Actual Results

The bytecode for TestA.sol was missing in TestA.json.

Perhaps TestA.json was created for the interface rather than the contract. I think it should be the other way around.

Environment

  • Windows 10
  • Truffle v5.1.21 (core: 5.1.21)
  • Solidity - 0.6.2 (solc-js)
  • Node v10.18.1
  • Web3.js v1.2.
@gnidan
Copy link
Contributor

gnidan commented Apr 13, 2020

Looks like #1087 strikes again!

Sorry for the inconvenience; Truffle has a long-standing limitation that prevents having two contracts with the same name.

Closing this as duplicate, but thank you for reminding me that this issue is really freakin' annoying ;)

@gnidan gnidan closed this as completed Apr 13, 2020
@mudgen
Copy link
Author

mudgen commented Apr 14, 2020

Okay, thanks!

This version of the problem might be easier to solve than contracts overwriting contracts. In my use cases it is more "okay" for a contract to overwrite an interface, since I am not going to deploy an interface.

Having an interface that overwrites the bytecode of a contract seems like a more subtle problem. For a long time I didn't know why my contract compiled and had no bytecode. I just thought truffle was broken.

My workaround was to install an earlier version of truffle: Truffle v5.1.21
With this version I could compile a couple times and it would work. With the current version of truffle this doesn't work.

@gnidan
Copy link
Contributor

gnidan commented Apr 14, 2020

Interesting @mudgen.

There might be a workaround here, to omit artifacts for interfaces. If you'd like to take a look at doing this, would love a PR! (Or maybe just open an issue for that specific task)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants