alloy-rs/core

[Bug] Error when using sol! to parse a Solidity file

Closed this issue ยท 4 comments

Component

sol! macro

What version of Alloy are you on?

v0.7.4

Operating System

macOS (Apple Silicon)

Describe the bug

From the docs, I understand that I should be able to use the sol! macro like this as well: sol!(Erc20, "../examples/erc20/src/test.sol");

Screenshot 2024-05-27 at 13 12 11

However, when I try to do that, I get a "names are not allowed outside of JSON ABI" error, which comes from

let msg = "names are not allowed outside of JSON ABI";

when importing .sol files, there's no need for a name, as the name will be picked up from the contract MyContract definition in the solidity file. Given a file may contain multiple contract _____ definitions, renaming by adding a name there would also be pretty unreliable. So for those reasons, solidity files can only be imported without a name

The following should work for you:

sol!("../examples/erc20/src/test.sol");

Gotcha, makes sense. Maybe update the error message with a suggestion?

Also, I'm guessing if you wanted rpc calls you just do:

sol!(
  #[sol(rpc)]
  "../examples/erc20/src/test.sol"
);

Feel free to close ๐Ÿ‘

yes, I think the invocation with #[sol(rpc)] will work as exepcted