signer.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import type { Addressable, NameResolver } from "../address/index.js";
  2. import type { TypedDataDomain, TypedDataField } from "../hash/index.js";
  3. import type { TransactionLike } from "../transaction/index.js";
  4. import type { ContractRunner } from "./contracts.js";
  5. import type { BlockTag, Provider, TransactionRequest, TransactionResponse } from "./provider.js";
  6. /**
  7. * A Signer represents an account on the Ethereum Blockchain, and is most often
  8. * backed by a private key represented by a mnemonic or residing on a Hardware Wallet.
  9. *
  10. * The API remains abstract though, so that it can deal with more advanced exotic
  11. * Signing entities, such as Smart Contract Wallets or Virtual Wallets (where the
  12. * private key may not be known).
  13. */
  14. export interface Signer extends Addressable, ContractRunner, NameResolver {
  15. /**
  16. * The [[Provider]] attached to this Signer (if any).
  17. */
  18. provider: null | Provider;
  19. /**
  20. * Returns a new instance of this Signer connected to //provider// or detached
  21. * from any Provider if null.
  22. */
  23. connect(provider: null | Provider): Signer;
  24. /**
  25. * Get the address of the Signer.
  26. */
  27. getAddress(): Promise<string>;
  28. /**
  29. * Gets the next nonce required for this Signer to send a transaction.
  30. *
  31. * @param blockTag - The blocktag to base the transaction count on, keep in mind
  32. * many nodes do not honour this value and silently ignore it [default: ``"latest"``]
  33. */
  34. getNonce(blockTag?: BlockTag): Promise<number>;
  35. /**
  36. * Prepares a {@link TransactionRequest} for calling:
  37. * - resolves ``to`` and ``from`` addresses
  38. * - if ``from`` is specified , check that it matches this Signer
  39. *
  40. * @param tx - The call to prepare
  41. */
  42. populateCall(tx: TransactionRequest): Promise<TransactionLike<string>>;
  43. /**
  44. * Prepares a {@link TransactionRequest} for sending to the network by
  45. * populating any missing properties:
  46. * - resolves ``to`` and ``from`` addresses
  47. * - if ``from`` is specified , check that it matches this Signer
  48. * - populates ``nonce`` via ``signer.getNonce("pending")``
  49. * - populates ``gasLimit`` via ``signer.estimateGas(tx)``
  50. * - populates ``chainId`` via ``signer.provider.getNetwork()``
  51. * - populates ``type`` and relevant fee data for that type (``gasPrice``
  52. * for legacy transactions, ``maxFeePerGas`` for EIP-1559, etc)
  53. *
  54. * @note Some Signer implementations may skip populating properties that
  55. * are populated downstream; for example JsonRpcSigner defers to the
  56. * node to populate the nonce and fee data.
  57. *
  58. * @param tx - The call to prepare
  59. */
  60. populateTransaction(tx: TransactionRequest): Promise<TransactionLike<string>>;
  61. /**
  62. * Estimates the required gas required to execute //tx// on the Blockchain. This
  63. * will be the expected amount a transaction will require as its ``gasLimit``
  64. * to successfully run all the necessary computations and store the needed state
  65. * that the transaction intends.
  66. *
  67. * Keep in mind that this is **best efforts**, since the state of the Blockchain
  68. * is in flux, which could affect transaction gas requirements.
  69. *
  70. * @throws UNPREDICTABLE_GAS_LIMIT A transaction that is believed by the node to likely
  71. * fail will throw an error during gas estimation. This could indicate that it
  72. * will actually fail or that the circumstances are simply too complex for the
  73. * node to take into account. In these cases, a manually determined ``gasLimit``
  74. * will need to be made.
  75. */
  76. estimateGas(tx: TransactionRequest): Promise<bigint>;
  77. /**
  78. * Evaluates the //tx// by running it against the current Blockchain state. This
  79. * cannot change state and has no cost in ether, as it is effectively simulating
  80. * execution.
  81. *
  82. * This can be used to have the Blockchain perform computations based on its state
  83. * (e.g. running a Contract's getters) or to simulate the effect of a transaction
  84. * before actually performing an operation.
  85. */
  86. call(tx: TransactionRequest): Promise<string>;
  87. /**
  88. * Resolves an ENS Name to an address.
  89. */
  90. resolveName(name: string): Promise<null | string>;
  91. /**
  92. * Signs %%tx%%, returning the fully signed transaction. This does not
  93. * populate any additional properties within the transaction.
  94. */
  95. signTransaction(tx: TransactionRequest): Promise<string>;
  96. /**
  97. * Sends %%tx%% to the Network. The ``signer.populateTransaction(tx)``
  98. * is called first to ensure all necessary properties for the
  99. * transaction to be valid have been popualted first.
  100. */
  101. sendTransaction(tx: TransactionRequest): Promise<TransactionResponse>;
  102. /**
  103. * Signs an [[link-eip-191]] prefixed personal message.
  104. *
  105. * If the %%message%% is a string, it is signed as UTF-8 encoded bytes. It is **not**
  106. * interpretted as a [[BytesLike]]; so the string ``"0x1234"`` is signed as six
  107. * characters, **not** two bytes.
  108. *
  109. * To sign that example as two bytes, the Uint8Array should be used
  110. * (i.e. ``new Uint8Array([ 0x12, 0x34 ])``).
  111. */
  112. signMessage(message: string | Uint8Array): Promise<string>;
  113. /**
  114. * Signs the [[link-eip-712]] typed data.
  115. */
  116. signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>): Promise<string>;
  117. }
  118. //# sourceMappingURL=signer.d.ts.map