ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

Json Formatter does not include "name" property if empty in the original abi fragment

Open zemse opened this issue 2 years ago • 0 comments

Ethers Version

5.6.9

Search Terms

abi, json, fragment

Describe the Problem

If name is empty string, then it is not included in the .format('json') output.

The ABI spec in the solidity docs (link) does not say that name can be optional and hence tools expect the name property to be present.

Why ethers's .format('json') should conform to that? Once an ethers.Contract is created, there is no way to directly get the raw ABI by solidity compiler as it is. If an ABI is required to be passed to another tool, one may simply use the .format('json') to generate the ABI for further passing to the other tool.

Code Snippet

// note that the following contains "name":""
fragment = JSON.parse('{"inputs":[],"name":"myMethod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}')

iface = new Interface([fragment])
iface.fragments[0].format('json')
// {"type":"function","name":"myMethod","constant":true,"stateMutability":"view","payable":false,"inputs":[],"outputs":[{"type":"uint256"}]}
// note that the result does not contain "name":""

Contract ABI

['function myMethod() view returns (uint)']
['{"inputs":[],"name":"myMethod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}']

Errors

No response

Environment

node.js (v12 or newer)

Environment (Other)

No response

zemse avatar Jul 26 '22 16:07 zemse