Fragments
Formats
JSON String ABI (Solidity Output JSON)
The JSON ABI Format is the format that is output from the Solidity compiler.
A JSON serialized object is always a string, which represents an Array of Objects, where each Object has various properties describing the Fragment of the ABI.
The deserialized JSON string (which is a normal JavaScript Object) may also be passed into any function which accepts a JSON String ABI.
Human-Readable ABI
The ABI is described by using an array of strings, where each string is the Solidity signature of the constructor, function, event or error.
When parsing a fragment, all inferred properties will be injected (e.g. a payable method will have its constant property set to false).
Tuples can be specified by using the tuple(...) syntax or with bare (additional) parenthesis, (...).
const ABI = [
// Constructor
"constructor(address ens)",
// Constant functions (pure or view)
"function balanceOf(address owner) view returns (uint)",
// State-mutating functions (payable or non-payable)
"function mint(uint amount) payable",
"function transfer(address to, uint amount) returns (bool)",
// Events
"event Transfer(address indexed from, address indexed to, uint amount)",
// Errors
"error InsufficientFunds(address from, uint balance)",
]Output Formats
Each Fragment and ParamType may be output using its format method.
hethers.utils.FormatTypes.full ⇒ string
hethers.utils.FormatTypes.full ⇒ stringThis is a full human-readable string, including all parameter names, any optional modifiers (e.g. indexed, public, etc) and white-space to aid in human readability.
hethers.utils.FormatTypes.minimal ⇒ string
hethers.utils.FormatTypes.minimal ⇒ stringThis is similar to full, except with no unnecessary whitespace or parameter names. This is useful for storing a minimal string which can still fully reconstruct the original Fragment using Fragment from.
hethers.utils.FormatTypes.json ⇒ string
hethers.utils.FormatTypes.json ⇒ stringThis returns a JavaScript Object which is safe to call JSON.stringify on to create a JSON string.
hethers.utils.FormatTypes.sighash ⇒ string
hethers.utils.FormatTypes.sighash ⇒ stringThis is a minimal output format, which is used by Solidity when computing a signature hash or an event topic hash.
Fragment
An ABI is a collection of Fragments, where each fragment specifies:
Properties
fragment.name ⇒ string
fragment.name ⇒ stringThis is the name of the Event or Function. This will be null for a ConstructorFragment.
fragment.type ⇒ string
fragment.type ⇒ stringThis is a string which indicates the type of the Fragment. This will be one of:
constructoreventfunction
This is an array of each ParamType for the input parameters to the Constructor, Event of Function.
Methods
fragment.format( [ format = sighash ] ) ⇒ string
fragment.format( [ format = sighash ] ) ⇒ stringCreates a string representation of the Fragment using the available output formats.
Creates a new Fragment sub-class from any compatible objectOrString.
hethers.utils.Fragment.isFragment( object ) ⇒ boolean
hethers.utils.Fragment.isFragment( object ) ⇒ booleanReturns true if object is a Fragment.
ConstructorFragment (inherits Fragment)
Properties
This is the gas limit that should be used during deployment. It may be null.
fragment.payable ⇒ boolean
fragment.payable ⇒ booleanThis is whether the constructor may receive ether during deployment as an endowment (i.e. msg.value != 0).
fragment.stateMutability ⇒ string
fragment.stateMutability ⇒ stringThis is the state mutability of the constructor. It can be any of:
nonpayablepayable
Methods
Creates a new ConstructorFragment from any compatible objectOrString.
hethers.utils.ConstructorFragment.isConstructorFragment( object ) ⇒ boolean
hethers.utils.ConstructorFragment.isConstructorFragment( object ) ⇒ booleanReturns true if object is a ConstructorFragment.
ErrorFragment (inherits Fragment)
Methods
Creates a new ErrorFragment from any compatible objectOrString.
hethers.utils.ErrorFragment.isErrorFragment( object ) ⇒ boolean
hethers.utils.ErrorFragment.isErrorFragment( object ) ⇒ booleanReturns true if object is an ErrorFragment.
EventFragment (inherits Fragment)
Properties
fragment.anonymous ⇒ boolean
fragment.anonymous ⇒ booleanThis is whether the event is anonymous. An anonymous Event does not inject its topic hash as topic0 when creating a log.
Methods
hethers.utils.EventFragment.from( objectOrString ) ⇒ EventFragment
hethers.utils.EventFragment.from( objectOrString ) ⇒ EventFragmentCreates a new EventFragment from any compatible objectOrString.
hethers.utils.EventFragment.isEventFragment( object ) ⇒ boolean
hethers.utils.EventFragment.isEventFragment( object ) ⇒ booleanReturns true if object is an EventFragment.
FunctionFragment (inherits ConstructorFragment)
Properties
fragment.constant ⇒ boolean
fragment.constant ⇒ booleanThis is whether the function is constant (i.e. does not change state). This is true if the state mutability is pure or view.
fragment.stateMutability ⇒ string
fragment.stateMutability ⇒ stringThis is the state mutability of the constructor. It can be any of:
nonpayablepayablepureview
fragment.outputs ⇒ Array<ParamType>
fragment.outputs ⇒ Array<ParamType>A list of the Function output parameters.
Methods
Creates a new FunctionFragment from any compatible objectOrString.
hethers.utils.FunctionFragment.isFunctionFragment( object ) ⇒ boolean
hethers.utils.FunctionFragment.isFunctionFragment( object ) ⇒ booleanReturns true if object is a FunctionFragment.
ParamType
The following examples will represent the Solidity parameter:
string foobar
Properties
paramType.name ⇒ string
paramType.name ⇒ stringThe local parameter name. This may be null for unnamed parameters. For example, the parameter definition string foobar would be foobar.
paramType.type ⇒ string
paramType.type ⇒ stringThe full type of the parameter, including tuple and array symbols. This may be null for unnamed parameters. For the above example, this would be foobar.
paramType.baseType ⇒ string
paramType.baseType ⇒ stringThe base type of the parameter. For primitive types (e.g. address, uint256, etc) this is equal to type. For arrays, it will be the string array and for a tuple, it will be the string tuple.
paramType.indexed ⇒ boolean
paramType.indexed ⇒ booleanWhether the parameter has been marked as indexed. This only applies to parameters which are part of an EventFragment.
paramType.arrayChildren ⇒ ParamType
paramType.arrayChildren ⇒ ParamTypeThe type of children of the array. This is null for any parameter which is not an array.
paramType.arrayLength ⇒ number
paramType.arrayLength ⇒ numberThe length of the array, or -1 for dynamic-length arrays. This is null for parameters which are not arrays.
paramType.components ⇒ Array<ParamType>
paramType.components ⇒ Array<ParamType>The components of a tuple. This is null for non-tuple parameters.
Methods
paramType.format( [ outputType = sighash ] )
paramType.format( [ outputType = sighash ] )Creates a string representation of the Fragment using the available output formats.
hethers.utils.ParamType.from( objectOrString ) ⇒ ParamType
hethers.utils.ParamType.from( objectOrString ) ⇒ ParamTypeCreates a new ParamType from any compatible objectOrString.
hethers.utils.ParamType.isParamType( object ) ⇒ boolean
hethers.utils.ParamType.isParamType( object ) ⇒ booleanReturns true if object is a ParamType.
Last updated