Skip to content

Misleading Error Message: Could not find target contract #7244

@timolson

Description

@timolson

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (ac80261 2024-02-24T00:17:06.154246094Z)

What command(s) is the bug in?

forge script

Operating System

Linux

Describe the bug

Running forge script MyDeployment.sol fails with the message Error: Could not find target contract MyDeployment even though the file is clearly present and the script contract name is correct.

In my case, the real bug was calling an external library method which had been accidentally marked public/external instead of internal, causing a dynamic linkage failure, and the message "Error: Could not find target contract"

You should be able to reproduce using a library Foo { function foo() public {} } along with a contract which calls Foo.foo() and finally a deployment script which constructs the contract that uses the external lib. If you change the visibility to internal, the static binding / inlining causes the "Could not find target contract" message to go away.

This is the same error message as reported in #3076 but presumably with a different cause/solution.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions