Support multi file verification on Etherscan
See original GitHub issueFeature Request
Support multi file verification on Etherscan using Truffle.
This is instead of flattening contracts.
Flattened contracts:
- Can only contain one SPDX License Identifier (introduced in Solidity 0.6.8) per file. Risking license identifiers being removed, especially from third party libraries.
- Remove import statements, making it harder to identify how contracts have been imported and from what sources such as an installed npm package
- Generally harder to ready and identify any inheritance used, including third party libraries such as OpenZeppelin Contracts.
Steps to Reproduce
Verify the following contract inheriting from OpenZeppelin Contracts v3.2.0
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `ERC20` functions.
*/
contract SimpleToken is ERC20 {
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor() public ERC20("Simple Token", "SIM") {
_mint(msg.sender, 100000000 * (10**uint256(decimals())));
}
}
Ideal Behavior
Ideally the contract would be verified as multiple files. The following example shows the six files that make up the contract: https://rinkeby.etherscan.io/address/0x3fFfF0a40E2E3152ab35D78cC49218dD2C35c6cc#code
The contract was verified using https://github.com/nomiclabs/buidler/tree/development/packages/buidler-etherscan which ideally there would be a Truffle plugin that supports multi file verification.
Actual Results
https://github.com/rkalis/truffle-plugin-verify flattens the contracts, removes SPDX License Identifiers and replaces with a single SPDX License Identifier and removes imports so that the contract can compile.
The following example shows a single flattened file for the contract: https://rinkeby.etherscan.io/address/0x5D226974f9ce71179a68B8EDcC7EeE99df8FC3C5#code
Environment
- Operating System: WSL2 Ubuntu 18.0.4
- Truffle version:
$ npx truffle version
Truffle v5.1.44 (core: 5.1.44)
Solidity - 0.6.12 (solc-js)
Node v10.21.0
Web3.js v1.2.1
First raised in Truffle: https://github.com/trufflesuite/truffle/issues/3366
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (11 by maintainers)

Top Related StackOverflow Question
I tried to do this today, but I ran into some issues in the step “compute the artifact path for this source path”, since it’s pretty difficult to find out the artifact file(s) corresponding to a Solidity file, since a file can include one or more contracts with different names. I think for now I’ll publish the multi file verification with the alphabetical file order soon (rather than the “intuitive” file order) and make an issue of fixing the file order in the future.
I just published the new release without the “intuitive” file order. I will close this issue, and create a new one to try to achieve a better ordering.