transaction.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. import { Signature } from "../crypto/index.js";
  2. import type { BigNumberish, BytesLike } from "../utils/index.js";
  3. import type { SignatureLike } from "../crypto/index.js";
  4. import type { AccessList, AccessListish } from "./index.js";
  5. /**
  6. * A **TransactionLike** is an object which is appropriate as a loose
  7. * input for many operations which will populate missing properties of
  8. * a transaction.
  9. */
  10. export interface TransactionLike<A = string> {
  11. /**
  12. * The type.
  13. */
  14. type?: null | number;
  15. /**
  16. * The recipient address or ``null`` for an ``init`` transaction.
  17. */
  18. to?: null | A;
  19. /**
  20. * The sender.
  21. */
  22. from?: null | A;
  23. /**
  24. * The nonce.
  25. */
  26. nonce?: null | number;
  27. /**
  28. * The maximum amount of gas that can be used.
  29. */
  30. gasLimit?: null | BigNumberish;
  31. /**
  32. * The gas price for legacy and berlin transactions.
  33. */
  34. gasPrice?: null | BigNumberish;
  35. /**
  36. * The maximum priority fee per gas for london transactions.
  37. */
  38. maxPriorityFeePerGas?: null | BigNumberish;
  39. /**
  40. * The maximum total fee per gas for london transactions.
  41. */
  42. maxFeePerGas?: null | BigNumberish;
  43. /**
  44. * The data.
  45. */
  46. data?: null | string;
  47. /**
  48. * The value (in wei) to send.
  49. */
  50. value?: null | BigNumberish;
  51. /**
  52. * The chain ID the transaction is valid on.
  53. */
  54. chainId?: null | BigNumberish;
  55. /**
  56. * The transaction hash.
  57. */
  58. hash?: null | string;
  59. /**
  60. * The signature provided by the sender.
  61. */
  62. signature?: null | SignatureLike;
  63. /**
  64. * The access list for berlin and london transactions.
  65. */
  66. accessList?: null | AccessListish;
  67. /**
  68. * The maximum fee per blob gas (see [[link-eip-4844]]).
  69. */
  70. maxFeePerBlobGas?: null | BigNumberish;
  71. /**
  72. * The versioned hashes (see [[link-eip-4844]]).
  73. */
  74. blobVersionedHashes?: null | Array<string>;
  75. /**
  76. * The blobs (if any) attached to this transaction (see [[link-eip-4844]]).
  77. */
  78. blobs?: null | Array<BlobLike>;
  79. /**
  80. * An external library for computing the KZG commitments and
  81. * proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
  82. *
  83. * This is generally ``null``, unless you are creating BLOb
  84. * transactions.
  85. */
  86. kzg?: null | KzgLibrary;
  87. }
  88. /**
  89. * A full-valid BLOb object for [[link-eip-4844]] transactions.
  90. *
  91. * The commitment and proof should have been computed using a
  92. * KZG library.
  93. */
  94. export interface Blob {
  95. data: string;
  96. proof: string;
  97. commitment: string;
  98. }
  99. /**
  100. * A BLOb object that can be passed for [[link-eip-4844]]
  101. * transactions.
  102. *
  103. * It may have had its commitment and proof already provided
  104. * or rely on an attached [[KzgLibrary]] to compute them.
  105. */
  106. export type BlobLike = BytesLike | {
  107. data: BytesLike;
  108. proof: BytesLike;
  109. commitment: BytesLike;
  110. };
  111. /**
  112. * A KZG Library with the necessary functions to compute
  113. * BLOb commitments and proofs.
  114. */
  115. export interface KzgLibrary {
  116. blobToKzgCommitment: (blob: Uint8Array) => Uint8Array;
  117. computeBlobKzgProof: (blob: Uint8Array, commitment: Uint8Array) => Uint8Array;
  118. }
  119. /**
  120. * A **Transaction** describes an operation to be executed on
  121. * Ethereum by an Externally Owned Account (EOA). It includes
  122. * who (the [[to]] address), what (the [[data]]) and how much (the
  123. * [[value]] in ether) the operation should entail.
  124. *
  125. * @example:
  126. * tx = new Transaction()
  127. * //_result:
  128. *
  129. * tx.data = "0x1234";
  130. * //_result:
  131. */
  132. export declare class Transaction implements TransactionLike<string> {
  133. #private;
  134. /**
  135. * The transaction type.
  136. *
  137. * If null, the type will be automatically inferred based on
  138. * explicit properties.
  139. */
  140. get type(): null | number;
  141. set type(value: null | number | string);
  142. /**
  143. * The name of the transaction type.
  144. */
  145. get typeName(): null | string;
  146. /**
  147. * The ``to`` address for the transaction or ``null`` if the
  148. * transaction is an ``init`` transaction.
  149. */
  150. get to(): null | string;
  151. set to(value: null | string);
  152. /**
  153. * The transaction nonce.
  154. */
  155. get nonce(): number;
  156. set nonce(value: BigNumberish);
  157. /**
  158. * The gas limit.
  159. */
  160. get gasLimit(): bigint;
  161. set gasLimit(value: BigNumberish);
  162. /**
  163. * The gas price.
  164. *
  165. * On legacy networks this defines the fee that will be paid. On
  166. * EIP-1559 networks, this should be ``null``.
  167. */
  168. get gasPrice(): null | bigint;
  169. set gasPrice(value: null | BigNumberish);
  170. /**
  171. * The maximum priority fee per unit of gas to pay. On legacy
  172. * networks this should be ``null``.
  173. */
  174. get maxPriorityFeePerGas(): null | bigint;
  175. set maxPriorityFeePerGas(value: null | BigNumberish);
  176. /**
  177. * The maximum total fee per unit of gas to pay. On legacy
  178. * networks this should be ``null``.
  179. */
  180. get maxFeePerGas(): null | bigint;
  181. set maxFeePerGas(value: null | BigNumberish);
  182. /**
  183. * The transaction data. For ``init`` transactions this is the
  184. * deployment code.
  185. */
  186. get data(): string;
  187. set data(value: BytesLike);
  188. /**
  189. * The amount of ether (in wei) to send in this transactions.
  190. */
  191. get value(): bigint;
  192. set value(value: BigNumberish);
  193. /**
  194. * The chain ID this transaction is valid on.
  195. */
  196. get chainId(): bigint;
  197. set chainId(value: BigNumberish);
  198. /**
  199. * If signed, the signature for this transaction.
  200. */
  201. get signature(): null | Signature;
  202. set signature(value: null | SignatureLike);
  203. /**
  204. * The access list.
  205. *
  206. * An access list permits discounted (but pre-paid) access to
  207. * bytecode and state variable access within contract execution.
  208. */
  209. get accessList(): null | AccessList;
  210. set accessList(value: null | AccessListish);
  211. /**
  212. * The max fee per blob gas for Cancun transactions.
  213. */
  214. get maxFeePerBlobGas(): null | bigint;
  215. set maxFeePerBlobGas(value: null | BigNumberish);
  216. /**
  217. * The BLOb versioned hashes for Cancun transactions.
  218. */
  219. get blobVersionedHashes(): null | Array<string>;
  220. set blobVersionedHashes(value: null | Array<string>);
  221. /**
  222. * The BLObs for the Transaction, if any.
  223. *
  224. * If ``blobs`` is non-``null``, then the [[seriailized]]
  225. * will return the network formatted sidecar, otherwise it
  226. * will return the standard [[link-eip-2718]] payload. The
  227. * [[unsignedSerialized]] is unaffected regardless.
  228. *
  229. * When setting ``blobs``, either fully valid [[Blob]] objects
  230. * may be specified (i.e. correctly padded, with correct
  231. * committments and proofs) or a raw [[BytesLike]] may
  232. * be provided.
  233. *
  234. * If raw [[BytesLike]] are provided, the [[kzg]] property **must**
  235. * be already set. The blob will be correctly padded and the
  236. * [[KzgLibrary]] will be used to compute the committment and
  237. * proof for the blob.
  238. *
  239. * A BLOb is a sequence of field elements, each of which must
  240. * be within the BLS field modulo, so some additional processing
  241. * may be required to encode arbitrary data to ensure each 32 byte
  242. * field is within the valid range.
  243. *
  244. * Setting this automatically populates [[blobVersionedHashes]],
  245. * overwriting any existing values. Setting this to ``null``
  246. * does **not** remove the [[blobVersionedHashes]], leaving them
  247. * present.
  248. */
  249. get blobs(): null | Array<Blob>;
  250. set blobs(_blobs: null | Array<BlobLike>);
  251. get kzg(): null | KzgLibrary;
  252. set kzg(kzg: null | KzgLibrary);
  253. /**
  254. * Creates a new Transaction with default values.
  255. */
  256. constructor();
  257. /**
  258. * The transaction hash, if signed. Otherwise, ``null``.
  259. */
  260. get hash(): null | string;
  261. /**
  262. * The pre-image hash of this transaction.
  263. *
  264. * This is the digest that a [[Signer]] must sign to authorize
  265. * this transaction.
  266. */
  267. get unsignedHash(): string;
  268. /**
  269. * The sending address, if signed. Otherwise, ``null``.
  270. */
  271. get from(): null | string;
  272. /**
  273. * The public key of the sender, if signed. Otherwise, ``null``.
  274. */
  275. get fromPublicKey(): null | string;
  276. /**
  277. * Returns true if signed.
  278. *
  279. * This provides a Type Guard that properties requiring a signed
  280. * transaction are non-null.
  281. */
  282. isSigned(): this is (Transaction & {
  283. type: number;
  284. typeName: string;
  285. from: string;
  286. signature: Signature;
  287. });
  288. /**
  289. * The serialized transaction.
  290. *
  291. * This throws if the transaction is unsigned. For the pre-image,
  292. * use [[unsignedSerialized]].
  293. */
  294. get serialized(): string;
  295. /**
  296. * The transaction pre-image.
  297. *
  298. * The hash of this is the digest which needs to be signed to
  299. * authorize this transaction.
  300. */
  301. get unsignedSerialized(): string;
  302. /**
  303. * Return the most "likely" type; currently the highest
  304. * supported transaction type.
  305. */
  306. inferType(): number;
  307. /**
  308. * Validates the explicit properties and returns a list of compatible
  309. * transaction types.
  310. */
  311. inferTypes(): Array<number>;
  312. /**
  313. * Returns true if this transaction is a legacy transaction (i.e.
  314. * ``type === 0``).
  315. *
  316. * This provides a Type Guard that the related properties are
  317. * non-null.
  318. */
  319. isLegacy(): this is (Transaction & {
  320. type: 0;
  321. gasPrice: bigint;
  322. });
  323. /**
  324. * Returns true if this transaction is berlin hardform transaction (i.e.
  325. * ``type === 1``).
  326. *
  327. * This provides a Type Guard that the related properties are
  328. * non-null.
  329. */
  330. isBerlin(): this is (Transaction & {
  331. type: 1;
  332. gasPrice: bigint;
  333. accessList: AccessList;
  334. });
  335. /**
  336. * Returns true if this transaction is london hardform transaction (i.e.
  337. * ``type === 2``).
  338. *
  339. * This provides a Type Guard that the related properties are
  340. * non-null.
  341. */
  342. isLondon(): this is (Transaction & {
  343. type: 2;
  344. accessList: AccessList;
  345. maxFeePerGas: bigint;
  346. maxPriorityFeePerGas: bigint;
  347. });
  348. /**
  349. * Returns true if this transaction is an [[link-eip-4844]] BLOB
  350. * transaction.
  351. *
  352. * This provides a Type Guard that the related properties are
  353. * non-null.
  354. */
  355. isCancun(): this is (Transaction & {
  356. type: 3;
  357. to: string;
  358. accessList: AccessList;
  359. maxFeePerGas: bigint;
  360. maxPriorityFeePerGas: bigint;
  361. maxFeePerBlobGas: bigint;
  362. blobVersionedHashes: Array<string>;
  363. });
  364. /**
  365. * Create a copy of this transaciton.
  366. */
  367. clone(): Transaction;
  368. /**
  369. * Return a JSON-friendly object.
  370. */
  371. toJSON(): any;
  372. /**
  373. * Create a **Transaction** from a serialized transaction or a
  374. * Transaction-like object.
  375. */
  376. static from(tx?: string | TransactionLike<string>): Transaction;
  377. }
  378. //# sourceMappingURL=transaction.d.ts.map