rexdavinci / browser-solidity-compiler

18 stars 7 forks source link

Compiling contracts with import #9

Open bahricanyesil opened 1 year ago

bahricanyesil commented 1 year ago

How can I compile a smart contract which imports other files or packages?

For example: "import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"

ashwwwin commented 9 months ago

Hey @bahricanyesil, wondering if you've figured this out

Any ideas @nikola-bozin-org?

nikola-bozin-org commented 9 months ago

You would need to use contract-flattener/solidity-flattener and than import that whole flattened/solidity-contract for compilation.

nikola-bozin-org commented 9 months ago

Quick note, there are no client-side contract-flattener's as of my knowledge. You would have to do it manually or make your script.

if you have for example contract1 = ... and contract2 = ... but contract 2 imports contract1, you would just do this: contract2.replace('import "./Contract1.sol";',contract1). But also make sure to exclude first two lines for licence and solidity version from atlest one contract.

Ofc, this is a quick solution, but a more robust solution is required if dealing with more complex contracts.

ashwwwin commented 9 months ago

I see, thank you for the extra info :)

bahricanyesil commented 9 months ago

Hey @bahricanyesil, wondering if you've figured this out

Any ideas @nikola-bozin-org?

As @nikola-bozin-org said, I've replaced the import statements with the actual contract codes.