viem 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +6 -0
  2. package/dist/cjs/actions/index.js +8 -2
  3. package/dist/cjs/actions/index.js.map +1 -1
  4. package/dist/cjs/actions/public/estimateFeesPerGas.js +3 -2
  5. package/dist/cjs/actions/public/estimateFeesPerGas.js.map +1 -1
  6. package/dist/cjs/actions/public/estimateGas.js +2 -2
  7. package/dist/cjs/actions/public/estimateGas.js.map +1 -1
  8. package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js +3 -3
  9. package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
  10. package/dist/cjs/actions/public/watchContractEvent.js +10 -7
  11. package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
  12. package/dist/cjs/{utils/transaction/prepareRequest.js → actions/wallet/prepareTransactionRequest.js} +19 -10
  13. package/dist/cjs/actions/wallet/prepareTransactionRequest.js.map +1 -0
  14. package/dist/cjs/actions/wallet/sendRawTransaction.js +11 -0
  15. package/dist/cjs/actions/wallet/sendRawTransaction.js.map +1 -0
  16. package/dist/cjs/actions/wallet/sendTransaction.js +6 -6
  17. package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
  18. package/dist/cjs/actions/wallet/signTransaction.js +47 -0
  19. package/dist/cjs/actions/wallet/signTransaction.js.map +1 -0
  20. package/dist/cjs/chains/celo/formatters.js +4 -1
  21. package/dist/cjs/chains/celo/formatters.js.map +1 -1
  22. package/dist/cjs/chains/index.js +3 -2
  23. package/dist/cjs/chains/index.js.map +1 -1
  24. package/dist/cjs/clients/decorators/public.js +4 -0
  25. package/dist/cjs/clients/decorators/public.js.map +1 -1
  26. package/dist/cjs/clients/decorators/wallet.js +6 -0
  27. package/dist/cjs/clients/decorators/wallet.js.map +1 -1
  28. package/dist/cjs/errors/version.js +1 -1
  29. package/dist/cjs/index.js +4 -5
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/cjs/utils/data/isBytesEqual.js +4 -3
  32. package/dist/cjs/utils/data/isBytesEqual.js.map +1 -1
  33. package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +2 -2
  34. package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -1
  35. package/dist/cjs/utils/formatters/transactionRequest.js +9 -1
  36. package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
  37. package/dist/cjs/utils/index.js +3 -3
  38. package/dist/cjs/utils/index.js.map +1 -1
  39. package/dist/esm/actions/index.js +3 -0
  40. package/dist/esm/actions/index.js.map +1 -1
  41. package/dist/esm/actions/public/estimateFeesPerGas.js +3 -2
  42. package/dist/esm/actions/public/estimateFeesPerGas.js.map +1 -1
  43. package/dist/esm/actions/public/estimateGas.js +2 -2
  44. package/dist/esm/actions/public/estimateGas.js.map +1 -1
  45. package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js +3 -3
  46. package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
  47. package/dist/esm/actions/public/watchContractEvent.js +5 -2
  48. package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
  49. package/dist/esm/{utils/transaction/prepareRequest.js → actions/wallet/prepareTransactionRequest.js} +58 -9
  50. package/dist/esm/actions/wallet/prepareTransactionRequest.js.map +1 -0
  51. package/dist/esm/actions/wallet/sendRawTransaction.js +31 -0
  52. package/dist/esm/actions/wallet/sendRawTransaction.js.map +1 -0
  53. package/dist/esm/actions/wallet/sendTransaction.js +6 -6
  54. package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
  55. package/dist/esm/actions/wallet/signTransaction.js +87 -0
  56. package/dist/esm/actions/wallet/signTransaction.js.map +1 -0
  57. package/dist/esm/chains/celo/formatters.js +4 -1
  58. package/dist/esm/chains/celo/formatters.js.map +1 -1
  59. package/dist/esm/chains/index.js +1 -0
  60. package/dist/esm/chains/index.js.map +1 -1
  61. package/dist/esm/clients/decorators/public.js +4 -0
  62. package/dist/esm/clients/decorators/public.js.map +1 -1
  63. package/dist/esm/clients/decorators/wallet.js +6 -0
  64. package/dist/esm/clients/decorators/wallet.js.map +1 -1
  65. package/dist/esm/errors/version.js +1 -1
  66. package/dist/esm/index.js +1 -2
  67. package/dist/esm/index.js.map +1 -1
  68. package/dist/esm/utils/data/isBytesEqual.js +2 -1
  69. package/dist/esm/utils/data/isBytesEqual.js.map +1 -1
  70. package/dist/esm/utils/ens/encodedLabelToLabelhash.js +1 -1
  71. package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -1
  72. package/dist/esm/utils/formatters/transactionRequest.js +8 -0
  73. package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
  74. package/dist/esm/utils/index.js +3 -1
  75. package/dist/esm/utils/index.js.map +1 -1
  76. package/dist/types/actions/index.d.ts +3 -0
  77. package/dist/types/actions/index.d.ts.map +1 -1
  78. package/dist/types/actions/public/estimateFeesPerGas.d.ts +2 -2
  79. package/dist/types/actions/public/estimateFeesPerGas.d.ts.map +1 -1
  80. package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts +4 -2
  81. package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -1
  82. package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
  83. package/dist/types/actions/wallet/prepareTransactionRequest.d.ts +52 -0
  84. package/dist/types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -0
  85. package/dist/types/actions/wallet/sendRawTransaction.d.ts +38 -0
  86. package/dist/types/actions/wallet/sendRawTransaction.d.ts.map +1 -0
  87. package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
  88. package/dist/types/actions/wallet/signTransaction.d.ts +55 -0
  89. package/dist/types/actions/wallet/signTransaction.d.ts.map +1 -0
  90. package/dist/types/chains/celo/formatters.d.ts +303 -5
  91. package/dist/types/chains/celo/formatters.d.ts.map +1 -1
  92. package/dist/types/chains/celo/types.d.ts +43 -17
  93. package/dist/types/chains/celo/types.d.ts.map +1 -1
  94. package/dist/types/chains/index.d.ts +958 -19
  95. package/dist/types/chains/index.d.ts.map +1 -1
  96. package/dist/types/chains/utils.d.ts +1 -1
  97. package/dist/types/chains/utils.d.ts.map +1 -1
  98. package/dist/types/clients/decorators/public.d.ts +66 -0
  99. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  100. package/dist/types/clients/decorators/wallet.d.ts +111 -0
  101. package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
  102. package/dist/types/errors/version.d.ts +1 -1
  103. package/dist/types/index.d.ts +4 -2
  104. package/dist/types/index.d.ts.map +1 -1
  105. package/dist/types/types/chain.d.ts +2 -2
  106. package/dist/types/types/chain.d.ts.map +1 -1
  107. package/dist/types/types/eip1193.d.ts +1 -1
  108. package/dist/types/utils/data/isBytesEqual.d.ts +1 -1
  109. package/dist/types/utils/data/isBytesEqual.d.ts.map +1 -1
  110. package/dist/types/utils/ens/encodeLabelhash.d.ts +1 -1
  111. package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -1
  112. package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +1 -1
  113. package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -1
  114. package/dist/types/utils/formatters/transactionRequest.d.ts +5 -0
  115. package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
  116. package/dist/types/utils/index.d.ts +3 -1
  117. package/dist/types/utils/index.d.ts.map +1 -1
  118. package/package.json +1 -1
  119. package/src/actions/index.ts +15 -0
  120. package/src/actions/public/estimateFeesPerGas.ts +6 -4
  121. package/src/actions/public/estimateGas.ts +5 -5
  122. package/src/actions/public/estimateMaxPriorityFeePerGas.ts +7 -5
  123. package/src/actions/public/watchContractEvent.ts +9 -6
  124. package/src/{utils/transaction/prepareRequest.ts → actions/wallet/prepareTransactionRequest.ts} +80 -36
  125. package/src/actions/wallet/sendRawTransaction.ts +48 -0
  126. package/src/actions/wallet/sendTransaction.ts +6 -6
  127. package/src/actions/wallet/signTransaction.ts +137 -0
  128. package/src/chains/celo/formatters.ts +11 -12
  129. package/src/chains/celo/types.ts +86 -30
  130. package/src/chains/index.ts +1 -0
  131. package/src/chains/utils.ts +4 -4
  132. package/src/clients/decorators/public.ts +81 -0
  133. package/src/clients/decorators/wallet.ts +133 -0
  134. package/src/errors/rpc.ts +1 -1
  135. package/src/errors/version.ts +1 -1
  136. package/src/index.ts +7 -1
  137. package/src/types/chain.ts +2 -2
  138. package/src/types/eip1193.ts +1 -1
  139. package/src/utils/data/isBytesEqual.ts +4 -1
  140. package/src/utils/ens/encodeLabelhash.ts +1 -1
  141. package/src/utils/ens/encodedLabelToLabelhash.ts +2 -2
  142. package/src/utils/formatters/transactionRequest.ts +10 -0
  143. package/src/utils/index.ts +4 -1
  144. package/dist/cjs/utils/transaction/prepareRequest.js.map +0 -1
  145. package/dist/esm/utils/transaction/prepareRequest.js.map +0 -1
  146. package/dist/types/utils/transaction/prepareRequest.d.ts +0 -21
  147. package/dist/types/utils/transaction/prepareRequest.d.ts.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { type ChainFormatters } from '../../types/chain.js'
2
2
  import type { Hash } from '../../types/misc.js'
3
+ import type { RpcTransaction } from '../../types/rpc.js'
3
4
  import { hexToBigInt } from '../../utils/encoding/fromHex.js'
4
5
  import { numberToHex } from '../../utils/encoding/toHex.js'
5
6
  import { defineBlock } from '../../utils/formatters/block.js'
@@ -12,13 +13,11 @@ import { defineTransactionRequest } from '../../utils/formatters/transactionRequ
12
13
  import type {
13
14
  CeloBlockOverrides,
14
15
  CeloRpcTransaction,
15
- CeloRpcTransactionOverrides,
16
16
  CeloRpcTransactionReceiptOverrides,
17
- CeloRpcTransactionRequestOverrides,
17
+ CeloRpcTransactionRequest,
18
18
  CeloTransaction,
19
- CeloTransactionOverrides,
20
19
  CeloTransactionReceiptOverrides,
21
- CeloTransactionRequestOverrides,
20
+ CeloTransactionRequest,
22
21
  } from './types.js'
23
22
 
24
23
  export const formattersCelo = {
@@ -34,7 +33,7 @@ export const formattersCelo = {
34
33
  const transactions = args.transactions?.map((transaction) => {
35
34
  if (typeof transaction === 'string') return transaction
36
35
  return {
37
- ...formatTransaction(transaction),
36
+ ...formatTransaction(transaction as RpcTransaction),
38
37
  feeCurrency: transaction.feeCurrency,
39
38
  gatewayFee: transaction.gatewayFee
40
39
  ? hexToBigInt(transaction.gatewayFee)
@@ -49,12 +48,12 @@ export const formattersCelo = {
49
48
  },
50
49
  }),
51
50
  transaction: /*#__PURE__*/ defineTransaction({
52
- format(args: CeloRpcTransactionOverrides): CeloTransactionOverrides {
51
+ format(args: CeloRpcTransaction): CeloTransaction {
53
52
  return {
54
53
  feeCurrency: args.feeCurrency,
55
54
  gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null,
56
55
  gatewayFeeRecipient: args.gatewayFeeRecipient,
57
- }
56
+ } as CeloTransaction
58
57
  },
59
58
  }),
60
59
  transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({
@@ -69,17 +68,17 @@ export const formattersCelo = {
69
68
  },
70
69
  }),
71
70
  transactionRequest: /*#__PURE__*/ defineTransactionRequest({
72
- format(
73
- args: CeloTransactionRequestOverrides,
74
- ): CeloRpcTransactionRequestOverrides {
75
- return {
71
+ format(args: CeloTransactionRequest): CeloRpcTransactionRequest {
72
+ const request = {
76
73
  feeCurrency: args.feeCurrency,
77
74
  gatewayFee:
78
75
  typeof args.gatewayFee !== 'undefined'
79
76
  ? numberToHex(args.gatewayFee)
80
77
  : undefined,
81
78
  gatewayFeeRecipient: args.gatewayFeeRecipient,
82
- }
79
+ } as CeloRpcTransactionRequest
80
+ if (args.type === 'cip42') request.type = '0x7c'
81
+ return request
83
82
  },
84
83
  }),
85
84
  } as const satisfies ChainFormatters
@@ -4,17 +4,21 @@ import type { Block, BlockTag } from '../../types/block.js'
4
4
  import type { FeeValuesEIP1559 } from '../../types/fee.js'
5
5
  import type { Hex } from '../../types/misc.js'
6
6
  import type {
7
+ Index,
8
+ Quantity,
7
9
  RpcBlock,
8
- RpcTransaction,
10
+ RpcTransaction as RpcTransaction_,
9
11
  RpcTransactionReceipt,
10
- RpcTransactionRequest,
12
+ RpcTransactionRequest as RpcTransactionRequest_,
11
13
  TransactionType,
12
14
  } from '../../types/rpc.js'
13
15
  import type {
14
16
  AccessList,
15
- Transaction,
17
+ Transaction as Transaction_,
18
+ TransactionBase,
16
19
  TransactionReceipt,
17
- TransactionRequest,
20
+ TransactionRequest as TransactionRequest_,
21
+ TransactionRequestBase,
18
22
  TransactionSerializable,
19
23
  TransactionSerializableBase,
20
24
  TransactionSerialized,
@@ -68,13 +72,9 @@ export type CeloRpcBlock<
68
72
  > &
69
73
  CeloRpcBlockOverrides
70
74
 
71
- export type CeloRpcTransactionOverrides = {
72
- feeCurrency: Address | null
73
- gatewayFee: Hex | null
74
- gatewayFeeRecipient: Address | null
75
- }
76
75
  export type CeloRpcTransaction<TPending extends boolean = boolean> =
77
- RpcTransaction<TPending> & CeloRpcTransactionOverrides
76
+ | RpcTransaction<TPending>
77
+ | RpcTransactionCIP42<TPending>
78
78
 
79
79
  export type CeloRpcTransactionReceiptOverrides = {
80
80
  feeCurrency: Address | null
@@ -84,21 +84,13 @@ export type CeloRpcTransactionReceiptOverrides = {
84
84
  export type CeloRpcTransactionReceipt = RpcTransactionReceipt &
85
85
  CeloRpcTransactionReceiptOverrides
86
86
 
87
- export type CeloRpcTransactionRequestOverrides = {
88
- feeCurrency?: Address
89
- gatewayFee?: Hex
90
- gatewayFeeRecipient?: Address
91
- }
92
- export type CeloRpcTransactionRequest = RpcTransactionRequest &
93
- CeloRpcTransactionRequestOverrides
87
+ export type CeloRpcTransactionRequest =
88
+ | RpcTransactionRequest
89
+ | RpcTransactionRequestCIP42
94
90
 
95
- export type CeloTransactionOverrides = {
96
- feeCurrency: Address | null
97
- gatewayFee: bigint | null
98
- gatewayFeeRecipient: Address | null
99
- }
100
91
  export type CeloTransaction<TPending extends boolean = boolean> =
101
- Transaction<TPending> & CeloTransactionOverrides
92
+ | Transaction<TPending>
93
+ | TransactionCIP42<TPending>
102
94
 
103
95
  export type CeloTransactionReceiptOverrides = {
104
96
  feeCurrency: Address | null
@@ -108,13 +100,9 @@ export type CeloTransactionReceiptOverrides = {
108
100
  export type CeloTransactionReceipt = TransactionReceipt &
109
101
  CeloTransactionReceiptOverrides
110
102
 
111
- export type CeloTransactionRequestOverrides = {
112
- feeCurrency?: Address
113
- gatewayFee?: bigint
114
- gatewayFeeRecipient?: Address
115
- }
116
- export type CeloTransactionRequest = TransactionRequest &
117
- CeloTransactionRequestOverrides
103
+ export type CeloTransactionRequest =
104
+ | TransactionRequest
105
+ | TransactionRequestCIP42
118
106
 
119
107
  export type CeloTransactionSerializable =
120
108
  | TransactionSerializableCIP42
@@ -126,6 +114,74 @@ export type CeloTransactionSerialized<
126
114
 
127
115
  export type CeloTransactionType = TransactionType | 'cip42'
128
116
 
117
+ type RpcTransaction<TPending extends boolean = boolean> =
118
+ RpcTransaction_<TPending> & {
119
+ feeCurrency: Address | null
120
+ gatewayFee: Hex | null
121
+ gatewayFeeRecipient: Address | null
122
+ }
123
+
124
+ type RpcTransactionRequest = RpcTransactionRequest_ & {
125
+ feeCurrency?: Address
126
+ gatewayFee?: Hex
127
+ gatewayFeeRecipient?: Address
128
+ }
129
+
130
+ export type RpcTransactionCIP42<TPending extends boolean = boolean> =
131
+ TransactionBase<Quantity, Index, TPending> &
132
+ FeeValuesEIP1559<Quantity> & {
133
+ feeCurrency: Address | null
134
+ gatewayFee: Hex | null
135
+ gatewayFeeRecipient: Address | null
136
+ type: '0x7c'
137
+ }
138
+
139
+ export type RpcTransactionRequestCIP42 = TransactionRequestBase<
140
+ Quantity,
141
+ Index
142
+ > &
143
+ Partial<FeeValuesEIP1559<Quantity>> & {
144
+ accessList?: AccessList
145
+ feeCurrency?: Address
146
+ gatewayFee?: Hex
147
+ gatewayFeeRecipient?: Address
148
+ type?: '0x7c'
149
+ }
150
+
151
+ type Transaction<TPending extends boolean = boolean> = Transaction_<
152
+ bigint,
153
+ number,
154
+ TPending
155
+ > & {
156
+ feeCurrency: Address | null
157
+ gatewayFee: bigint | null
158
+ gatewayFeeRecipient: Address | null
159
+ }
160
+
161
+ export type TransactionCIP42<TPending extends boolean = boolean> =
162
+ TransactionBase<bigint, number, TPending> &
163
+ FeeValuesEIP1559 & {
164
+ feeCurrency: Address | null
165
+ gatewayFee: bigint | null
166
+ gatewayFeeRecipient: Address | null
167
+ type: 'cip42'
168
+ }
169
+
170
+ type TransactionRequest = TransactionRequest_ & {
171
+ feeCurrency?: Address
172
+ gatewayFee?: bigint
173
+ gatewayFeeRecipient?: Address
174
+ }
175
+
176
+ export type TransactionRequestCIP42 = TransactionRequestBase &
177
+ Partial<FeeValuesEIP1559> & {
178
+ accessList?: AccessList
179
+ feeCurrency?: Address
180
+ gatewayFee?: bigint
181
+ gatewayFeeRecipient?: Address
182
+ type?: 'cip42'
183
+ }
184
+
129
185
  export type TransactionSerializableCIP42<
130
186
  TQuantity = bigint,
131
187
  TIndex = number,
@@ -66,6 +66,7 @@ export const haqqTestedge2 = /*#__PURE__*/ defineChain(chains.haqqTestedge2)
66
66
  export const hardhat = /*#__PURE__*/ defineChain(chains.hardhat)
67
67
  export const harmonyOne = /*#__PURE__*/ defineChain(chains.harmonyOne)
68
68
  export const klaytn = /*#__PURE__*/ defineChain(chains.klaytn)
69
+ export const linea = /*#__PURE__*/ defineChain(chains.linea)
69
70
  export const lineaTestnet = /*#__PURE__*/ defineChain(chains.lineaTestnet)
70
71
  export const localhost = /*#__PURE__*/ defineChain(chains.localhost)
71
72
  export const mainnet = /*#__PURE__*/ defineChain(chains.mainnet)
@@ -10,20 +10,20 @@ export type {
10
10
  CeloRpcBlock,
11
11
  CeloRpcBlockOverrides,
12
12
  CeloRpcTransaction,
13
- CeloRpcTransactionOverrides,
14
13
  CeloRpcTransactionReceipt,
15
14
  CeloRpcTransactionReceiptOverrides,
16
15
  CeloRpcTransactionRequest,
17
- CeloRpcTransactionRequestOverrides,
18
16
  CeloTransaction,
19
- CeloTransactionOverrides,
20
17
  CeloTransactionReceipt,
21
18
  CeloTransactionReceiptOverrides,
22
19
  CeloTransactionRequest,
23
- CeloTransactionRequestOverrides,
24
20
  CeloTransactionSerializable,
25
21
  CeloTransactionSerialized,
26
22
  CeloTransactionType,
23
+ RpcTransactionCIP42,
24
+ RpcTransactionRequestCIP42,
25
+ TransactionCIP42,
26
+ TransactionRequestCIP42,
27
27
  TransactionSerializableCIP42,
28
28
  TransactionSerializedCIP42,
29
29
  } from './celo/types.js'
@@ -206,6 +206,16 @@ import {
206
206
  type WatchPendingTransactionsReturnType,
207
207
  watchPendingTransactions,
208
208
  } from '../../actions/public/watchPendingTransactions.js'
209
+ import {
210
+ type PrepareTransactionRequestParameters,
211
+ type PrepareTransactionRequestReturnType,
212
+ prepareTransactionRequest,
213
+ } from '../../actions/wallet/prepareTransactionRequest.js'
214
+ import {
215
+ type SendRawTransactionParameters,
216
+ type SendRawTransactionReturnType,
217
+ sendRawTransaction,
218
+ } from '../../actions/wallet/sendRawTransaction.js'
209
219
  import type { Account } from '../../types/account.js'
210
220
  import type { BlockNumber, BlockTag } from '../../types/block.js'
211
221
  import type { Chain } from '../../types/chain.js'
@@ -1199,6 +1209,47 @@ export type PublicActions<
1199
1209
  >(
1200
1210
  args: MulticallParameters<TContracts, TAllowFailure>,
1201
1211
  ) => Promise<MulticallReturnType<TContracts, TAllowFailure>>
1212
+ /**
1213
+ * Prepares a transaction request for signing.
1214
+ *
1215
+ * - Docs: https://viem.sh/docs/actions/wallet/prepareTransactionRequest.html
1216
+ *
1217
+ * @param args - {@link PrepareTransactionRequestParameters}
1218
+ * @returns The transaction request. {@link PrepareTransactionRequestReturnType}
1219
+ *
1220
+ * @example
1221
+ * import { createWalletClient, custom } from 'viem'
1222
+ * import { mainnet } from 'viem/chains'
1223
+ *
1224
+ * const client = createWalletClient({
1225
+ * chain: mainnet,
1226
+ * transport: custom(window.ethereum),
1227
+ * })
1228
+ * const request = await client.prepareTransactionRequest({
1229
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
1230
+ * to: '0x0000000000000000000000000000000000000000',
1231
+ * value: 1n,
1232
+ * })
1233
+ *
1234
+ * @example
1235
+ * // Account Hoisting
1236
+ * import { createWalletClient, http } from 'viem'
1237
+ * import { privateKeyToAccount } from 'viem/accounts'
1238
+ * import { mainnet } from 'viem/chains'
1239
+ *
1240
+ * const client = createWalletClient({
1241
+ * account: privateKeyToAccount('0x…'),
1242
+ * chain: mainnet,
1243
+ * transport: custom(window.ethereum),
1244
+ * })
1245
+ * const request = await client.prepareTransactionRequest({
1246
+ * to: '0x0000000000000000000000000000000000000000',
1247
+ * value: 1n,
1248
+ * })
1249
+ */
1250
+ prepareTransactionRequest: <TChainOverride extends Chain | undefined,>(
1251
+ args: PrepareTransactionRequestParameters<TChain, TAccount, TChainOverride>,
1252
+ ) => Promise<PrepareTransactionRequestReturnType>
1202
1253
  /**
1203
1254
  * Calls a read-only function on a contract, and returns the response.
1204
1255
  *
@@ -1236,6 +1287,33 @@ export type PublicActions<
1236
1287
  >(
1237
1288
  args: ReadContractParameters<TAbi, TFunctionName>,
1238
1289
  ) => Promise<ReadContractReturnType<TAbi, TFunctionName>>
1290
+ /**
1291
+ * Sends a **signed** transaction to the network
1292
+ *
1293
+ * - Docs: https://viem.sh/docs/actions/wallet/sendRawTransaction.html
1294
+ * - JSON-RPC Method: [`eth_sendRawTransaction`](https://ethereum.github.io/execution-apis/api-documentation/)
1295
+ *
1296
+ * @param client - Client to use
1297
+ * @param parameters - {@link SendRawTransactionParameters}
1298
+ * @returns The transaction hash. {@link SendRawTransactionReturnType}
1299
+ *
1300
+ * @example
1301
+ * import { createWalletClient, custom } from 'viem'
1302
+ * import { mainnet } from 'viem/chains'
1303
+ * import { sendRawTransaction } from 'viem/wallet'
1304
+ *
1305
+ * const client = createWalletClient({
1306
+ * chain: mainnet,
1307
+ * transport: custom(window.ethereum),
1308
+ * })
1309
+ *
1310
+ * const hash = await client.sendRawTransaction({
1311
+ * serializedTransaction: '0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33'
1312
+ * })
1313
+ */
1314
+ sendRawTransaction: (
1315
+ args: SendRawTransactionParameters,
1316
+ ) => Promise<SendRawTransactionReturnType>
1239
1317
  /**
1240
1318
  * Simulates/validates a contract interaction. This is useful for retrieving **return data** and **revert reasons** of contract write functions.
1241
1319
  *
@@ -1567,7 +1645,10 @@ export function publicActions<
1567
1645
  getTransactionCount: (args) => getTransactionCount(client, args),
1568
1646
  getTransactionReceipt: (args) => getTransactionReceipt(client, args),
1569
1647
  multicall: (args) => multicall(client, args as any) as any,
1648
+ prepareTransactionRequest: (args) =>
1649
+ prepareTransactionRequest(client as any, args as any),
1570
1650
  readContract: (args) => readContract(client, args),
1651
+ sendRawTransaction: (args) => sendRawTransaction(client, args),
1571
1652
  simulateContract: (args) => simulateContract(client, args),
1572
1653
  verifyMessage: (args) => verifyMessage(client, args),
1573
1654
  verifyTypedData: (args) => verifyTypedData(client, args),
@@ -22,6 +22,11 @@ import {
22
22
  type GetPermissionsReturnType,
23
23
  getPermissions,
24
24
  } from '../../actions/wallet/getPermissions.js'
25
+ import {
26
+ type PrepareTransactionRequestParameters,
27
+ type PrepareTransactionRequestReturnType,
28
+ prepareTransactionRequest,
29
+ } from '../../actions/wallet/prepareTransactionRequest.js'
25
30
  import {
26
31
  type RequestAddressesReturnType,
27
32
  requestAddresses,
@@ -31,6 +36,11 @@ import {
31
36
  type RequestPermissionsReturnType,
32
37
  requestPermissions,
33
38
  } from '../../actions/wallet/requestPermissions.js'
39
+ import {
40
+ type SendRawTransactionParameters,
41
+ type SendRawTransactionReturnType,
42
+ sendRawTransaction,
43
+ } from '../../actions/wallet/sendRawTransaction.js'
34
44
  import {
35
45
  type SendTransactionParameters,
36
46
  type SendTransactionReturnType,
@@ -41,6 +51,11 @@ import {
41
51
  type SignMessageReturnType,
42
52
  signMessage,
43
53
  } from '../../actions/wallet/signMessage.js'
54
+ import {
55
+ type SignTransactionParameters,
56
+ type SignTransactionReturnType,
57
+ signTransaction,
58
+ } from '../../actions/wallet/signTransaction.js'
44
59
  import {
45
60
  type SignTypedDataParameters,
46
61
  type SignTypedDataReturnType,
@@ -175,6 +190,47 @@ export type WalletActions<
175
190
  * const permissions = await client.getPermissions()
176
191
  */
177
192
  getPermissions: () => Promise<GetPermissionsReturnType>
193
+ /**
194
+ * Prepares a transaction request for signing.
195
+ *
196
+ * - Docs: https://viem.sh/docs/actions/wallet/prepareTransactionRequest.html
197
+ *
198
+ * @param args - {@link PrepareTransactionRequestParameters}
199
+ * @returns The transaction request. {@link PrepareTransactionRequestReturnType}
200
+ *
201
+ * @example
202
+ * import { createWalletClient, custom } from 'viem'
203
+ * import { mainnet } from 'viem/chains'
204
+ *
205
+ * const client = createWalletClient({
206
+ * chain: mainnet,
207
+ * transport: custom(window.ethereum),
208
+ * })
209
+ * const request = await client.prepareTransactionRequest({
210
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
211
+ * to: '0x0000000000000000000000000000000000000000',
212
+ * value: 1n,
213
+ * })
214
+ *
215
+ * @example
216
+ * // Account Hoisting
217
+ * import { createWalletClient, http } from 'viem'
218
+ * import { privateKeyToAccount } from 'viem/accounts'
219
+ * import { mainnet } from 'viem/chains'
220
+ *
221
+ * const client = createWalletClient({
222
+ * account: privateKeyToAccount('0x…'),
223
+ * chain: mainnet,
224
+ * transport: custom(window.ethereum),
225
+ * })
226
+ * const request = await client.prepareTransactionRequest({
227
+ * to: '0x0000000000000000000000000000000000000000',
228
+ * value: 1n,
229
+ * })
230
+ */
231
+ prepareTransactionRequest: <TChainOverride extends Chain | undefined,>(
232
+ args: PrepareTransactionRequestParameters<TChain, TAccount, TChainOverride>,
233
+ ) => Promise<PrepareTransactionRequestReturnType>
178
234
  /**
179
235
  * Requests a list of accounts managed by a wallet.
180
236
  *
@@ -222,6 +278,33 @@ export type WalletActions<
222
278
  requestPermissions: (
223
279
  args: RequestPermissionsParameters,
224
280
  ) => Promise<RequestPermissionsReturnType>
281
+ /**
282
+ * Sends a **signed** transaction to the network
283
+ *
284
+ * - Docs: https://viem.sh/docs/actions/wallet/sendRawTransaction.html
285
+ * - JSON-RPC Method: [`eth_sendRawTransaction`](https://ethereum.github.io/execution-apis/api-documentation/)
286
+ *
287
+ * @param client - Client to use
288
+ * @param parameters - {@link SendRawTransactionParameters}
289
+ * @returns The transaction hash. {@link SendRawTransactionReturnType}
290
+ *
291
+ * @example
292
+ * import { createWalletClient, custom } from 'viem'
293
+ * import { mainnet } from 'viem/chains'
294
+ * import { sendRawTransaction } from 'viem/wallet'
295
+ *
296
+ * const client = createWalletClient({
297
+ * chain: mainnet,
298
+ * transport: custom(window.ethereum),
299
+ * })
300
+ *
301
+ * const hash = await client.sendRawTransaction({
302
+ * serializedTransaction: '0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33'
303
+ * })
304
+ */
305
+ sendRawTransaction: (
306
+ args: SendRawTransactionParameters,
307
+ ) => Promise<SendRawTransactionReturnType>
225
308
  /**
226
309
  * Creates, signs, and sends a new transaction to the network.
227
310
  *
@@ -313,6 +396,52 @@ export type WalletActions<
313
396
  signMessage: (
314
397
  args: SignMessageParameters<TAccount>,
315
398
  ) => Promise<SignMessageReturnType>
399
+ /**
400
+ * Signs a transaction.
401
+ *
402
+ * - Docs: https://viem.sh/docs/actions/wallet/signTransaction.html
403
+ * - JSON-RPC Methods:
404
+ * - JSON-RPC Accounts: [`eth_signTransaction`](https://ethereum.github.io/execution-apis/api-documentation/)
405
+ * - Local Accounts: Signs locally. No JSON-RPC request.
406
+ *
407
+ * @param args - {@link SignTransactionParameters}
408
+ * @returns The signed message. {@link SignTransactionReturnType}
409
+ *
410
+ * @example
411
+ * import { createWalletClient, custom } from 'viem'
412
+ * import { mainnet } from 'viem/chains'
413
+ *
414
+ * const client = createWalletClient({
415
+ * chain: mainnet,
416
+ * transport: custom(window.ethereum),
417
+ * })
418
+ * const request = await client.prepareTransactionRequest({
419
+ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
420
+ * to: '0x0000000000000000000000000000000000000000',
421
+ * value: 1n,
422
+ * })
423
+ * const signature = await client.signTransaction(request)
424
+ *
425
+ * @example
426
+ * // Account Hoisting
427
+ * import { createWalletClient, http } from 'viem'
428
+ * import { privateKeyToAccount } from 'viem/accounts'
429
+ * import { mainnet } from 'viem/chains'
430
+ *
431
+ * const client = createWalletClient({
432
+ * account: privateKeyToAccount('0x…'),
433
+ * chain: mainnet,
434
+ * transport: custom(window.ethereum),
435
+ * })
436
+ * const request = await client.prepareTransactionRequest({
437
+ * to: '0x0000000000000000000000000000000000000000',
438
+ * value: 1n,
439
+ * })
440
+ * const signature = await client.signTransaction(request)
441
+ */
442
+ signTransaction: <TChainOverride extends Chain | undefined,>(
443
+ args: SignTransactionParameters<TChain, TAccount, TChainOverride>,
444
+ ) => Promise<SignTransactionReturnType>
316
445
  /**
317
446
  * Signs typed data and calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`.
318
447
  *
@@ -536,10 +665,14 @@ export function walletActions<
536
665
  getAddresses: () => getAddresses(client),
537
666
  getChainId: () => getChainId(client),
538
667
  getPermissions: () => getPermissions(client),
668
+ prepareTransactionRequest: (args) =>
669
+ prepareTransactionRequest(client as any, args as any),
539
670
  requestAddresses: () => requestAddresses(client),
540
671
  requestPermissions: (args) => requestPermissions(client, args),
672
+ sendRawTransaction: (args) => sendRawTransaction(client, args),
541
673
  sendTransaction: (args) => sendTransaction(client, args),
542
674
  signMessage: (args) => signMessage(client, args),
675
+ signTransaction: (args) => signTransaction(client, args),
543
676
  signTypedData: (args) => signTypedData(client, args),
544
677
  switchChain: (args) => switchChain(client, args),
545
678
  watchAsset: (args) => watchAsset(client, args),
package/src/errors/rpc.ts CHANGED
@@ -60,7 +60,7 @@ export type ProviderRpcErrorCode =
60
60
  | 4200 // Unsupported Method
61
61
  | 4900 // Disconnected
62
62
  | 4901 // Chain Disconnected
63
- | 4902 // Chain Not Recongnized
63
+ | 4902 // Chain Not Recognized
64
64
 
65
65
  /**
66
66
  * Error subclass implementing Ethereum Provider errors per EIP-1193.
@@ -1 +1 @@
1
- export const version = '1.7.0'
1
+ export const version = '1.8.1'
package/src/index.ts CHANGED
@@ -203,6 +203,12 @@ export type {
203
203
  SendTransactionParameters,
204
204
  SendTransactionReturnType,
205
205
  } from './actions/wallet/sendTransaction.js'
206
+ export type {
207
+ PrepareTransactionRequestParameters,
208
+ PrepareTransactionRequestReturnType,
209
+ /** @deprecated import `prepareTransactionRequest` from `viem/actions` instead. */
210
+ prepareTransactionRequest as prepareRequest,
211
+ } from './actions/wallet/prepareTransactionRequest.js'
206
212
  export type {
207
213
  SendUnsignedTransactionParameters,
208
214
  SendUnsignedTransactionReturnType,
@@ -740,6 +746,7 @@ export {
740
746
  type FormattedTransactionRequest,
741
747
  defineTransactionRequest,
742
748
  formatTransactionRequest,
749
+ rpcTransactionType,
743
750
  } from './utils/formatters/transactionRequest.js'
744
751
  export {
745
752
  type GetAbiItemParameters,
@@ -862,7 +869,6 @@ export { parseEther } from './utils/unit/parseEther.js'
862
869
  export { parseGwei } from './utils/unit/parseGwei.js'
863
870
  export { parseTransaction } from './utils/transaction/parseTransaction.js'
864
871
  export { parseUnits } from './utils/unit/parseUnits.js'
865
- export { prepareRequest } from './utils/transaction/prepareRequest.js'
866
872
  export { serializeAccessList } from './utils/transaction/serializeAccessList.js'
867
873
  export {
868
874
  serializeTransaction,
@@ -1,6 +1,7 @@
1
1
  import type { Address } from 'abitype'
2
2
 
3
3
  import type { EstimateFeesPerGasReturnType } from '../actions/public/estimateFeesPerGas.js'
4
+ import type { PrepareTransactionRequestParameters } from '../actions/wallet/prepareTransactionRequest.js'
4
5
  import type { Client } from '../clients/createClient.js'
5
6
  import type { Transport } from '../clients/transports/createTransport.js'
6
7
  import type { Account } from '../types/account.js'
@@ -11,7 +12,6 @@ import type {
11
12
  } from '../types/transaction.js'
12
13
  import type { IsUndefined, Prettify } from '../types/utils.js'
13
14
  import type { FormattedBlock } from '../utils/formatters/block.js'
14
- import type { PrepareRequestParameters } from '../utils/transaction/prepareRequest.js'
15
15
  import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
16
16
 
17
17
  export type Chain<
@@ -112,7 +112,7 @@ export type ChainFeesFnParameters<
112
112
  * is outside of a transaction request context (e.g. a direct call to
113
113
  * the `estimateFeesPerGas` Action).
114
114
  */
115
- request?: PrepareRequestParameters<
115
+ request?: PrepareTransactionRequestParameters<
116
116
  Omit<Chain, 'formatters'> & { formatters: formatters },
117
117
  Account | undefined,
118
118
  undefined
@@ -639,7 +639,7 @@ export type PublicRpcSchema = [
639
639
  ReturnType: string
640
640
  },
641
641
  /**
642
- * @description Sends and already-signed transaction to the network
642
+ * @description Sends a **signed** transaction to the network
643
643
  * @link https://eips.ethereum.org/EIPS/eip-1474
644
644
  * @example
645
645
  * provider.request({ method: 'eth_sendRawTransaction', params: ['0x...'] })
@@ -1,6 +1,9 @@
1
- import { type ByteArray, type Hex, isHex, toBytes } from '../../index.js'
2
1
  import { equalBytes } from '@noble/curves/abstract/utils'
3
2
 
3
+ import type { ByteArray, Hex } from '../../types/misc.js'
4
+ import { toBytes } from '../encoding/toBytes.js'
5
+ import { isHex } from './isHex.js'
6
+
4
7
  export function isBytesEqual(a_: ByteArray | Hex, b_: ByteArray | Hex) {
5
8
  const a = isHex(a_) ? toBytes(a_) : a_
6
9
  const b = isHex(b_) ? toBytes(b_) : b_
@@ -1,4 +1,4 @@
1
- import type { Hex } from '../../index.js'
1
+ import type { Hex } from '../../types/misc.js'
2
2
 
3
3
  export function encodeLabelhash(hash: Hex): `[${string}]` {
4
4
  return `[${hash.slice(2)}]`
@@ -1,5 +1,5 @@
1
- import type { Hex } from '../../index.js'
2
- import { isHex } from '../index.js'
1
+ import type { Hex } from '../../types/misc.js'
2
+ import { isHex } from '../data/isHex.js'
3
3
 
4
4
  export function encodedLabelToLabelhash(label: string): Hex | null {
5
5
  if (label.length !== 66) return null