viem 1.19.1 → 1.19.4
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/CHANGELOG.md +24 -0
- package/_cjs/actions/ens/getEnsAddress.js +1 -1
- package/_cjs/actions/ens/getEnsAddress.js.map +1 -1
- package/_cjs/actions/ens/getEnsAvatar.js +1 -1
- package/_cjs/actions/ens/getEnsAvatar.js.map +1 -1
- package/_cjs/actions/ens/getEnsName.js +1 -1
- package/_cjs/actions/ens/getEnsName.js.map +1 -1
- package/_cjs/actions/ens/getEnsResolver.js +1 -1
- package/_cjs/actions/ens/getEnsResolver.js.map +1 -1
- package/_cjs/actions/ens/getEnsText.js +1 -1
- package/_cjs/actions/ens/getEnsText.js.map +1 -1
- package/_cjs/actions/getContract.js +7 -7
- package/_cjs/actions/getContract.js.map +1 -1
- package/_cjs/actions/public/estimateContractGas.js +1 -1
- package/_cjs/actions/public/estimateContractGas.js.map +1 -1
- package/_cjs/actions/public/estimateFeesPerGas.js +5 -2
- package/_cjs/actions/public/estimateFeesPerGas.js.map +1 -1
- package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js +5 -3
- package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/_cjs/actions/public/getContractEvents.js +1 -1
- package/_cjs/actions/public/getContractEvents.js.map +1 -1
- package/_cjs/actions/public/getTransactionConfirmations.js +4 -2
- package/_cjs/actions/public/getTransactionConfirmations.js.map +1 -1
- package/_cjs/actions/public/multicall.js +1 -1
- package/_cjs/actions/public/multicall.js.map +1 -1
- package/_cjs/actions/public/readContract.js +1 -1
- package/_cjs/actions/public/readContract.js.map +1 -1
- package/_cjs/actions/public/simulateContract.js +1 -1
- package/_cjs/actions/public/simulateContract.js.map +1 -1
- package/_cjs/actions/public/verifyHash.js +1 -1
- package/_cjs/actions/public/verifyHash.js.map +1 -1
- package/_cjs/actions/public/waitForTransactionReceipt.js +5 -5
- package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_cjs/actions/public/watchBlockNumber.js +1 -1
- package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/_cjs/actions/public/watchBlocks.js +2 -2
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +7 -6
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +7 -6
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/public/watchPendingTransactions.js +5 -4
- package/_cjs/actions/public/watchPendingTransactions.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +3 -3
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendTransaction.js +4 -4
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/signTransaction.js +1 -1
- package/_cjs/actions/wallet/signTransaction.js.map +1 -1
- package/_cjs/actions/wallet/writeContract.js +1 -1
- package/_cjs/actions/wallet/writeContract.js.map +1 -1
- package/_cjs/chains/definitions/aurora.js +6 -0
- package/_cjs/chains/definitions/aurora.js.map +1 -1
- package/_cjs/chains/definitions/bscTestnet.js +2 -2
- package/_cjs/chains/definitions/bscTestnet.js.map +1 -1
- package/_cjs/chains/definitions/shibarium.js +35 -0
- package/_cjs/chains/definitions/shibarium.js.map +1 -0
- package/_cjs/chains/index.js +4 -2
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/utils/encoding/toRlp.js +3 -1
- package/_cjs/utils/encoding/toRlp.js.map +1 -1
- package/_cjs/utils/getAction.js +2 -2
- package/_cjs/utils/getAction.js.map +1 -1
- package/_cjs/utils/observe.js +2 -1
- package/_cjs/utils/observe.js.map +1 -1
- package/_cjs/utils/promise/createBatchScheduler.js +8 -2
- package/_cjs/utils/promise/createBatchScheduler.js.map +1 -1
- package/_cjs/utils/unit/formatEther.js.map +1 -1
- package/_cjs/utils/unit/formatGwei.js.map +1 -1
- package/_cjs/utils/unit/formatUnits.js.map +1 -1
- package/_cjs/utils/unit/parseEther.js.map +1 -1
- package/_cjs/utils/unit/parseGwei.js.map +1 -1
- package/_cjs/utils/unit/parseUnits.js.map +1 -1
- package/_esm/actions/ens/getEnsAddress.js +1 -1
- package/_esm/actions/ens/getEnsAddress.js.map +1 -1
- package/_esm/actions/ens/getEnsAvatar.js +1 -1
- package/_esm/actions/ens/getEnsAvatar.js.map +1 -1
- package/_esm/actions/ens/getEnsName.js +1 -1
- package/_esm/actions/ens/getEnsName.js.map +1 -1
- package/_esm/actions/ens/getEnsResolver.js +1 -1
- package/_esm/actions/ens/getEnsResolver.js.map +1 -1
- package/_esm/actions/ens/getEnsText.js +1 -1
- package/_esm/actions/ens/getEnsText.js.map +1 -1
- package/_esm/actions/getContract.js +7 -7
- package/_esm/actions/getContract.js.map +1 -1
- package/_esm/actions/public/estimateContractGas.js +1 -1
- package/_esm/actions/public/estimateContractGas.js.map +1 -1
- package/_esm/actions/public/estimateFeesPerGas.js +5 -2
- package/_esm/actions/public/estimateFeesPerGas.js.map +1 -1
- package/_esm/actions/public/estimateMaxPriorityFeePerGas.js +5 -3
- package/_esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/_esm/actions/public/getContractEvents.js +1 -1
- package/_esm/actions/public/getContractEvents.js.map +1 -1
- package/_esm/actions/public/getTransactionConfirmations.js +4 -2
- package/_esm/actions/public/getTransactionConfirmations.js.map +1 -1
- package/_esm/actions/public/multicall.js +1 -1
- package/_esm/actions/public/multicall.js.map +1 -1
- package/_esm/actions/public/readContract.js +1 -1
- package/_esm/actions/public/readContract.js.map +1 -1
- package/_esm/actions/public/simulateContract.js +1 -1
- package/_esm/actions/public/simulateContract.js.map +1 -1
- package/_esm/actions/public/verifyHash.js +1 -1
- package/_esm/actions/public/verifyHash.js.map +1 -1
- package/_esm/actions/public/waitForTransactionReceipt.js +5 -5
- package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
- package/_esm/actions/public/watchBlockNumber.js +1 -1
- package/_esm/actions/public/watchBlockNumber.js.map +1 -1
- package/_esm/actions/public/watchBlocks.js +2 -2
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +7 -6
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +7 -6
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/public/watchPendingTransactions.js +5 -4
- package/_esm/actions/public/watchPendingTransactions.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +3 -3
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +4 -4
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/signTransaction.js +1 -1
- package/_esm/actions/wallet/signTransaction.js.map +1 -1
- package/_esm/actions/wallet/writeContract.js +1 -1
- package/_esm/actions/wallet/writeContract.js.map +1 -1
- package/_esm/chains/definitions/aurora.js +6 -0
- package/_esm/chains/definitions/aurora.js.map +1 -1
- package/_esm/chains/definitions/bscTestnet.js +2 -2
- package/_esm/chains/definitions/bscTestnet.js.map +1 -1
- package/_esm/chains/definitions/shibarium.js +32 -0
- package/_esm/chains/definitions/shibarium.js.map +1 -0
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/utils/encoding/toRlp.js +3 -1
- package/_esm/utils/encoding/toRlp.js.map +1 -1
- package/_esm/utils/getAction.js +12 -2
- package/_esm/utils/getAction.js.map +1 -1
- package/_esm/utils/observe.js +2 -1
- package/_esm/utils/observe.js.map +1 -1
- package/_esm/utils/promise/createBatchScheduler.js +8 -2
- package/_esm/utils/promise/createBatchScheduler.js.map +1 -1
- package/_esm/utils/unit/formatEther.js +11 -0
- package/_esm/utils/unit/formatEther.js.map +1 -1
- package/_esm/utils/unit/formatGwei.js +11 -0
- package/_esm/utils/unit/formatGwei.js.map +1 -1
- package/_esm/utils/unit/formatUnits.js +11 -0
- package/_esm/utils/unit/formatUnits.js.map +1 -1
- package/_esm/utils/unit/parseEther.js +11 -0
- package/_esm/utils/unit/parseEther.js.map +1 -1
- package/_esm/utils/unit/parseGwei.js +11 -0
- package/_esm/utils/unit/parseGwei.js.map +1 -1
- package/_esm/utils/unit/parseUnits.js +11 -0
- package/_esm/utils/unit/parseUnits.js.map +1 -1
- package/_types/actions/ens/getEnsAddress.d.ts.map +1 -1
- package/_types/actions/ens/getEnsAvatar.d.ts.map +1 -1
- package/_types/actions/ens/getEnsName.d.ts.map +1 -1
- package/_types/actions/ens/getEnsResolver.d.ts.map +1 -1
- package/_types/actions/ens/getEnsText.d.ts.map +1 -1
- package/_types/actions/getContract.d.ts +8 -8
- package/_types/actions/getContract.d.ts.map +1 -1
- package/_types/actions/public/estimateContractGas.d.ts.map +1 -1
- package/_types/actions/public/estimateFeesPerGas.d.ts.map +1 -1
- package/_types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -1
- package/_types/actions/public/getContractEvents.d.ts.map +1 -1
- package/_types/actions/public/getTransactionConfirmations.d.ts.map +1 -1
- package/_types/actions/public/multicall.d.ts.map +1 -1
- package/_types/actions/public/readContract.d.ts.map +1 -1
- package/_types/actions/public/simulateContract.d.ts.map +1 -1
- package/_types/actions/public/verifyHash.d.ts.map +1 -1
- package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
- package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/_types/actions/public/watchBlocks.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/actions/public/watchPendingTransactions.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/writeContract.d.ts.map +1 -1
- package/_types/chains/definitions/aurora.d.ts +6 -0
- package/_types/chains/definitions/aurora.d.ts.map +1 -1
- package/_types/chains/definitions/bscTestnet.d.ts +2 -2
- package/_types/chains/definitions/shibarium.d.ts +35 -0
- package/_types/chains/definitions/shibarium.d.ts.map +1 -0
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/types/ens.d.ts +1 -1
- package/_types/types/ens.d.ts.map +1 -1
- package/_types/utils/formatters/block.d.ts +2 -2
- package/_types/utils/formatters/block.d.ts.map +1 -1
- package/_types/utils/formatters/formatter.d.ts +1 -1
- package/_types/utils/formatters/transaction.d.ts +2 -2
- package/_types/utils/formatters/transaction.d.ts.map +1 -1
- package/_types/utils/formatters/transactionReceipt.d.ts +1 -1
- package/_types/utils/formatters/transactionRequest.d.ts +1 -1
- package/_types/utils/getAction.d.ts +8 -1
- package/_types/utils/getAction.d.ts.map +1 -1
- package/_types/utils/promise/createBatchScheduler.d.ts.map +1 -1
- package/_types/utils/unit/formatEther.d.ts +11 -0
- package/_types/utils/unit/formatEther.d.ts.map +1 -1
- package/_types/utils/unit/formatGwei.d.ts +11 -0
- package/_types/utils/unit/formatGwei.d.ts.map +1 -1
- package/_types/utils/unit/formatUnits.d.ts +11 -0
- package/_types/utils/unit/formatUnits.d.ts.map +1 -1
- package/_types/utils/unit/parseEther.d.ts +11 -0
- package/_types/utils/unit/parseEther.d.ts.map +1 -1
- package/_types/utils/unit/parseGwei.d.ts +11 -0
- package/_types/utils/unit/parseGwei.d.ts.map +1 -1
- package/_types/utils/unit/parseUnits.d.ts +11 -0
- package/_types/utils/unit/parseUnits.d.ts.map +1 -1
- package/actions/ens/getEnsAddress.ts +1 -0
- package/actions/ens/getEnsAvatar.ts +1 -0
- package/actions/ens/getEnsName.ts +1 -0
- package/actions/ens/getEnsResolver.ts +1 -0
- package/actions/ens/getEnsText.ts +1 -0
- package/actions/getContract.ts +23 -16
- package/actions/public/estimateContractGas.ts +1 -0
- package/actions/public/estimateFeesPerGas.ts +5 -2
- package/actions/public/estimateMaxPriorityFeePerGas.ts +5 -3
- package/actions/public/getContractEvents.ts +1 -0
- package/actions/public/getTransactionConfirmations.ts +4 -2
- package/actions/public/multicall.ts +1 -0
- package/actions/public/readContract.ts +1 -0
- package/actions/public/simulateContract.ts +1 -0
- package/actions/public/verifyHash.ts +1 -0
- package/actions/public/waitForTransactionReceipt.ts +9 -1
- package/actions/public/watchBlockNumber.ts +1 -0
- package/actions/public/watchBlocks.ts +2 -0
- package/actions/public/watchContractEvent.ts +19 -4
- package/actions/public/watchEvent.ts +19 -4
- package/actions/public/watchPendingTransactions.ts +13 -3
- package/actions/wallet/prepareTransactionRequest.ts +7 -1
- package/actions/wallet/sendTransaction.ts +5 -2
- package/actions/wallet/signTransaction.ts +1 -1
- package/actions/wallet/writeContract.ts +1 -0
- package/chains/definitions/aurora.ts +6 -0
- package/chains/definitions/bscTestnet.ts +2 -2
- package/chains/definitions/shibarium.ts +32 -0
- package/chains/index.ts +1 -0
- package/clients/createClient.ts +1 -1
- package/errors/version.ts +1 -1
- package/package.json +2 -2
- package/types/ens.ts +1 -1
- package/utils/encoding/toRlp.ts +3 -1
- package/utils/formatters/block.ts +1 -1
- package/utils/formatters/formatter.ts +1 -1
- package/utils/formatters/transaction.ts +1 -1
- package/utils/getAction.ts +11 -1
- package/utils/observe.ts +1 -1
- package/utils/promise/createBatchScheduler.ts +8 -4
- package/utils/unit/formatEther.ts +11 -0
- package/utils/unit/formatGwei.ts +11 -0
- package/utils/unit/formatUnits.ts +11 -0
- package/utils/unit/parseEther.ts +11 -0
- package/utils/unit/parseGwei.ts +11 -0
- package/utils/unit/parseUnits.ts +11 -0
@@ -83,7 +83,7 @@ export async function internal_estimateMaxPriorityFeePerGas<
|
|
83
83
|
): Promise<EstimateMaxPriorityFeePerGasReturnType> {
|
84
84
|
const { block: block_, chain = client.chain, request } = args || {}
|
85
85
|
if (typeof chain?.fees?.defaultPriorityFee === 'function') {
|
86
|
-
const block = block_ || (await getAction(client, getBlock)({}))
|
86
|
+
const block = block_ || (await getAction(client, getBlock, 'getBlock')({}))
|
87
87
|
return chain.fees.defaultPriorityFee({
|
88
88
|
block,
|
89
89
|
client,
|
@@ -102,8 +102,10 @@ export async function internal_estimateMaxPriorityFeePerGas<
|
|
102
102
|
// fall back to calculating it manually via `gasPrice - baseFeePerGas`.
|
103
103
|
// See: https://github.com/ethereum/pm/issues/328#:~:text=eth_maxPriorityFeePerGas%20after%20London%20will%20effectively%20return%20eth_gasPrice%20%2D%20baseFee
|
104
104
|
const [block, gasPrice] = await Promise.all([
|
105
|
-
block_
|
106
|
-
|
105
|
+
block_
|
106
|
+
? Promise.resolve(block_)
|
107
|
+
: getAction(client, getBlock, 'getBlock')({}),
|
108
|
+
getAction(client, getGasPrice, 'getGasPrice')({}),
|
107
109
|
])
|
108
110
|
|
109
111
|
if (typeof block.baseFeePerGas !== 'bigint')
|
@@ -67,8 +67,10 @@ export async function getTransactionConfirmations<
|
|
67
67
|
{ hash, transactionReceipt }: GetTransactionConfirmationsParameters<TChain>,
|
68
68
|
): Promise<GetTransactionConfirmationsReturnType> {
|
69
69
|
const [blockNumber, transaction] = await Promise.all([
|
70
|
-
getAction(client, getBlockNumber)({}),
|
71
|
-
hash
|
70
|
+
getAction(client, getBlockNumber, 'getBlockNumber')({}),
|
71
|
+
hash
|
72
|
+
? getAction(client, getTransaction, 'getBlockNumber')({ hash })
|
73
|
+
: undefined,
|
72
74
|
])
|
73
75
|
const transactionBlockNumber =
|
74
76
|
transactionReceipt?.blockNumber || transaction?.blockNumber
|
@@ -144,6 +144,7 @@ export async function waitForTransactionReceipt<
|
|
144
144
|
const _unwatch = getAction(
|
145
145
|
client,
|
146
146
|
watchBlockNumber,
|
147
|
+
'watchBlockNumber',
|
147
148
|
)({
|
148
149
|
emitMissed: true,
|
149
150
|
emitOnBegin: true,
|
@@ -185,6 +186,7 @@ export async function waitForTransactionReceipt<
|
|
185
186
|
transaction = (await getAction(
|
186
187
|
client,
|
187
188
|
getTransaction,
|
189
|
+
'getTransaction',
|
188
190
|
)({ hash })) as GetTransactionReturnType<TChain>
|
189
191
|
if (transaction.blockNumber)
|
190
192
|
blockNumber = transaction.blockNumber
|
@@ -199,7 +201,11 @@ export async function waitForTransactionReceipt<
|
|
199
201
|
}
|
200
202
|
|
201
203
|
// Get the receipt to check if it's been processed.
|
202
|
-
receipt = await getAction(
|
204
|
+
receipt = await getAction(
|
205
|
+
client,
|
206
|
+
getTransactionReceipt,
|
207
|
+
'getTransactionReceipt',
|
208
|
+
)({ hash })
|
203
209
|
|
204
210
|
// Check if we have enough confirmations. If not, continue polling.
|
205
211
|
if (
|
@@ -225,6 +231,7 @@ export async function waitForTransactionReceipt<
|
|
225
231
|
const block = await getAction(
|
226
232
|
client,
|
227
233
|
getBlock,
|
234
|
+
'getBlock',
|
228
235
|
)({
|
229
236
|
blockNumber,
|
230
237
|
includeTransactions: true,
|
@@ -245,6 +252,7 @@ export async function waitForTransactionReceipt<
|
|
245
252
|
receipt = await getAction(
|
246
253
|
client,
|
247
254
|
getTransactionReceipt,
|
255
|
+
'getTransactionReceipt',
|
248
256
|
)({
|
249
257
|
hash: replacementTransaction.hash,
|
250
258
|
})
|
@@ -144,6 +144,7 @@ export function watchBlocks<
|
|
144
144
|
const block = await getAction(
|
145
145
|
client,
|
146
146
|
getBlock,
|
147
|
+
'getBlock',
|
147
148
|
)({
|
148
149
|
blockTag,
|
149
150
|
includeTransactions,
|
@@ -160,6 +161,7 @@ export function watchBlocks<
|
|
160
161
|
const block = (await getAction(
|
161
162
|
client,
|
162
163
|
getBlock,
|
164
|
+
'getBlock',
|
163
165
|
)({
|
164
166
|
blockNumber: i,
|
165
167
|
includeTransactions,
|
@@ -191,6 +191,7 @@ export function watchContractEvent<
|
|
191
191
|
filter = (await getAction(
|
192
192
|
client,
|
193
193
|
createContractEventFilter,
|
194
|
+
'createContractEventFilter',
|
194
195
|
)({
|
195
196
|
abi,
|
196
197
|
address,
|
@@ -210,13 +211,21 @@ export function watchContractEvent<
|
|
210
211
|
try {
|
211
212
|
let logs: Log[]
|
212
213
|
if (filter) {
|
213
|
-
logs = await getAction(
|
214
|
+
logs = await getAction(
|
215
|
+
client,
|
216
|
+
getFilterChanges,
|
217
|
+
'getFilterChanges',
|
218
|
+
)({ filter })
|
214
219
|
} else {
|
215
220
|
// If the filter doesn't exist, we will fall back to use `getLogs`.
|
216
221
|
// The fall back exists because some RPC Providers do not support filters.
|
217
222
|
|
218
223
|
// Fetch the block number to use for `getLogs`.
|
219
|
-
const blockNumber = await getAction(
|
224
|
+
const blockNumber = await getAction(
|
225
|
+
client,
|
226
|
+
getBlockNumber,
|
227
|
+
'getBlockNumber',
|
228
|
+
)({})
|
220
229
|
|
221
230
|
// If the block number has changed, we will need to fetch the logs.
|
222
231
|
// If the block number doesn't exist, we are yet to reach the first poll interval,
|
@@ -225,6 +234,7 @@ export function watchContractEvent<
|
|
225
234
|
logs = await getAction(
|
226
235
|
client,
|
227
236
|
getContractEvents,
|
237
|
+
'getContractEvents',
|
228
238
|
)({
|
229
239
|
abi,
|
230
240
|
address,
|
@@ -242,7 +252,7 @@ export function watchContractEvent<
|
|
242
252
|
|
243
253
|
if (logs.length === 0) return
|
244
254
|
if (batch) emit.onLogs(logs as any)
|
245
|
-
else
|
255
|
+
else for (const log of logs) emit.onLogs([log] as any)
|
246
256
|
} catch (err) {
|
247
257
|
// If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
|
248
258
|
// Reinitalize the filter when this occurs
|
@@ -258,7 +268,12 @@ export function watchContractEvent<
|
|
258
268
|
)
|
259
269
|
|
260
270
|
return async () => {
|
261
|
-
if (filter)
|
271
|
+
if (filter)
|
272
|
+
await getAction(
|
273
|
+
client,
|
274
|
+
uninstallFilter,
|
275
|
+
'uninstallFilter',
|
276
|
+
)({ filter })
|
262
277
|
unwatch()
|
263
278
|
}
|
264
279
|
})
|
@@ -226,6 +226,7 @@ export function watchEvent<
|
|
226
226
|
filter = (await getAction(
|
227
227
|
client,
|
228
228
|
createEventFilter as any,
|
229
|
+
'createEventFilter',
|
229
230
|
)({
|
230
231
|
address,
|
231
232
|
args,
|
@@ -245,13 +246,21 @@ export function watchEvent<
|
|
245
246
|
try {
|
246
247
|
let logs: Log[]
|
247
248
|
if (filter) {
|
248
|
-
logs = await getAction(
|
249
|
+
logs = await getAction(
|
250
|
+
client,
|
251
|
+
getFilterChanges,
|
252
|
+
'getFilterChanges',
|
253
|
+
)({ filter })
|
249
254
|
} else {
|
250
255
|
// If the filter doesn't exist, we will fall back to use `getLogs`.
|
251
256
|
// The fall back exists because some RPC Providers do not support filters.
|
252
257
|
|
253
258
|
// Fetch the block number to use for `getLogs`.
|
254
|
-
const blockNumber = await getAction(
|
259
|
+
const blockNumber = await getAction(
|
260
|
+
client,
|
261
|
+
getBlockNumber,
|
262
|
+
'getBlockNumber',
|
263
|
+
)({})
|
255
264
|
|
256
265
|
// If the block number has changed, we will need to fetch the logs.
|
257
266
|
// If the block number doesn't exist, we are yet to reach the first poll interval,
|
@@ -260,6 +269,7 @@ export function watchEvent<
|
|
260
269
|
logs = await getAction(
|
261
270
|
client,
|
262
271
|
getLogs,
|
272
|
+
'getLogs',
|
263
273
|
)({
|
264
274
|
address,
|
265
275
|
args,
|
@@ -276,7 +286,7 @@ export function watchEvent<
|
|
276
286
|
|
277
287
|
if (logs.length === 0) return
|
278
288
|
if (batch) emit.onLogs(logs as any)
|
279
|
-
else
|
289
|
+
else for (const log of logs) emit.onLogs([log] as any)
|
280
290
|
} catch (err) {
|
281
291
|
// If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
|
282
292
|
// Reinitalize the filter when this occurs
|
@@ -292,7 +302,12 @@ export function watchEvent<
|
|
292
302
|
)
|
293
303
|
|
294
304
|
return async () => {
|
295
|
-
if (filter)
|
305
|
+
if (filter)
|
306
|
+
await getAction(
|
307
|
+
client,
|
308
|
+
uninstallFilter,
|
309
|
+
'uninstallFilter',
|
310
|
+
)({ filter })
|
296
311
|
unwatch()
|
297
312
|
}
|
298
313
|
})
|
@@ -129,6 +129,7 @@ export function watchPendingTransactions<
|
|
129
129
|
filter = await getAction(
|
130
130
|
client,
|
131
131
|
createPendingTransactionFilter,
|
132
|
+
'createPendingTransactionFilter',
|
132
133
|
)({})
|
133
134
|
return
|
134
135
|
} catch (err) {
|
@@ -137,10 +138,14 @@ export function watchPendingTransactions<
|
|
137
138
|
}
|
138
139
|
}
|
139
140
|
|
140
|
-
const hashes = await getAction(
|
141
|
+
const hashes = await getAction(
|
142
|
+
client,
|
143
|
+
getFilterChanges,
|
144
|
+
'getFilterChanges',
|
145
|
+
)({ filter })
|
141
146
|
if (hashes.length === 0) return
|
142
147
|
if (batch) emit.onTransactions(hashes)
|
143
|
-
else
|
148
|
+
else for (const hash of hashes) emit.onTransactions([hash])
|
144
149
|
} catch (err) {
|
145
150
|
emit.onError?.(err as Error)
|
146
151
|
}
|
@@ -152,7 +157,12 @@ export function watchPendingTransactions<
|
|
152
157
|
)
|
153
158
|
|
154
159
|
return async () => {
|
155
|
-
if (filter)
|
160
|
+
if (filter)
|
161
|
+
await getAction(
|
162
|
+
client,
|
163
|
+
uninstallFilter,
|
164
|
+
'uninstallFilter',
|
165
|
+
)({ filter })
|
156
166
|
unwatch()
|
157
167
|
}
|
158
168
|
})
|
@@ -130,7 +130,11 @@ export async function prepareTransactionRequest<
|
|
130
130
|
if (!account_) throw new AccountNotFoundError()
|
131
131
|
const account = parseAccount(account_)
|
132
132
|
|
133
|
-
const block = await getAction(
|
133
|
+
const block = await getAction(
|
134
|
+
client,
|
135
|
+
getBlock,
|
136
|
+
'getBlock',
|
137
|
+
)({ blockTag: 'latest' })
|
134
138
|
|
135
139
|
const request = { ...args, from: account.address }
|
136
140
|
|
@@ -138,6 +142,7 @@ export async function prepareTransactionRequest<
|
|
138
142
|
request.nonce = await getAction(
|
139
143
|
client,
|
140
144
|
getTransactionCount,
|
145
|
+
'getTransactionCount',
|
141
146
|
)({
|
142
147
|
address: account.address,
|
143
148
|
blockTag: 'pending',
|
@@ -196,6 +201,7 @@ export async function prepareTransactionRequest<
|
|
196
201
|
request.gas = await getAction(
|
197
202
|
client,
|
198
203
|
estimateGas,
|
204
|
+
'estimateGas',
|
199
205
|
)({
|
200
206
|
...request,
|
201
207
|
account: { address: account.address, type: 'json-rpc' },
|
@@ -155,7 +155,7 @@ export async function sendTransaction<
|
|
155
155
|
|
156
156
|
let chainId
|
157
157
|
if (chain !== null) {
|
158
|
-
chainId = await getAction(client, getChainId)({})
|
158
|
+
chainId = await getAction(client, getChainId, 'getChainId')({})
|
159
159
|
assertCurrentChain({
|
160
160
|
currentChainId: chainId,
|
161
161
|
chain,
|
@@ -167,6 +167,7 @@ export async function sendTransaction<
|
|
167
167
|
const request = await getAction(
|
168
168
|
client,
|
169
169
|
prepareTransactionRequest,
|
170
|
+
'prepareTransactionRequest',
|
170
171
|
)({
|
171
172
|
account,
|
172
173
|
accessList,
|
@@ -182,7 +183,8 @@ export async function sendTransaction<
|
|
182
183
|
...rest,
|
183
184
|
} as any)
|
184
185
|
|
185
|
-
if (!chainId)
|
186
|
+
if (!chainId)
|
187
|
+
chainId = await getAction(client, getChainId, 'getChainId')({})
|
186
188
|
|
187
189
|
const serializer = chain?.serializers?.transaction
|
188
190
|
const serializedTransaction = (await account.signTransaction(
|
@@ -195,6 +197,7 @@ export async function sendTransaction<
|
|
195
197
|
return await getAction(
|
196
198
|
client,
|
197
199
|
sendRawTransaction,
|
200
|
+
'sendRawTransaction',
|
198
201
|
)({
|
199
202
|
serializedTransaction,
|
200
203
|
})
|
@@ -128,7 +128,7 @@ export async function signTransaction<
|
|
128
128
|
...args,
|
129
129
|
})
|
130
130
|
|
131
|
-
const chainId = await getAction(client, getChainId)({})
|
131
|
+
const chainId = await getAction(client, getChainId, 'getChainId')({})
|
132
132
|
if (chain !== null)
|
133
133
|
assertCurrentChain({
|
134
134
|
currentChainId: chainId,
|
@@ -18,4 +18,10 @@ export const aurora = /*#__PURE__*/ defineChain({
|
|
18
18
|
etherscan: { name: 'Aurorascan', url: 'https://aurorascan.dev' },
|
19
19
|
default: { name: 'Aurorascan', url: 'https://aurorascan.dev' },
|
20
20
|
},
|
21
|
+
contracts: {
|
22
|
+
multicall3: {
|
23
|
+
address: '0xca11bde05977b3631167028862be2a173976ca11',
|
24
|
+
blockCreated: 62907816,
|
25
|
+
},
|
26
|
+
},
|
21
27
|
})
|
@@ -10,8 +10,8 @@ export const bscTestnet = /*#__PURE__*/ defineChain({
|
|
10
10
|
symbol: 'tBNB',
|
11
11
|
},
|
12
12
|
rpcUrls: {
|
13
|
-
default: { http: ['https://data-seed-prebsc-1-s1.
|
14
|
-
public: { http: ['https://data-seed-prebsc-1-s1.
|
13
|
+
default: { http: ['https://data-seed-prebsc-1-s1.bnbchain.org:8545'] },
|
14
|
+
public: { http: ['https://data-seed-prebsc-1-s1.bnbchain.org:8545'] },
|
15
15
|
},
|
16
16
|
blockExplorers: {
|
17
17
|
etherscan: { name: 'BscScan', url: 'https://testnet.bscscan.com' },
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { defineChain } from '../../utils/chain/defineChain.js'
|
2
|
+
|
3
|
+
export const shibarium = /*#__PURE__*/ defineChain({
|
4
|
+
id: 109,
|
5
|
+
name: 'Shibarium',
|
6
|
+
network: 'shibarium',
|
7
|
+
nativeCurrency: { name: 'Bone', symbol: 'BONE', decimals: 18 },
|
8
|
+
rpcUrls: {
|
9
|
+
default: {
|
10
|
+
http: ['https://rpc.shibrpc.com'],
|
11
|
+
},
|
12
|
+
public: {
|
13
|
+
http: ['https://rpc.shibrpc.com'],
|
14
|
+
},
|
15
|
+
},
|
16
|
+
blockExplorers: {
|
17
|
+
etherscan: {
|
18
|
+
name: 'Blockscout',
|
19
|
+
url: 'https://shibariumscan.io',
|
20
|
+
},
|
21
|
+
default: {
|
22
|
+
name: 'Blockscout',
|
23
|
+
url: 'https://shibariumscan.io',
|
24
|
+
},
|
25
|
+
},
|
26
|
+
contracts: {
|
27
|
+
multicall3: {
|
28
|
+
address: '0x864Bf681ADD6052395188A89101A1B37d3B4C961',
|
29
|
+
blockCreated: 265900,
|
30
|
+
},
|
31
|
+
},
|
32
|
+
})
|
package/chains/index.ts
CHANGED
@@ -137,6 +137,7 @@ export { songbird } from './definitions/songbird.js'
|
|
137
137
|
export { songbirdTestnet } from './definitions/songbirdTestnet.js'
|
138
138
|
export { spicy } from './definitions/spicy.js'
|
139
139
|
export { shardeumSphinx } from './definitions/shardeumSphinx.js'
|
140
|
+
export { shibarium } from './definitions/shibarium.js'
|
140
141
|
export { syscoin } from './definitions/syscoin.js'
|
141
142
|
export { syscoinTestnet } from './definitions/syscoinTestnet.js'
|
142
143
|
export { taraxa } from './definitions/taraxa.js'
|
package/clients/createClient.ts
CHANGED
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '1.19.
|
1
|
+
export const version = '1.19.2'
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "viem",
|
3
3
|
"description": "TypeScript Interface for Ethereum",
|
4
|
-
"version": "1.19.
|
4
|
+
"version": "1.19.4",
|
5
5
|
"main": "./_cjs/index.js",
|
6
6
|
"module": "./_esm/index.js",
|
7
7
|
"types": "./_types/index.d.ts",
|
@@ -133,7 +133,7 @@
|
|
133
133
|
}
|
134
134
|
},
|
135
135
|
"dependencies": {
|
136
|
-
"@adraffy/ens-normalize": "1.
|
136
|
+
"@adraffy/ens-normalize": "1.10.0",
|
137
137
|
"@noble/curves": "1.2.0",
|
138
138
|
"@noble/hashes": "1.3.2",
|
139
139
|
"@scure/bip32": "1.3.2",
|
package/types/ens.ts
CHANGED
package/utils/encoding/toRlp.ts
CHANGED
@@ -88,7 +88,9 @@ function getEncodableList(list: Encodable[]): Encodable {
|
|
88
88
|
else if (sizeOfBodyLength === 3) cursor.pushUint24(bodyLength)
|
89
89
|
else cursor.pushUint32(bodyLength)
|
90
90
|
}
|
91
|
-
|
91
|
+
for (const { encode } of list) {
|
92
|
+
encode(cursor)
|
93
|
+
}
|
92
94
|
},
|
93
95
|
}
|
94
96
|
}
|
@@ -28,7 +28,7 @@ export type FormattedBlock<
|
|
28
28
|
_ExcludedPendingDependencies extends string = BlockPendingDependencies &
|
29
29
|
ExtractChainFormatterExclude<TChain, 'block'>,
|
30
30
|
_Formatted = Omit<_FormatterReturnType, BlockPendingDependencies> & {
|
31
|
-
[
|
31
|
+
[_key in _ExcludedPendingDependencies]: never
|
32
32
|
} & Pick<
|
33
33
|
Block<bigint, TIncludeTransactions, TBlockTag>,
|
34
34
|
BlockPendingDependencies
|
@@ -31,7 +31,7 @@ export function defineFormatter<TType extends string, TParameters, TReturnType>(
|
|
31
31
|
...formatted,
|
32
32
|
...overrides(args),
|
33
33
|
} as Prettify<Assign<TReturnType, TOverrideReturnType>> & {
|
34
|
-
[
|
34
|
+
[_key in TExclude[number]]: never
|
35
35
|
}
|
36
36
|
},
|
37
37
|
type,
|
@@ -29,7 +29,7 @@ export type FormattedTransaction<
|
|
29
29
|
_ExcludedPendingDependencies extends string = TransactionPendingDependencies &
|
30
30
|
ExtractChainFormatterExclude<TChain, 'transaction'>,
|
31
31
|
> = UnionOmit<_FormatterReturnType, TransactionPendingDependencies> & {
|
32
|
-
[
|
32
|
+
[_key in _ExcludedPendingDependencies]: never
|
33
33
|
} & Pick<
|
34
34
|
Transaction<bigint, number, TBlockTag extends 'pending' ? true : false>,
|
35
35
|
TransactionPendingDependencies
|
package/utils/getAction.ts
CHANGED
@@ -1,13 +1,23 @@
|
|
1
1
|
import type { Client } from '../clients/createClient.js'
|
2
2
|
|
3
|
+
/**
|
4
|
+
* Retrieves and returns an action from the client (if exists), and falls
|
5
|
+
* back to the tree-shakable action.
|
6
|
+
*
|
7
|
+
* Useful for extracting overridden actions from a client (ie. if a consumer
|
8
|
+
* wants to override the `sendTransaction` implementation).
|
9
|
+
*/
|
3
10
|
export function getAction<params extends {}, returnType extends {}>(
|
4
11
|
client: Client,
|
5
12
|
action: (_: any, params: params) => returnType,
|
13
|
+
// Some minifiers drop `Function.prototype.name`, meaning that `action.name`
|
14
|
+
// will not work. For that case, the consumer needs to pass the name explicitly.
|
15
|
+
name: string,
|
6
16
|
) {
|
7
17
|
return (params: params): returnType =>
|
8
18
|
(
|
9
19
|
client as Client & {
|
10
20
|
[key: string]: (params: params) => returnType
|
11
21
|
}
|
12
|
-
)[action.name]?.(params) ?? action(client, params)
|
22
|
+
)[action.name || name]?.(params) ?? action(client, params)
|
13
23
|
}
|
package/utils/observe.ts
CHANGED
@@ -61,7 +61,7 @@ export function observe<TCallbacks extends Callbacks>(
|
|
61
61
|
) => {
|
62
62
|
const listeners = getListeners()
|
63
63
|
if (listeners.length === 0) return
|
64
|
-
|
64
|
+
for (const listener of listeners) listener.fns[key]?.(...args)
|
65
65
|
}) as TCallbacks[Extract<keyof TCallbacks, string>]
|
66
66
|
}
|
67
67
|
|
@@ -66,12 +66,16 @@ export function createBatchScheduler<
|
|
66
66
|
fn(args as TParameters[])
|
67
67
|
.then((data) => {
|
68
68
|
if (sort && Array.isArray(data)) data.sort(sort)
|
69
|
-
|
70
|
-
pendingPromise
|
71
|
-
|
69
|
+
for (let i = 0; i < scheduler.length; i++) {
|
70
|
+
const { pendingPromise } = scheduler[i]
|
71
|
+
pendingPromise.resolve?.([data[i], data])
|
72
|
+
}
|
72
73
|
})
|
73
74
|
.catch((err) => {
|
74
|
-
|
75
|
+
for (let i = 0; i < scheduler.length; i++) {
|
76
|
+
const { pendingPromise } = scheduler[i]
|
77
|
+
pendingPromise.reject?.(err)
|
78
|
+
}
|
75
79
|
})
|
76
80
|
}
|
77
81
|
|
@@ -4,6 +4,17 @@ import { type FormatUnitsErrorType, formatUnits } from './formatUnits.js'
|
|
4
4
|
|
5
5
|
export type FormatEtherErrorType = FormatUnitsErrorType
|
6
6
|
|
7
|
+
/**
|
8
|
+
* Converts numerical wei to a string representation of ether.
|
9
|
+
*
|
10
|
+
* - Docs: https://viem.sh/docs/utilities/formatEther.html
|
11
|
+
*
|
12
|
+
* @example
|
13
|
+
* import { formatEther } from 'viem'
|
14
|
+
*
|
15
|
+
* formatEther(1000000000000000000n)
|
16
|
+
* // '1'
|
17
|
+
*/
|
7
18
|
export function formatEther(wei: bigint, unit: 'wei' | 'gwei' = 'wei') {
|
8
19
|
return formatUnits(wei, etherUnits[unit])
|
9
20
|
}
|
package/utils/unit/formatGwei.ts
CHANGED
@@ -4,6 +4,17 @@ import { type FormatUnitsErrorType, formatUnits } from './formatUnits.js'
|
|
4
4
|
|
5
5
|
export type FormatGweiErrorType = FormatUnitsErrorType
|
6
6
|
|
7
|
+
/**
|
8
|
+
* Converts numerical wei to a string representation of gwei.
|
9
|
+
*
|
10
|
+
* - Docs: https://viem.sh/docs/utilities/formatGwei.html
|
11
|
+
*
|
12
|
+
* @example
|
13
|
+
* import { formatGwei } from 'viem'
|
14
|
+
*
|
15
|
+
* formatGwei(1000000000n)
|
16
|
+
* // '1'
|
17
|
+
*/
|
7
18
|
export function formatGwei(wei: bigint, unit: 'wei' = 'wei') {
|
8
19
|
return formatUnits(wei, gweiUnits[unit])
|
9
20
|
}
|