viem 0.3.35 → 0.3.37
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/LICENSE +1 -1
- package/README.md +12 -0
- package/dist/cjs/actions/getContract.js +20 -16
- package/dist/cjs/actions/getContract.js.map +1 -1
- package/dist/cjs/actions/public/estimateContractGas.js +1 -1
- package/dist/cjs/actions/public/estimateContractGas.js.map +1 -1
- package/dist/cjs/actions/public/estimateGas.js +3 -2
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/errors/rpc.js +8 -2
- package/dist/cjs/errors/rpc.js.map +1 -1
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/eip1193.js +3 -3
- package/dist/cjs/types/eip1193.js.map +1 -1
- package/dist/cjs/utils/buildRequest.js.map +1 -1
- package/dist/esm/actions/getContract.js +20 -16
- package/dist/esm/actions/getContract.js.map +1 -1
- package/dist/esm/actions/public/estimateContractGas.js +1 -1
- package/dist/esm/actions/public/estimateContractGas.js.map +1 -1
- package/dist/esm/actions/public/estimateGas.js +3 -2
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/errors/rpc.js +8 -2
- package/dist/esm/errors/rpc.js.map +1 -1
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/eip1193.js +1 -1
- package/dist/esm/types/eip1193.js.map +1 -1
- package/dist/esm/utils/buildRequest.js.map +1 -1
- package/dist/types/actions/getContract.d.ts +44 -11
- package/dist/types/actions/getContract.d.ts.map +1 -1
- package/dist/types/actions/public/createBlockFilter.d.ts +1 -1
- package/dist/types/actions/public/createContractEventFilter.d.ts +1 -1
- package/dist/types/actions/public/createEventFilter.d.ts +1 -1
- package/dist/types/actions/public/createPendingTransactionFilter.d.ts +1 -1
- package/dist/types/actions/public/estimateContractGas.d.ts +5 -3
- package/dist/types/actions/public/estimateContractGas.d.ts.map +1 -1
- package/dist/types/actions/public/estimateGas.d.ts.map +1 -1
- package/dist/types/actions/public/getFilterChanges.d.ts +4 -4
- package/dist/types/actions/public/getTransaction.d.ts +1 -1
- package/dist/types/actions/public/getTransactionCount.d.ts +1 -1
- package/dist/types/actions/public/getTransactionReceipt.d.ts +1 -1
- package/dist/types/actions/public/multicall.d.ts +1 -1
- package/dist/types/actions/public/readContract.d.ts +1 -1
- package/dist/types/actions/public/simulateContract.d.ts +2 -2
- package/dist/types/actions/public/uninstallFilter.d.ts +3 -3
- package/dist/types/actions/public/watchContractEvent.d.ts +1 -1
- package/dist/types/actions/public/watchEvent.d.ts +2 -2
- package/dist/types/actions/test/setBlockTimestampInterval.d.ts +1 -1
- package/dist/types/actions/test/stopImpersonatingAccount.d.ts +1 -1
- package/dist/types/actions/wallet/deployContract.d.ts +1 -1
- package/dist/types/actions/wallet/signMessage.d.ts +2 -2
- package/dist/types/actions/wallet/writeContract.d.ts +3 -3
- package/dist/types/chains.d.ts +38 -12
- package/dist/types/chains.d.ts.map +1 -1
- package/dist/types/clients/createPublicClient.d.ts +1 -1
- package/dist/types/clients/createTestClient.d.ts +2 -2
- package/dist/types/clients/createWalletClient.d.ts +2 -2
- package/dist/types/clients/decorators/public.d.ts +22 -22
- package/dist/types/clients/decorators/test.d.ts +2 -2
- package/dist/types/clients/decorators/wallet.d.ts +6 -6
- package/dist/types/errors/rpc.d.ts +12 -8
- package/dist/types/errors/rpc.d.ts.map +1 -1
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +7 -8
- package/dist/types/types/eip1193.d.ts.map +1 -1
- package/dist/types/utils/buildRequest.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/actions/getContract.ts +105 -55
- package/src/actions/public/createBlockFilter.ts +1 -1
- package/src/actions/public/createContractEventFilter.ts +1 -1
- package/src/actions/public/createEventFilter.ts +1 -1
- package/src/actions/public/createPendingTransactionFilter.ts +1 -1
- package/src/actions/public/estimateContractGas.ts +11 -5
- package/src/actions/public/estimateGas.ts +3 -2
- package/src/actions/public/getFilterChanges.ts +4 -4
- package/src/actions/public/getTransaction.ts +1 -1
- package/src/actions/public/getTransactionCount.ts +1 -1
- package/src/actions/public/getTransactionReceipt.ts +1 -1
- package/src/actions/public/multicall.ts +1 -1
- package/src/actions/public/readContract.ts +1 -1
- package/src/actions/public/simulateContract.ts +2 -2
- package/src/actions/public/uninstallFilter.ts +3 -3
- package/src/actions/public/watchContractEvent.ts +1 -1
- package/src/actions/public/watchEvent.ts +2 -2
- package/src/actions/test/setBlockTimestampInterval.ts +1 -1
- package/src/actions/test/stopImpersonatingAccount.ts +1 -1
- package/src/actions/wallet/deployContract.ts +1 -1
- package/src/actions/wallet/signMessage.ts +2 -2
- package/src/actions/wallet/writeContract.ts +3 -3
- package/src/clients/createPublicClient.ts +1 -1
- package/src/clients/createTestClient.ts +2 -2
- package/src/clients/createWalletClient.ts +2 -2
- package/src/clients/decorators/public.ts +22 -22
- package/src/clients/decorators/test.ts +2 -2
- package/src/clients/decorators/wallet.ts +6 -6
- package/src/errors/rpc.ts +43 -15
- package/src/errors/version.ts +1 -1
- package/src/index.ts +24 -2
- package/src/types/eip1193.ts +10 -13
- package/src/utils/buildRequest.ts +5 -1
@@ -234,7 +234,7 @@ export type PublicActions<
|
|
234
234
|
*/
|
235
235
|
call: (parameters: CallParameters<TChain>) => Promise<CallReturnType>
|
236
236
|
/**
|
237
|
-
* Creates a Filter to listen for new block hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
|
237
|
+
* Creates a Filter to listen for new block hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html).
|
238
238
|
*
|
239
239
|
* - Docs: https://viem.sh/docs/actions/public/createBlockFilter.html
|
240
240
|
* - JSON-RPC Methods: [`eth_newBlockFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newBlockFilter)
|
@@ -254,7 +254,7 @@ export type PublicActions<
|
|
254
254
|
*/
|
255
255
|
createBlockFilter: () => Promise<CreateBlockFilterReturnType>
|
256
256
|
/**
|
257
|
-
* Creates a Filter to retrieve event logs that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges) or [`getFilterLogs`](https://viem.sh/docs/actions/public/getFilterLogs).
|
257
|
+
* Creates a Filter to retrieve event logs that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html) or [`getFilterLogs`](https://viem.sh/docs/actions/public/getFilterLogs.html).
|
258
258
|
*
|
259
259
|
* - Docs: https://viem.sh/docs/contract/createContractEventFilter.html
|
260
260
|
*
|
@@ -281,7 +281,7 @@ export type PublicActions<
|
|
281
281
|
args: CreateContractEventFilterParameters<TAbi, TEventName, TArgs>,
|
282
282
|
) => Promise<CreateContractEventFilterReturnType<TAbi, TEventName, TArgs>>
|
283
283
|
/**
|
284
|
-
* Creates a [`Filter`](https://viem.sh/docs/glossary/types.html#filter) to listen for new events that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
|
284
|
+
* Creates a [`Filter`](https://viem.sh/docs/glossary/types.html#filter) to listen for new events that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html).
|
285
285
|
*
|
286
286
|
* - Docs: https://viem.sh/docs/actions/public/createEventFilter.html
|
287
287
|
* - JSON-RPC Methods: [`eth_newFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter)
|
@@ -310,7 +310,7 @@ export type PublicActions<
|
|
310
310
|
args?: CreateEventFilterParameters<TAbiEvent, TAbi, TEventName, TArgs>,
|
311
311
|
) => Promise<CreateEventFilterReturnType<TAbiEvent, TAbi, TEventName, TArgs>>
|
312
312
|
/**
|
313
|
-
* Creates a Filter to listen for new pending transaction hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
|
313
|
+
* Creates a Filter to listen for new pending transaction hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html).
|
314
314
|
*
|
315
315
|
* - Docs: https://viem.sh/docs/actions/public/createPendingTransactionFilter.html
|
316
316
|
* - JSON-RPC Methods: [`eth_newPendingTransactionFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newpendingtransactionfilter)
|
@@ -335,7 +335,7 @@ export type PublicActions<
|
|
335
335
|
* - Docs: https://viem.sh/docs/contract/estimateContractGas.html
|
336
336
|
*
|
337
337
|
* @remarks
|
338
|
-
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`estimateGas` action](https://viem.sh/docs/actions/public/estimateGas) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
|
338
|
+
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public.html) to call the [`estimateGas` action](https://viem.sh/docs/actions/public/estimateGas.html) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData.html).
|
339
339
|
*
|
340
340
|
* @param args - {@link EstimateContractGasParameters}
|
341
341
|
* @returns The gas estimate (in wei). {@link EstimateContractGasReturnType}
|
@@ -719,10 +719,10 @@ export type PublicActions<
|
|
719
719
|
* @remarks
|
720
720
|
* A Filter can be created from the following actions:
|
721
721
|
*
|
722
|
-
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter)
|
723
|
-
* - [`createContractEventFilter`](https://viem.sh/docs/contract/createContractEventFilter)
|
724
|
-
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter)
|
725
|
-
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter)
|
722
|
+
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter.html)
|
723
|
+
* - [`createContractEventFilter`](https://viem.sh/docs/contract/createContractEventFilter.html)
|
724
|
+
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter.html)
|
725
|
+
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter.html)
|
726
726
|
*
|
727
727
|
* Depending on the type of filter, the return value will be different:
|
728
728
|
*
|
@@ -896,7 +896,7 @@ export type PublicActions<
|
|
896
896
|
args: GetStorageAtParameters,
|
897
897
|
) => Promise<GetStorageAtReturnType>
|
898
898
|
/**
|
899
|
-
* Returns information about a [Transaction](https://viem.sh/docs/glossary/terms#transaction) given a hash or block identifier.
|
899
|
+
* Returns information about a [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) given a hash or block identifier.
|
900
900
|
*
|
901
901
|
* - Docs: https://viem.sh/docs/actions/public/getTransaction.html
|
902
902
|
* - Example: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/fetching-transactions
|
@@ -946,7 +946,7 @@ export type PublicActions<
|
|
946
946
|
args: GetTransactionConfirmationsParameters<TChain>,
|
947
947
|
) => Promise<GetTransactionConfirmationsReturnType>
|
948
948
|
/**
|
949
|
-
* Returns the number of [Transactions](https://viem.sh/docs/glossary/terms#transaction) an Account has broadcast / sent.
|
949
|
+
* Returns the number of [Transactions](https://viem.sh/docs/glossary/terms.html#transaction) an Account has broadcast / sent.
|
950
950
|
*
|
951
951
|
* - Docs: https://viem.sh/docs/actions/public/getTransactionCount.html
|
952
952
|
* - JSON-RPC Methods: [`eth_getTransactionCount`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactioncount)
|
@@ -970,7 +970,7 @@ export type PublicActions<
|
|
970
970
|
args: GetTransactionCountParameters,
|
971
971
|
) => Promise<GetTransactionCountReturnType>
|
972
972
|
/**
|
973
|
-
* Returns the [Transaction Receipt](https://viem.sh/docs/glossary/terms#transaction-receipt) given a [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash.
|
973
|
+
* Returns the [Transaction Receipt](https://viem.sh/docs/glossary/terms.html#transaction-receipt) given a [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash.
|
974
974
|
*
|
975
975
|
* - Docs: https://viem.sh/docs/actions/public/getTransactionReceipt.html
|
976
976
|
* - Example: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/fetching-transactions
|
@@ -995,7 +995,7 @@ export type PublicActions<
|
|
995
995
|
args: GetTransactionReceiptParameters,
|
996
996
|
) => Promise<GetTransactionReceiptReturnType<TChain>>
|
997
997
|
/**
|
998
|
-
* Similar to [`readContract`](https://viem.sh/docs/contract/readContract), but batches up multiple functions on a contract in a single RPC call via the [`multicall3` contract](https://github.com/mds1/multicall).
|
998
|
+
* Similar to [`readContract`](https://viem.sh/docs/contract/readContract.html), but batches up multiple functions on a contract in a single RPC call via the [`multicall3` contract](https://github.com/mds1/multicall).
|
999
999
|
*
|
1000
1000
|
* - Docs: https://viem.sh/docs/contract/multicall.html
|
1001
1001
|
*
|
@@ -1046,7 +1046,7 @@ export type PublicActions<
|
|
1046
1046
|
* @remarks
|
1047
1047
|
* A "read-only" function (constant function) on a Solidity contract is denoted by a `view` or `pure` keyword. They can only read the state of the contract, and cannot make any changes to it. Since read-only methods do not change the state of the contract, they do not require any gas to be executed, and can be called by any user without the need to pay for gas.
|
1048
1048
|
*
|
1049
|
-
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`call` action](https://viem.sh/docs/actions/public/call) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
|
1049
|
+
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public.html) to call the [`call` action](https://viem.sh/docs/actions/public/call.html) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData.html).
|
1050
1050
|
*
|
1051
1051
|
* @param args - {@link ReadContractParameters}
|
1052
1052
|
* @returns The response from the contract. Type is inferred. {@link ReadContractReturnType}
|
@@ -1081,9 +1081,9 @@ export type PublicActions<
|
|
1081
1081
|
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts
|
1082
1082
|
*
|
1083
1083
|
* @remarks
|
1084
|
-
* This function does not require gas to execute and _**does not**_ change the state of the blockchain. It is almost identical to [`readContract`](https://viem.sh/docs/contract/readContract), but also supports contract write functions.
|
1084
|
+
* This function does not require gas to execute and _**does not**_ change the state of the blockchain. It is almost identical to [`readContract`](https://viem.sh/docs/contract/readContract.html), but also supports contract write functions.
|
1085
1085
|
*
|
1086
|
-
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`call` action](https://viem.sh/docs/actions/public/call) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
|
1086
|
+
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public.html) to call the [`call` action](https://viem.sh/docs/actions/public/call.html) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData.html).
|
1087
1087
|
*
|
1088
1088
|
* @param args - {@link SimulateContractParameters}
|
1089
1089
|
* @returns The simulation result and write request. {@link SimulateContractReturnType}
|
@@ -1127,9 +1127,9 @@ export type PublicActions<
|
|
1127
1127
|
/**
|
1128
1128
|
* Destroys a Filter that was created from one of the following Actions:
|
1129
1129
|
*
|
1130
|
-
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter)
|
1131
|
-
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter)
|
1132
|
-
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter)
|
1130
|
+
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter.html)
|
1131
|
+
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter.html)
|
1132
|
+
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter.html)
|
1133
1133
|
*
|
1134
1134
|
* - Docs: https://viem.sh/docs/actions/public/uninstallFilter.html
|
1135
1135
|
* - JSON-RPC Methods: [`eth_uninstallFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_uninstallFilter)
|
@@ -1252,7 +1252,7 @@ export type PublicActions<
|
|
1252
1252
|
* @remarks
|
1253
1253
|
* This Action will batch up all the event logs found within the [`pollingInterval`](https://viem.sh/docs/contract/watchContractEvent.html#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/contract/watchContractEvent.html#onLogs).
|
1254
1254
|
*
|
1255
|
-
* `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
|
1255
|
+
* `watchContractEvent` will attempt to create an [Event Filter](https://viem.sh/docs/contract/createContractEventFilter.html) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchContractEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs.html) instead.
|
1256
1256
|
*
|
1257
1257
|
* @param args - {@link WatchContractEventParameters}
|
1258
1258
|
* @returns A function that can be invoked to stop watching for new event logs. {@link WatchContractEventReturnType}
|
@@ -1280,7 +1280,7 @@ export type PublicActions<
|
|
1280
1280
|
args: WatchContractEventParameters<TAbi, TEventName>,
|
1281
1281
|
) => WatchContractEventReturnType
|
1282
1282
|
/**
|
1283
|
-
* Watches and returns emitted [Event Logs](https://viem.sh/docs/glossary/terms#event-log).
|
1283
|
+
* Watches and returns emitted [Event Logs](https://viem.sh/docs/glossary/terms.html#event-log).
|
1284
1284
|
*
|
1285
1285
|
* - Docs: https://viem.sh/docs/actions/public/watchEvent.html
|
1286
1286
|
* - JSON-RPC Methods:
|
@@ -1293,7 +1293,7 @@ export type PublicActions<
|
|
1293
1293
|
* @remarks
|
1294
1294
|
* This Action will batch up all the Event Logs found within the [`pollingInterval`](https://viem.sh/docs/actions/public/watchEvent.html#pollinginterval-optional), and invoke them via [`onLogs`](https://viem.sh/docs/actions/public/watchEvent.html#onLogs).
|
1295
1295
|
*
|
1296
|
-
* `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter.html) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs) instead.
|
1296
|
+
* `watchEvent` will attempt to create an [Event Filter](https://viem.sh/docs/actions/public/createEventFilter.html) and listen to changes to the Filter per polling interval, however, if the RPC Provider does not support Filters (e.g. `eth_newFilter`), then `watchEvent` will fall back to using [`getLogs`](https://viem.sh/docs/actions/public/getLogs.html) instead.
|
1297
1297
|
*
|
1298
1298
|
* @param args - {@link WatchEventParameters}
|
1299
1299
|
* @returns A function that can be invoked to stop watching for new Event Logs. {@link WatchEventReturnType}
|
@@ -390,7 +390,7 @@ export type TestActions = {
|
|
390
390
|
*/
|
391
391
|
setBlockGasLimit: (args: SetBlockGasLimitParameters) => Promise<void>
|
392
392
|
/**
|
393
|
-
* Similar to [`increaseTime`](https://viem.sh/docs/actions/test/increaseTime), but sets a block timestamp `interval`. The timestamp of future blocks will be computed as `lastBlock_timestamp` + `interval`.
|
393
|
+
* Similar to [`increaseTime`](https://viem.sh/docs/actions/test/increaseTime.html), but sets a block timestamp `interval`. The timestamp of future blocks will be computed as `lastBlock_timestamp` + `interval`.
|
394
394
|
*
|
395
395
|
* - Docs: https://viem.sh/docs/actions/test/setBlockTimestampInterval.html
|
396
396
|
*
|
@@ -641,7 +641,7 @@ export type TestActions = {
|
|
641
641
|
*/
|
642
642
|
snapshot: () => Promise<Quantity>
|
643
643
|
/**
|
644
|
-
* Stop impersonating an account after having previously used [`impersonateAccount`](https://viem.sh/docs/actions/test/impersonateAccount).
|
644
|
+
* Stop impersonating an account after having previously used [`impersonateAccount`](https://viem.sh/docs/actions/test/impersonateAccount.html).
|
645
645
|
*
|
646
646
|
* - Docs: https://viem.sh/docs/actions/test/stopImpersonatingAccount.html
|
647
647
|
*
|
@@ -93,7 +93,7 @@ export type WalletActions<
|
|
93
93
|
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/deploying-contracts
|
94
94
|
*
|
95
95
|
* @param args - {@link DeployContractParameters}
|
96
|
-
* @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
|
96
|
+
* @returns The [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash. {@link DeployContractReturnType}
|
97
97
|
*
|
98
98
|
* @example
|
99
99
|
* import { createWalletClient, http } from 'viem'
|
@@ -276,8 +276,8 @@ export type WalletActions<
|
|
276
276
|
* - Local Accounts: Signs locally. No JSON-RPC request.
|
277
277
|
*
|
278
278
|
* With the calculated signature, you can:
|
279
|
-
* - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage) to verify the signature,
|
280
|
-
* - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress) to recover the signing address from a signature.
|
279
|
+
* - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage.html) to verify the signature,
|
280
|
+
* - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress.html) to recover the signing address from a signature.
|
281
281
|
*
|
282
282
|
* @param args - {@link SignMessageParameters}
|
283
283
|
* @returns The signed message. {@link SignMessageReturnType}
|
@@ -467,14 +467,14 @@ export type WalletActions<
|
|
467
467
|
* - Docs: https://viem.sh/docs/contract/writeContract.html
|
468
468
|
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts
|
469
469
|
*
|
470
|
-
* A "write" function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a [Transaction](https://viem.sh/docs/glossary/terms) is needed to be broadcast in order to change the state.
|
470
|
+
* A "write" function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a [Transaction](https://viem.sh/docs/glossary/terms.html) is needed to be broadcast in order to change the state.
|
471
471
|
*
|
472
|
-
* Internally, uses a [Wallet Client](https://viem.sh/docs/clients/wallet) to call the [`sendTransaction` action](https://viem.sh/docs/actions/wallet/sendTransaction) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
|
472
|
+
* Internally, uses a [Wallet Client](https://viem.sh/docs/clients/wallet.html) to call the [`sendTransaction` action](https://viem.sh/docs/actions/wallet/sendTransaction.html) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData.html).
|
473
473
|
*
|
474
474
|
* __Warning: The `write` internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to [simulate the contract write with `contract.simulate`](https://viem.sh/docs/contract/writeContract.html#usage) before you execute it.__
|
475
475
|
*
|
476
476
|
* @param args - {@link WriteContractParameters}
|
477
|
-
* @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms#hash). {@link WriteContractReturnType}
|
477
|
+
* @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms.html#hash). {@link WriteContractReturnType}
|
478
478
|
*
|
479
479
|
* @example
|
480
480
|
* import { createWalletClient, custom, parseAbi } from 'viem'
|
package/src/errors/rpc.ts
CHANGED
@@ -1,10 +1,27 @@
|
|
1
|
+
import type { Prettify } from '../types/utils.js'
|
1
2
|
import { BaseError } from './base.js'
|
2
3
|
import { RpcRequestError } from './request.js'
|
3
4
|
|
4
5
|
const unknownErrorCode = -1
|
5
6
|
|
6
|
-
type
|
7
|
-
|
7
|
+
export type RpcErrorCode =
|
8
|
+
| -1
|
9
|
+
| -32700 // Parse error
|
10
|
+
| -32600 // Invalid request
|
11
|
+
| -32601 // Method not found
|
12
|
+
| -32602 // Invalid params
|
13
|
+
| -32603 // Internal error
|
14
|
+
| -32000 // Invalid input
|
15
|
+
| -32001 // Resource not found
|
16
|
+
| -32002 // Resource unavailable
|
17
|
+
| -32003 // Transaction rejected
|
18
|
+
| -32004 // Method not supported
|
19
|
+
| -32005 // Limit exceeded
|
20
|
+
| -32006 // JSON-RPC version not supported
|
21
|
+
| -32042 // Method not found
|
22
|
+
|
23
|
+
type RpcErrorOptions<TCode extends number = RpcErrorCode> = {
|
24
|
+
code?: TCode | (number & {})
|
8
25
|
docsPath?: string
|
9
26
|
metaMessages?: string[]
|
10
27
|
shortMessage: string
|
@@ -15,17 +32,14 @@ type RpcErrorOptions = {
|
|
15
32
|
*
|
16
33
|
* - EIP https://eips.ethereum.org/EIPS/eip-1474
|
17
34
|
*/
|
18
|
-
export class RpcError extends BaseError {
|
19
|
-
|
35
|
+
export class RpcError<TCode extends number = RpcErrorCode> extends BaseError {
|
36
|
+
override name = 'RpcError'
|
37
|
+
|
38
|
+
code: TCode | (number & {})
|
20
39
|
|
21
40
|
constructor(
|
22
41
|
cause: Error,
|
23
|
-
{
|
24
|
-
code = unknownErrorCode,
|
25
|
-
docsPath,
|
26
|
-
metaMessages,
|
27
|
-
shortMessage,
|
28
|
-
}: RpcErrorOptions,
|
42
|
+
{ code, docsPath, metaMessages, shortMessage }: RpcErrorOptions<TCode>,
|
29
43
|
) {
|
30
44
|
super(shortMessage, {
|
31
45
|
cause,
|
@@ -34,25 +48,39 @@ export class RpcError extends BaseError {
|
|
34
48
|
metaMessages || (cause as { metaMessages?: string[] })?.metaMessages,
|
35
49
|
})
|
36
50
|
this.name = cause.name
|
37
|
-
this.code =
|
51
|
+
this.code = (
|
52
|
+
cause instanceof RpcRequestError ? cause.code : code ?? unknownErrorCode
|
53
|
+
) as TCode
|
38
54
|
}
|
39
55
|
}
|
40
56
|
|
57
|
+
export type ProviderRpcErrorCode =
|
58
|
+
| 4001 // User Rejected Request
|
59
|
+
| 4100 // Unauthorized
|
60
|
+
| 4200 // Unsupported Method
|
61
|
+
| 4900 // Disconnected
|
62
|
+
| 4901 // Chain Disconnected
|
63
|
+
| 4902 // Chain Not Recongnized
|
64
|
+
|
41
65
|
/**
|
42
66
|
* Error subclass implementing Ethereum Provider errors per EIP-1193.
|
43
67
|
*
|
44
68
|
* - EIP https://eips.ethereum.org/EIPS/eip-1193
|
45
69
|
*/
|
46
|
-
export class ProviderRpcError<
|
70
|
+
export class ProviderRpcError<
|
71
|
+
T = undefined,
|
72
|
+
> extends RpcError<ProviderRpcErrorCode> {
|
47
73
|
override name = 'ProviderRpcError'
|
48
74
|
|
49
75
|
data?: T
|
50
76
|
|
51
77
|
constructor(
|
52
78
|
cause: Error,
|
53
|
-
options:
|
54
|
-
|
55
|
-
|
79
|
+
options: Prettify<
|
80
|
+
RpcErrorOptions<ProviderRpcErrorCode> & {
|
81
|
+
data?: T
|
82
|
+
}
|
83
|
+
>,
|
56
84
|
) {
|
57
85
|
super(cause, options)
|
58
86
|
|
package/src/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '0.3.
|
1
|
+
export const version = '0.3.37'
|
package/src/index.ts
CHANGED
@@ -292,9 +292,11 @@ export {
|
|
292
292
|
ParseRpcError,
|
293
293
|
ProviderDisconnectedError,
|
294
294
|
ProviderRpcError,
|
295
|
+
type ProviderRpcErrorCode,
|
295
296
|
ResourceNotFoundRpcError,
|
296
297
|
ResourceUnavailableRpcError,
|
297
298
|
RpcError,
|
299
|
+
type RpcErrorCode,
|
298
300
|
TransactionRejectedRpcError,
|
299
301
|
SwitchChainError,
|
300
302
|
UnauthorizedProviderError,
|
@@ -430,9 +432,29 @@ export {
|
|
430
432
|
type BlockTag,
|
431
433
|
type Uncle,
|
432
434
|
} from './types/block.js'
|
433
|
-
export {
|
435
|
+
export {
|
436
|
+
type ByteArray,
|
437
|
+
type Hash,
|
438
|
+
type Hex,
|
439
|
+
type LogTopic,
|
440
|
+
type Signature,
|
441
|
+
} from './types/misc.js'
|
434
442
|
export type { Chain } from './types/chain.js'
|
435
|
-
export type {
|
443
|
+
export type {
|
444
|
+
EIP1193Provider,
|
445
|
+
ProviderRpcError as EIP1193ProviderRpcError,
|
446
|
+
ProviderConnectInfo,
|
447
|
+
ProviderMessage,
|
448
|
+
AddEthereumChainParameter,
|
449
|
+
NetworkSync,
|
450
|
+
PublicRequests,
|
451
|
+
Requests,
|
452
|
+
SignableRequests,
|
453
|
+
WatchAssetParams,
|
454
|
+
WalletPermissionCaveat,
|
455
|
+
WalletPermission,
|
456
|
+
WalletRequests,
|
457
|
+
} from './types/eip1193.js'
|
436
458
|
export {
|
437
459
|
type FeeHistory,
|
438
460
|
type FeeValues,
|
package/src/types/eip1193.ts
CHANGED
@@ -23,17 +23,11 @@ export type EIP1193Provider = Requests & Events
|
|
23
23
|
//////////////////////////////////////////////////
|
24
24
|
// Errors
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
// https://eips.ethereum.org/EIPS/eip-1193#provider-errors
|
29
|
-
| 4_001 | 4_100 | 4_200 | 4_900 | 4_901
|
30
|
-
// https://eips.ethereum.org/EIPS/eip-1474#error-codes
|
31
|
-
| -32700 | -32600 | -32601 | -32602 | -32603 | -32000 | -32001 | -32002 | -32003 | -32004 | -32005 | -32006
|
32
|
-
export class RpcError extends Error {
|
33
|
-
code: RpcErrorCode | (number & {})
|
26
|
+
export class ProviderRpcError extends Error {
|
27
|
+
code: number
|
34
28
|
details: string
|
35
29
|
|
36
|
-
constructor(code:
|
30
|
+
constructor(code: number, message: string) {
|
37
31
|
super(message)
|
38
32
|
this.code = code
|
39
33
|
this.details = message
|
@@ -57,7 +51,7 @@ export type Events = {
|
|
57
51
|
event: 'connect',
|
58
52
|
listener: (connectInfo: ProviderConnectInfo) => void,
|
59
53
|
): void
|
60
|
-
on(event: 'disconnect', listener: (error:
|
54
|
+
on(event: 'disconnect', listener: (error: ProviderRpcError) => void): void
|
61
55
|
on(event: 'chainChanged', listener: (chainId: string) => void): void
|
62
56
|
on(event: 'accountsChanged', listener: (accounts: string[]) => void): void
|
63
57
|
on(event: 'message', listener: (message: ProviderMessage) => void): void
|
@@ -66,7 +60,10 @@ export type Events = {
|
|
66
60
|
event: 'connect',
|
67
61
|
listener: (connectInfo: ProviderConnectInfo) => void,
|
68
62
|
): void
|
69
|
-
removeListener(
|
63
|
+
removeListener(
|
64
|
+
event: 'disconnect',
|
65
|
+
listener: (error: ProviderRpcError) => void,
|
66
|
+
): void
|
70
67
|
removeListener(
|
71
68
|
event: 'chainChanged',
|
72
69
|
listener: (chainId: string) => void,
|
@@ -84,7 +81,7 @@ export type Events = {
|
|
84
81
|
//////////////////////////////////////////////////
|
85
82
|
// Provider Requests
|
86
83
|
|
87
|
-
export type
|
84
|
+
export type AddEthereumChainParameter = {
|
88
85
|
/** A 0x-prefixed hexadecimal string */
|
89
86
|
chainId: string
|
90
87
|
/** The chain name. */
|
@@ -1034,7 +1031,7 @@ export type WalletRequests = {
|
|
1034
1031
|
* // => { ... }
|
1035
1032
|
*/
|
1036
1033
|
method: 'wallet_addEthereumChain'
|
1037
|
-
params: [chain:
|
1034
|
+
params: [chain: AddEthereumChainParameter]
|
1038
1035
|
}): Promise<null>
|
1039
1036
|
request(args: {
|
1040
1037
|
/**
|
@@ -12,9 +12,11 @@ import {
|
|
12
12
|
MethodNotSupportedRpcError,
|
13
13
|
ParseRpcError,
|
14
14
|
ProviderDisconnectedError,
|
15
|
+
type ProviderRpcErrorCode,
|
15
16
|
ResourceNotFoundRpcError,
|
16
17
|
ResourceUnavailableRpcError,
|
17
18
|
type RpcError,
|
19
|
+
type RpcErrorCode,
|
18
20
|
SwitchChainError,
|
19
21
|
TransactionRejectedRpcError,
|
20
22
|
UnauthorizedProviderError,
|
@@ -66,7 +68,9 @@ export function buildRequest<TRequest extends (args: any) => Promise<any>>(
|
|
66
68
|
try {
|
67
69
|
return await request(args)
|
68
70
|
} catch (err_) {
|
69
|
-
const err = err_ as unknown as RpcError
|
71
|
+
const err = err_ as unknown as RpcError<
|
72
|
+
RpcErrorCode | ProviderRpcErrorCode
|
73
|
+
>
|
70
74
|
if (err.code === -32700) throw new ParseRpcError(err)
|
71
75
|
if (err.code === -32600) throw new InvalidRequestRpcError(err)
|
72
76
|
if (err.code === -32601) throw new MethodNotFoundRpcError(err)
|