fragments.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /**
  2. * A fragment is a single item from an ABI, which may represent any of:
  3. *
  4. * - [Functions](FunctionFragment)
  5. * - [Events](EventFragment)
  6. * - [Constructors](ConstructorFragment)
  7. * - Custom [Errors](ErrorFragment)
  8. * - [Fallback or Receive](FallbackFragment) functions
  9. *
  10. * @_subsection api/abi/abi-coder:Fragments [about-fragments]
  11. */
  12. /**
  13. * A Type description in a [JSON ABI format](link-solc-jsonabi).
  14. */
  15. export interface JsonFragmentType {
  16. /**
  17. * The parameter name.
  18. */
  19. readonly name?: string;
  20. /**
  21. * If the parameter is indexed.
  22. */
  23. readonly indexed?: boolean;
  24. /**
  25. * The type of the parameter.
  26. */
  27. readonly type?: string;
  28. /**
  29. * The internal Solidity type.
  30. */
  31. readonly internalType?: string;
  32. /**
  33. * The components for a tuple.
  34. */
  35. readonly components?: ReadonlyArray<JsonFragmentType>;
  36. }
  37. /**
  38. * A fragment for a method, event or error in a [JSON ABI format](link-solc-jsonabi).
  39. */
  40. export interface JsonFragment {
  41. /**
  42. * The name of the error, event, function, etc.
  43. */
  44. readonly name?: string;
  45. /**
  46. * The type of the fragment (e.g. ``event``, ``"function"``, etc.)
  47. */
  48. readonly type?: string;
  49. /**
  50. * If the event is anonymous.
  51. */
  52. readonly anonymous?: boolean;
  53. /**
  54. * If the function is payable.
  55. */
  56. readonly payable?: boolean;
  57. /**
  58. * If the function is constant.
  59. */
  60. readonly constant?: boolean;
  61. /**
  62. * The mutability state of the function.
  63. */
  64. readonly stateMutability?: string;
  65. /**
  66. * The input parameters.
  67. */
  68. readonly inputs?: ReadonlyArray<JsonFragmentType>;
  69. /**
  70. * The output parameters.
  71. */
  72. readonly outputs?: ReadonlyArray<JsonFragmentType>;
  73. /**
  74. * The gas limit to use when sending a transaction for this function.
  75. */
  76. readonly gas?: string;
  77. }
  78. /**
  79. * The format to serialize the output as.
  80. *
  81. * **``"sighash"``** - the bare formatting, used to compute the selector
  82. * or topic hash; this format cannot be reversed (as it discards ``indexed``)
  83. * so cannot by used to export an [[Interface]].
  84. *
  85. * **``"minimal"``** - Human-Readable ABI with minimal spacing and without
  86. * names, so it is compact, but will result in Result objects that cannot
  87. * be accessed by name.
  88. *
  89. * **``"full"``** - Full Human-Readable ABI, with readable spacing and names
  90. * intact; this is generally the recommended format.
  91. *
  92. * **``"json"``** - The [JSON ABI format](link-solc-jsonabi).
  93. */
  94. export type FormatType = "sighash" | "minimal" | "full" | "json";
  95. /**
  96. * When [walking](ParamType-walk) a [[ParamType]], this is called
  97. * on each component.
  98. */
  99. export type ParamTypeWalkFunc = (type: string, value: any) => any;
  100. /**
  101. * When [walking asynchronously](ParamType-walkAsync) a [[ParamType]],
  102. * this is called on each component.
  103. */
  104. export type ParamTypeWalkAsyncFunc = (type: string, value: any) => any | Promise<any>;
  105. /**
  106. * Each input and output of a [[Fragment]] is an Array of **ParamType**.
  107. */
  108. export declare class ParamType {
  109. #private;
  110. /**
  111. * The local name of the parameter (or ``""`` if unbound)
  112. */
  113. readonly name: string;
  114. /**
  115. * The fully qualified type (e.g. ``"address"``, ``"tuple(address)"``,
  116. * ``"uint256[3][]"``)
  117. */
  118. readonly type: string;
  119. /**
  120. * The base type (e.g. ``"address"``, ``"tuple"``, ``"array"``)
  121. */
  122. readonly baseType: string;
  123. /**
  124. * True if the parameters is indexed.
  125. *
  126. * For non-indexable types this is ``null``.
  127. */
  128. readonly indexed: null | boolean;
  129. /**
  130. * The components for the tuple.
  131. *
  132. * For non-tuple types this is ``null``.
  133. */
  134. readonly components: null | ReadonlyArray<ParamType>;
  135. /**
  136. * The array length, or ``-1`` for dynamic-lengthed arrays.
  137. *
  138. * For non-array types this is ``null``.
  139. */
  140. readonly arrayLength: null | number;
  141. /**
  142. * The type of each child in the array.
  143. *
  144. * For non-array types this is ``null``.
  145. */
  146. readonly arrayChildren: null | ParamType;
  147. /**
  148. * @private
  149. */
  150. constructor(guard: any, name: string, type: string, baseType: string, indexed: null | boolean, components: null | ReadonlyArray<ParamType>, arrayLength: null | number, arrayChildren: null | ParamType);
  151. /**
  152. * Return a string representation of this type.
  153. *
  154. * For example,
  155. *
  156. * ``sighash" => "(uint256,address)"``
  157. *
  158. * ``"minimal" => "tuple(uint256,address) indexed"``
  159. *
  160. * ``"full" => "tuple(uint256 foo, address bar) indexed baz"``
  161. */
  162. format(format?: FormatType): string;
  163. /**
  164. * Returns true if %%this%% is an Array type.
  165. *
  166. * This provides a type gaurd ensuring that [[arrayChildren]]
  167. * and [[arrayLength]] are non-null.
  168. */
  169. isArray(): this is (ParamType & {
  170. arrayChildren: ParamType;
  171. arrayLength: number;
  172. });
  173. /**
  174. * Returns true if %%this%% is a Tuple type.
  175. *
  176. * This provides a type gaurd ensuring that [[components]]
  177. * is non-null.
  178. */
  179. isTuple(): this is (ParamType & {
  180. components: ReadonlyArray<ParamType>;
  181. });
  182. /**
  183. * Returns true if %%this%% is an Indexable type.
  184. *
  185. * This provides a type gaurd ensuring that [[indexed]]
  186. * is non-null.
  187. */
  188. isIndexable(): this is (ParamType & {
  189. indexed: boolean;
  190. });
  191. /**
  192. * Walks the **ParamType** with %%value%%, calling %%process%%
  193. * on each type, destructing the %%value%% recursively.
  194. */
  195. walk(value: any, process: ParamTypeWalkFunc): any;
  196. /**
  197. * Walks the **ParamType** with %%value%%, asynchronously calling
  198. * %%process%% on each type, destructing the %%value%% recursively.
  199. *
  200. * This can be used to resolve ENS names by walking and resolving each
  201. * ``"address"`` type.
  202. */
  203. walkAsync(value: any, process: ParamTypeWalkAsyncFunc): Promise<any>;
  204. /**
  205. * Creates a new **ParamType** for %%obj%%.
  206. *
  207. * If %%allowIndexed%% then the ``indexed`` keyword is permitted,
  208. * otherwise the ``indexed`` keyword will throw an error.
  209. */
  210. static from(obj: any, allowIndexed?: boolean): ParamType;
  211. /**
  212. * Returns true if %%value%% is a **ParamType**.
  213. */
  214. static isParamType(value: any): value is ParamType;
  215. }
  216. /**
  217. * The type of a [[Fragment]].
  218. */
  219. export type FragmentType = "constructor" | "error" | "event" | "fallback" | "function" | "struct";
  220. /**
  221. * An abstract class to represent An individual fragment from a parse ABI.
  222. */
  223. export declare abstract class Fragment {
  224. /**
  225. * The type of the fragment.
  226. */
  227. readonly type: FragmentType;
  228. /**
  229. * The inputs for the fragment.
  230. */
  231. readonly inputs: ReadonlyArray<ParamType>;
  232. /**
  233. * @private
  234. */
  235. constructor(guard: any, type: FragmentType, inputs: ReadonlyArray<ParamType>);
  236. /**
  237. * Returns a string representation of this fragment as %%format%%.
  238. */
  239. abstract format(format?: FormatType): string;
  240. /**
  241. * Creates a new **Fragment** for %%obj%%, wich can be any supported
  242. * ABI frgament type.
  243. */
  244. static from(obj: any): Fragment;
  245. /**
  246. * Returns true if %%value%% is a [[ConstructorFragment]].
  247. */
  248. static isConstructor(value: any): value is ConstructorFragment;
  249. /**
  250. * Returns true if %%value%% is an [[ErrorFragment]].
  251. */
  252. static isError(value: any): value is ErrorFragment;
  253. /**
  254. * Returns true if %%value%% is an [[EventFragment]].
  255. */
  256. static isEvent(value: any): value is EventFragment;
  257. /**
  258. * Returns true if %%value%% is a [[FunctionFragment]].
  259. */
  260. static isFunction(value: any): value is FunctionFragment;
  261. /**
  262. * Returns true if %%value%% is a [[StructFragment]].
  263. */
  264. static isStruct(value: any): value is StructFragment;
  265. }
  266. /**
  267. * An abstract class to represent An individual fragment
  268. * which has a name from a parse ABI.
  269. */
  270. export declare abstract class NamedFragment extends Fragment {
  271. /**
  272. * The name of the fragment.
  273. */
  274. readonly name: string;
  275. /**
  276. * @private
  277. */
  278. constructor(guard: any, type: FragmentType, name: string, inputs: ReadonlyArray<ParamType>);
  279. }
  280. /**
  281. * A Fragment which represents a //Custom Error//.
  282. */
  283. export declare class ErrorFragment extends NamedFragment {
  284. /**
  285. * @private
  286. */
  287. constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>);
  288. /**
  289. * The Custom Error selector.
  290. */
  291. get selector(): string;
  292. /**
  293. * Returns a string representation of this fragment as %%format%%.
  294. */
  295. format(format?: FormatType): string;
  296. /**
  297. * Returns a new **ErrorFragment** for %%obj%%.
  298. */
  299. static from(obj: any): ErrorFragment;
  300. /**
  301. * Returns ``true`` and provides a type guard if %%value%% is an
  302. * **ErrorFragment**.
  303. */
  304. static isFragment(value: any): value is ErrorFragment;
  305. }
  306. /**
  307. * A Fragment which represents an Event.
  308. */
  309. export declare class EventFragment extends NamedFragment {
  310. /**
  311. * Whether this event is anonymous.
  312. */
  313. readonly anonymous: boolean;
  314. /**
  315. * @private
  316. */
  317. constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>, anonymous: boolean);
  318. /**
  319. * The Event topic hash.
  320. */
  321. get topicHash(): string;
  322. /**
  323. * Returns a string representation of this event as %%format%%.
  324. */
  325. format(format?: FormatType): string;
  326. /**
  327. * Return the topic hash for an event with %%name%% and %%params%%.
  328. */
  329. static getTopicHash(name: string, params?: Array<any>): string;
  330. /**
  331. * Returns a new **EventFragment** for %%obj%%.
  332. */
  333. static from(obj: any): EventFragment;
  334. /**
  335. * Returns ``true`` and provides a type guard if %%value%% is an
  336. * **EventFragment**.
  337. */
  338. static isFragment(value: any): value is EventFragment;
  339. }
  340. /**
  341. * A Fragment which represents a constructor.
  342. */
  343. export declare class ConstructorFragment extends Fragment {
  344. /**
  345. * Whether the constructor can receive an endowment.
  346. */
  347. readonly payable: boolean;
  348. /**
  349. * The recommended gas limit for deployment or ``null``.
  350. */
  351. readonly gas: null | bigint;
  352. /**
  353. * @private
  354. */
  355. constructor(guard: any, type: FragmentType, inputs: ReadonlyArray<ParamType>, payable: boolean, gas: null | bigint);
  356. /**
  357. * Returns a string representation of this constructor as %%format%%.
  358. */
  359. format(format?: FormatType): string;
  360. /**
  361. * Returns a new **ConstructorFragment** for %%obj%%.
  362. */
  363. static from(obj: any): ConstructorFragment;
  364. /**
  365. * Returns ``true`` and provides a type guard if %%value%% is a
  366. * **ConstructorFragment**.
  367. */
  368. static isFragment(value: any): value is ConstructorFragment;
  369. }
  370. /**
  371. * A Fragment which represents a method.
  372. */
  373. export declare class FallbackFragment extends Fragment {
  374. /**
  375. * If the function can be sent value during invocation.
  376. */
  377. readonly payable: boolean;
  378. constructor(guard: any, inputs: ReadonlyArray<ParamType>, payable: boolean);
  379. /**
  380. * Returns a string representation of this fallback as %%format%%.
  381. */
  382. format(format?: FormatType): string;
  383. /**
  384. * Returns a new **FallbackFragment** for %%obj%%.
  385. */
  386. static from(obj: any): FallbackFragment;
  387. /**
  388. * Returns ``true`` and provides a type guard if %%value%% is a
  389. * **FallbackFragment**.
  390. */
  391. static isFragment(value: any): value is FallbackFragment;
  392. }
  393. /**
  394. * A Fragment which represents a method.
  395. */
  396. export declare class FunctionFragment extends NamedFragment {
  397. /**
  398. * If the function is constant (e.g. ``pure`` or ``view`` functions).
  399. */
  400. readonly constant: boolean;
  401. /**
  402. * The returned types for the result of calling this function.
  403. */
  404. readonly outputs: ReadonlyArray<ParamType>;
  405. /**
  406. * The state mutability (e.g. ``payable``, ``nonpayable``, ``view``
  407. * or ``pure``)
  408. */
  409. readonly stateMutability: "payable" | "nonpayable" | "view" | "pure";
  410. /**
  411. * If the function can be sent value during invocation.
  412. */
  413. readonly payable: boolean;
  414. /**
  415. * The recommended gas limit to send when calling this function.
  416. */
  417. readonly gas: null | bigint;
  418. /**
  419. * @private
  420. */
  421. constructor(guard: any, name: string, stateMutability: "payable" | "nonpayable" | "view" | "pure", inputs: ReadonlyArray<ParamType>, outputs: ReadonlyArray<ParamType>, gas: null | bigint);
  422. /**
  423. * The Function selector.
  424. */
  425. get selector(): string;
  426. /**
  427. * Returns a string representation of this function as %%format%%.
  428. */
  429. format(format?: FormatType): string;
  430. /**
  431. * Return the selector for a function with %%name%% and %%params%%.
  432. */
  433. static getSelector(name: string, params?: Array<any>): string;
  434. /**
  435. * Returns a new **FunctionFragment** for %%obj%%.
  436. */
  437. static from(obj: any): FunctionFragment;
  438. /**
  439. * Returns ``true`` and provides a type guard if %%value%% is a
  440. * **FunctionFragment**.
  441. */
  442. static isFragment(value: any): value is FunctionFragment;
  443. }
  444. /**
  445. * A Fragment which represents a structure.
  446. */
  447. export declare class StructFragment extends NamedFragment {
  448. /**
  449. * @private
  450. */
  451. constructor(guard: any, name: string, inputs: ReadonlyArray<ParamType>);
  452. /**
  453. * Returns a string representation of this struct as %%format%%.
  454. */
  455. format(): string;
  456. /**
  457. * Returns a new **StructFragment** for %%obj%%.
  458. */
  459. static from(obj: any): StructFragment;
  460. /**
  461. * Returns ``true`` and provides a type guard if %%value%% is a
  462. * **StructFragment**.
  463. */
  464. static isFragment(value: any): value is FunctionFragment;
  465. }
  466. //# sourceMappingURL=fragments.d.ts.map