I've been reading as much around this as possible, but cannot verify a contract which relies on openzeppelin imports, because the compiled bytecode differs from the deployed bytecode.
All compiled and deployed with hardhat, solc 0.8.0
1: a contract was compiled and deployed to rinkeby and mainnet, while there were other contracts (i.e. a backup version of the main contract) in the same project.
2: I did not verify the contract immediately (silly I know)
3: some small changes are made to the non-dependent files in the same project (i.e. backup .sol files are renamed and replaced with the deployed contract)
4: Trying to verify the deployed contract some days later fails (following @abcoathup 's tutorial using hardhat-etherscan, and via direct verification on etherscan with flattened contract)
I have read and used this guide (thanks for writing it!)
I have tried directly verifying on etherscan, with a flattened contract (manually copied all dependencies into the same Contract.sol)
I have tried the hardhat-etherscan method:
npx hardhat verify --network network contractAddress constructorArgs)
In all attempts I get the same error:
"Error in plugin @nomiclabs/hardhat-etherscan: The address provided as argument contains a contract, but its bytecode doesn't match any of your local contracts. Possible causes are: - Contract code changed after the deployment was executed. This includes code for seemingly unrelated contracts. - A solidity file was added, moved, deleted or renamed after the deployment was executed. This includes files for seemingly unrelated contracts. - Solidity compiler settings were modified after the deployment was executed (like the optimizer, target EVM, etc.). - The given address is wrong. - The selected network (mainnet) is wrong."
Or from etherscan:
unable to find a matching bytecode
So my question is: does the state of the project directory at compile/deployment (i.e. the existence of other .sol files) affect the deployed bytecode for a contract?
If so, is it impossible to reproduce the same bytecode for verification if the non-dependent file structure or non-dependent file names have changed?
I'm beginning to tear my hair out over this one - any help would be really appreciated!