This function is similar to
[[Format.Utils.Inspect.unsafeNativize|unsafeNativize]], but is intended to
be safe, and also allows for different output formats. The only currently
supported format is "ethers", which is intended to match the way that
Truffle Contract currently returns values (based on the Ethers decoder). As
such, it only handles ABI types, and in addition does not handle the types
fixed, ufixed, or function. Note that in these cases it returns undefined
rather than throwing, as we want this function to be used in contexts where
it had better not throw. It also does not handle circularities, for similar
reasons.
To handle numeric types, this function takes an optional numberFormatter
option that tells it how to handle numbers; this function should take a
BigInt as input. By default, this function will be the identity, and so
numbers will be represented as BigInts.
Note that this function begins by calling abify, so out-of-range enums (that
aren't so out-of-range as to be padding errors) will not return undefined.
Out-of-range booleans similarly will return true rather than undefined.
However, other range errors may return undefined; this may technically be a
slight incompatibility with existing behavior, but should not be relevant
except in quite unusual cases.
In order to match the behavior for tuples, tuples will be transformed into
arrays, but named entries will additionally be keyed by name. Moreover,
indexed variables of reference type will be nativized to an undecoded hex
string.
This function is similar to [[Format.Utils.Inspect.unsafeNativize|unsafeNativize]], but is intended to be safe, and also allows for different output formats. The only currently supported format is "ethers", which is intended to match the way that Truffle Contract currently returns values (based on the Ethers decoder). As such, it only handles ABI types, and in addition does not handle the types fixed, ufixed, or function. Note that in these cases it returns
undefinedrather than throwing, as we want this function to be used in contexts where it had better not throw. It also does not handle circularities, for similar reasons.To handle numeric types, this function takes an optional numberFormatter option that tells it how to handle numbers; this function should take a BigInt as input. By default, this function will be the identity, and so numbers will be represented as BigInts.
Note that this function begins by calling abify, so out-of-range enums (that aren't so out-of-range as to be padding errors) will not return
undefined. Out-of-range booleans similarly will return true rather thanundefined. However, other range errors may returnundefined; this may technically be a slight incompatibility with existing behavior, but should not be relevant except in quite unusual cases.In order to match the behavior for tuples, tuples will be transformed into arrays, but named entries will additionally be keyed by name. Moreover, indexed variables of reference type will be nativized to an undecoded hex string.