Package: ape-solidity
Quick StartCompile Solidity contracts.Dependenciespython3version 3.8 up to 3.11.InstallationviapipYou can install the latest release viapip:pipinstallape-solidityviasetuptoolsYou can clone the repository and usesetuptoolsfor the most up-to-date version:gitclonehttps://github.com/ApeWorX/ape-solidity.gitcdape-solidity
python3setup.pyinstallQuick UsageIn your project, make sure you have acontracts/directory containing Solidity files (.sol).Then, while this plugin is installed, compile your contracts:apecompileThe byte-code and ABI for your contracts should now exist in a__local__.jsonfile in a.build/directory.Solidity VersioningBy default,ape-soliditytries to use the best versions of Solidity by looking at all the source files' pragma specifications.
However, it is often better to specify a version directly.
If you know the best version to use, set it in yourape-config.yaml, like this:solidity:version:0.8.14EVM VersioningBy default,ape-soliditywill use whatever version of EVM rules are set as default in the compiler version that gets used.
Sometimes, you might want to use a different version, such as deploying on Arbitrum or Optimism where new opcodes are not supported yet.
If you want to require a different version of EVM rules to use in the configuration of the compiler, set it in yourape-config.yamllike this:solidity:evm_version:parisDependency MappingTo configure import remapping, use your project'sape-config.yamlfile:solidity:import_remapping:-"@openzeppelin=path/to/open_zeppelin/contracts"If you are using thedependencies:key in yourape-config.yaml,apecan automatically
search those dependencies for the path.dependencies:-name:OpenZeppelingithub:OpenZeppelin/openzeppelin-contractsversion:4.4.2solidity:import_remapping:-"@openzeppelin=OpenZeppelin/4.4.2"Once you have your dependencies configured, you can import packages using your import keys:import"@openzeppelin/token/ERC721/ERC721.sol";Library LinkingTo compile contracts that use libraries, you need to add the libraries first.
Use theadd_library()method from theape-soliditycompiler class to add the library.
A typical flow is:Deploy the library.Calladd_library()using the Solidity compiler plugin, which will also re-compile contracts that need the library.Deploy and use contracts that require the library.For example:importpytest@pytest.fixturedefcontract(accounts,project,compilers):# Deploy the library.account=accounts[0]library=project.Set.deploy(sender=account)# Add the library to Solidity (re-compiles contracts that use the library).compilers.solidity.add_library(library)# Deploy the contract that uses the library.returnproject.C.deploy(sender=account)Compiler SettingsWhen usingape-solidity, your project's manifest's compiler settings will include standard JSON output.
You should have one listedcompilerpersolcversion used in your project.
You can view your current project manifest, including the compiler settings, by doing:fromapeimportprojectmanifest=project.extract_manifest()forcompiler_entryinmanifest.compilers:print(compiler_entry.version)print(compiler_entry.settings)NOTE: These are the settings used during contract verification when using theEtherscan plugin.--via-IRYul IR Compilation PipelineYou can enablesolc's--via-IRflag by adding the following values to yourape-config.yamlsolidity:via_ir:True