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.
- package/README.md +6 -0
- package/dist/cjs/actions/index.js +8 -2
- package/dist/cjs/actions/index.js.map +1 -1
- package/dist/cjs/actions/public/estimateFeesPerGas.js +3 -2
- package/dist/cjs/actions/public/estimateFeesPerGas.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js +2 -2
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js +3 -3
- package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js +10 -7
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/{utils/transaction/prepareRequest.js → actions/wallet/prepareTransactionRequest.js} +19 -10
- package/dist/cjs/actions/wallet/prepareTransactionRequest.js.map +1 -0
- package/dist/cjs/actions/wallet/sendRawTransaction.js +11 -0
- package/dist/cjs/actions/wallet/sendRawTransaction.js.map +1 -0
- package/dist/cjs/actions/wallet/sendTransaction.js +6 -6
- package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/cjs/actions/wallet/signTransaction.js +47 -0
- package/dist/cjs/actions/wallet/signTransaction.js.map +1 -0
- package/dist/cjs/chains/celo/formatters.js +4 -1
- package/dist/cjs/chains/celo/formatters.js.map +1 -1
- package/dist/cjs/chains/index.js +3 -2
- package/dist/cjs/chains/index.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js +4 -0
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/clients/decorators/wallet.js +6 -0
- package/dist/cjs/clients/decorators/wallet.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js +4 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/data/isBytesEqual.js +4 -3
- package/dist/cjs/utils/data/isBytesEqual.js.map +1 -1
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +2 -2
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionRequest.js +9 -1
- package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/cjs/utils/index.js +3 -3
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/esm/actions/index.js +3 -0
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/actions/public/estimateFeesPerGas.js +3 -2
- package/dist/esm/actions/public/estimateFeesPerGas.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js +2 -2
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js +3 -3
- package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js +5 -2
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/{utils/transaction/prepareRequest.js → actions/wallet/prepareTransactionRequest.js} +58 -9
- package/dist/esm/actions/wallet/prepareTransactionRequest.js.map +1 -0
- package/dist/esm/actions/wallet/sendRawTransaction.js +31 -0
- package/dist/esm/actions/wallet/sendRawTransaction.js.map +1 -0
- package/dist/esm/actions/wallet/sendTransaction.js +6 -6
- package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/esm/actions/wallet/signTransaction.js +87 -0
- package/dist/esm/actions/wallet/signTransaction.js.map +1 -0
- package/dist/esm/chains/celo/formatters.js +4 -1
- package/dist/esm/chains/celo/formatters.js.map +1 -1
- package/dist/esm/chains/index.js +1 -0
- package/dist/esm/chains/index.js.map +1 -1
- package/dist/esm/clients/decorators/public.js +4 -0
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/clients/decorators/wallet.js +6 -0
- package/dist/esm/clients/decorators/wallet.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/data/isBytesEqual.js +2 -1
- package/dist/esm/utils/data/isBytesEqual.js.map +1 -1
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js +1 -1
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -1
- package/dist/esm/utils/formatters/transactionRequest.js +8 -0
- package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/esm/utils/index.js +3 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/types/actions/index.d.ts +3 -0
- package/dist/types/actions/index.d.ts.map +1 -1
- package/dist/types/actions/public/estimateFeesPerGas.d.ts +2 -2
- package/dist/types/actions/public/estimateFeesPerGas.d.ts.map +1 -1
- package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts +4 -2
- package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/wallet/prepareTransactionRequest.d.ts +52 -0
- package/dist/types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -0
- package/dist/types/actions/wallet/sendRawTransaction.d.ts +38 -0
- package/dist/types/actions/wallet/sendRawTransaction.d.ts.map +1 -0
- package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/dist/types/actions/wallet/signTransaction.d.ts +55 -0
- package/dist/types/actions/wallet/signTransaction.d.ts.map +1 -0
- package/dist/types/chains/celo/formatters.d.ts +303 -5
- package/dist/types/chains/celo/formatters.d.ts.map +1 -1
- package/dist/types/chains/celo/types.d.ts +43 -17
- package/dist/types/chains/celo/types.d.ts.map +1 -1
- package/dist/types/chains/index.d.ts +958 -19
- package/dist/types/chains/index.d.ts.map +1 -1
- package/dist/types/chains/utils.d.ts +1 -1
- package/dist/types/chains/utils.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +66 -0
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/clients/decorators/wallet.d.ts +111 -0
- package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/chain.d.ts +2 -2
- package/dist/types/types/chain.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +1 -1
- package/dist/types/utils/data/isBytesEqual.d.ts +1 -1
- package/dist/types/utils/data/isBytesEqual.d.ts.map +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -1
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +1 -1
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionRequest.d.ts +5 -0
- package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +3 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/actions/index.ts +15 -0
- package/src/actions/public/estimateFeesPerGas.ts +6 -4
- package/src/actions/public/estimateGas.ts +5 -5
- package/src/actions/public/estimateMaxPriorityFeePerGas.ts +7 -5
- package/src/actions/public/watchContractEvent.ts +9 -6
- package/src/{utils/transaction/prepareRequest.ts → actions/wallet/prepareTransactionRequest.ts} +80 -36
- package/src/actions/wallet/sendRawTransaction.ts +48 -0
- package/src/actions/wallet/sendTransaction.ts +6 -6
- package/src/actions/wallet/signTransaction.ts +137 -0
- package/src/chains/celo/formatters.ts +11 -12
- package/src/chains/celo/types.ts +86 -30
- package/src/chains/index.ts +1 -0
- package/src/chains/utils.ts +4 -4
- package/src/clients/decorators/public.ts +81 -0
- package/src/clients/decorators/wallet.ts +133 -0
- package/src/errors/rpc.ts +1 -1
- package/src/errors/version.ts +1 -1
- package/src/index.ts +7 -1
- package/src/types/chain.ts +2 -2
- package/src/types/eip1193.ts +1 -1
- package/src/utils/data/isBytesEqual.ts +4 -1
- package/src/utils/ens/encodeLabelhash.ts +1 -1
- package/src/utils/ens/encodedLabelToLabelhash.ts +2 -2
- package/src/utils/formatters/transactionRequest.ts +10 -0
- package/src/utils/index.ts +4 -1
- package/dist/cjs/utils/transaction/prepareRequest.js.map +0 -1
- package/dist/esm/utils/transaction/prepareRequest.js.map +0 -1
- package/dist/types/utils/transaction/prepareRequest.d.ts +0 -21
- 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
|
-
|
17
|
+
CeloRpcTransactionRequest,
|
18
18
|
CeloTransaction,
|
19
|
-
CeloTransactionOverrides,
|
20
19
|
CeloTransactionReceiptOverrides,
|
21
|
-
|
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:
|
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
|
-
|
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
|
package/src/chains/celo/types.ts
CHANGED
@@ -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>
|
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
|
88
|
-
|
89
|
-
|
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>
|
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
|
112
|
-
|
113
|
-
|
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,
|
package/src/chains/index.ts
CHANGED
@@ -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)
|
package/src/chains/utils.ts
CHANGED
@@ -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
|
63
|
+
| 4902 // Chain Not Recognized
|
64
64
|
|
65
65
|
/**
|
66
66
|
* Error subclass implementing Ethereum Provider errors per EIP-1193.
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '1.
|
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,
|
package/src/types/chain.ts
CHANGED
@@ -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?:
|
115
|
+
request?: PrepareTransactionRequestParameters<
|
116
116
|
Omit<Chain, 'formatters'> & { formatters: formatters },
|
117
117
|
Account | undefined,
|
118
118
|
undefined
|
package/src/types/eip1193.ts
CHANGED
@@ -639,7 +639,7 @@ export type PublicRpcSchema = [
|
|
639
639
|
ReturnType: string
|
640
640
|
},
|
641
641
|
/**
|
642
|
-
* @description Sends
|
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,5 +1,5 @@
|
|
1
|
-
import type { Hex } from '../../
|
2
|
-
import { isHex } from '../
|
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
|