Currently, in the Sourcify ABI Loader, the contract name is retrieved from the Natspec comments (i.e., devdoc.title). However, if the contract name is missing in the Natspec comments, no fallback is provided, which results in the contract name being null. I propose adding a fallback mechanism to retrieve the contract name from the compiler settings' compilationTarget if it's not available in the Natspec comments.
// Note: Sometimes metadata.json contains sources, but not always. So we can't rely on just the metadata.json
const m = JSON.parse(metadata.content);
+ // Sourcify includes a title from the Natspec comments
+ let name = m.output.devdoc?.title;
+
+ if (!name && m.settings.compilationTarget) {
+ // Try to use the compilation target name as a fallback
+ const targetNames = Object.values(m.settings.compilationTarget);
+ if (targetNames.length > 0) {
+ name = targetNames[0];
+ }
+ }
+
return {
abi: m.output.abi,
- name: m.output.devdoc?.title ?? null, // Sourcify includes a title from the Natspec comments
+ name: name ?? null,
evmVersion: m.settings.evmVersion,
compilerVersion: m.compiler.version,
runs: m.settings.optimizer.runs,
If this feature request is accepted, I will be happy to open a pull request implementing the above change.
Currently, in the Sourcify ABI Loader, the contract name is retrieved from the Natspec comments (i.e.,
devdoc.title
). However, if the contract name is missing in the Natspec comments, no fallback is provided, which results in the contract name being null. I propose adding a fallback mechanism to retrieve the contract name from the compiler settings'compilationTarget
if it's not available in the Natspec comments.https://github.com/shazow/whatsabi/blob/7e9d811679cb4b296fd29491c0929a7b05f1a301/src/loaders.ts#L252-L268
Proposed Change:
If this feature request is accepted, I will be happy to open a pull request implementing the above change.