book icon indicating copy to clipboard operation
book copied to clipboard

Add example using OZ contracts in VSCode

Open alexbakers opened this issue 1 year ago • 3 comments

https://github.com/foundry-rs/foundry/issues/2019

alexbakers avatar Jul 21 '22 19:07 alexbakers

Can you add more context to the example? I.e. explain what the solution is doing/what the problem is (you did that a bit in your linked comment) so it is easier to reproduce for project structures that do not follow the example exactly

onbjerg avatar Jul 21 '22 20:07 onbjerg

I wanted to show an example of usage solidity.remappings settings.

{
  "solidity.remappings": [
    "@openzeppelin/=packages/contracts/lib/openzeppelin-contracts/",
    "ds-test/=packages/contracts/lib/forge-std/lib/ds-test/src/",
    "forge-std/=packages/contracts/lib/forge-std/src/"
  ],
  "solidity.packageDefaultDependenciesDirectory": "lib",
  "solidity.packageDefaultDependenciesContractsDirectory": "src",
}

The documentation indicates that for a non-standard project layout you need to change solidity.packageDefaultDependenciesDirectory and solidity.packageDefaultDependenciesContractsDirectory. However, if solidity.remappings is configured correctly, these parameters do not affect anything. The import works equally well in both cases. Even if it's empty.

{
  "solidity.remappings": [
    "@openzeppelin/=packages/contracts/lib/openzeppelin-contracts/",
    "ds-test/=packages/contracts/lib/forge-std/lib/ds-test/src/",
    "forge-std/=packages/contracts/lib/forge-std/src/"
  ],
  "solidity.packageDefaultDependenciesDirectory": "",
  "solidity.packageDefaultDependenciesContractsDirectory": "",
}

https://ethereum.stackexchange.com/questions/126469/importing-openzeppelin-contracts-in-foundry I was looking for an answer to this question, and I wish it was in the documentation. If you think this is redundant information, I don't mind.

Thank you.

alexbakers avatar Jul 21 '22 21:07 alexbakers

Nono, I think it's fine - I was just asking for you to add some more context to the document itself so others can reproduce it for project layouts that do not necessarily match the example :) Imo there is more context in the original comment you posted in the other repository and some of that would be good here as well.

onbjerg avatar Jul 22 '22 16:07 onbjerg