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
@@ -90,6 +90,7 @@ export type GetContractParameters<
|
|
90
90
|
*
|
91
91
|
* If you pass in a [`walletClient`](https://viem.sh/docs/clients/wallet.html), the following methods are available:
|
92
92
|
*
|
93
|
+
* - [`estimateGas`](https://viem.sh/docs/contract/estimateContractGas.html)
|
93
94
|
* - [`write`](https://viem.sh/docs/contract/writeContract.html)
|
94
95
|
*/
|
95
96
|
walletClient?: TWalletClient
|
@@ -163,7 +164,7 @@ export type GetContractReturnType<
|
|
163
164
|
* import { createPublicClient, getContract, http, parseAbi } from 'viem'
|
164
165
|
* import { mainnet } from 'viem/chains'
|
165
166
|
*
|
166
|
-
* const
|
167
|
+
* const publicClient = createPublicClient({
|
167
168
|
* chain: mainnet,
|
168
169
|
* transport: http(),
|
169
170
|
* })
|
@@ -179,9 +180,8 @@ export type GetContractReturnType<
|
|
179
180
|
estimateGas: {
|
180
181
|
[FunctionName in _WriteFunctionNames]: GetEstimateFunction<
|
181
182
|
_Narrowable,
|
182
|
-
TPublicClient
|
183
|
-
|
184
|
-
: undefined,
|
183
|
+
TPublicClient['chain'],
|
184
|
+
undefined,
|
185
185
|
TAbi,
|
186
186
|
FunctionName
|
187
187
|
>
|
@@ -197,7 +197,7 @@ export type GetContractReturnType<
|
|
197
197
|
* import { createPublicClient, getContract, http, parseAbi } from 'viem'
|
198
198
|
* import { mainnet } from 'viem/chains'
|
199
199
|
*
|
200
|
-
* const
|
200
|
+
* const publicClient = createPublicClient({
|
201
201
|
* chain: mainnet,
|
202
202
|
* transport: http(),
|
203
203
|
* })
|
@@ -213,9 +213,7 @@ export type GetContractReturnType<
|
|
213
213
|
simulate: {
|
214
214
|
[FunctionName in _WriteFunctionNames]: GetSimulateFunction<
|
215
215
|
_Narrowable,
|
216
|
-
TPublicClient
|
217
|
-
? TPublicClient['chain']
|
218
|
-
: undefined,
|
216
|
+
TPublicClient['chain'],
|
219
217
|
TAbi,
|
220
218
|
FunctionName
|
221
219
|
>
|
@@ -231,7 +229,7 @@ export type GetContractReturnType<
|
|
231
229
|
* import { createPublicClient, getContract, http, parseAbi } from 'viem'
|
232
230
|
* import { mainnet } from 'viem/chains'
|
233
231
|
*
|
234
|
-
* const
|
232
|
+
* const publicClient = createPublicClient({
|
235
233
|
* chain: mainnet,
|
236
234
|
* transport: http(),
|
237
235
|
* })
|
@@ -260,7 +258,7 @@ export type GetContractReturnType<
|
|
260
258
|
* import { createPublicClient, getContract, http, parseAbi } from 'viem'
|
261
259
|
* import { mainnet } from 'viem/chains'
|
262
260
|
*
|
263
|
-
* const
|
261
|
+
* const publicClient = createPublicClient({
|
264
262
|
* chain: mainnet,
|
265
263
|
* transport: http(),
|
266
264
|
* })
|
@@ -288,6 +286,35 @@ export type GetContractReturnType<
|
|
288
286
|
? IsNever<_WriteFunctionNames> extends true
|
289
287
|
? unknown
|
290
288
|
: {
|
289
|
+
/**
|
290
|
+
* Estimates the gas necessary to complete a transaction without submitting it to the network.
|
291
|
+
*
|
292
|
+
* @example
|
293
|
+
* import { createWalletClient, getContract, http, parseAbi } from 'viem'
|
294
|
+
* import { mainnet } from 'viem/chains'
|
295
|
+
*
|
296
|
+
* const walletClient = createWalletClient({
|
297
|
+
* chain: mainnet,
|
298
|
+
* transport: http(),
|
299
|
+
* })
|
300
|
+
* const contract = getContract({
|
301
|
+
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
302
|
+
* abi: parseAbi(['function mint() public']),
|
303
|
+
* walletClient,
|
304
|
+
* })
|
305
|
+
* const gas = await contract.estimateGas.mint({
|
306
|
+
* account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
307
|
+
* })
|
308
|
+
*/
|
309
|
+
estimateGas: {
|
310
|
+
[FunctionName in _WriteFunctionNames]: GetEstimateFunction<
|
311
|
+
_Narrowable,
|
312
|
+
TWalletClient['chain'],
|
313
|
+
TWalletClient['account'],
|
314
|
+
TAbi,
|
315
|
+
FunctionName
|
316
|
+
>
|
317
|
+
}
|
291
318
|
/**
|
292
319
|
* Executes a write function on a contract.
|
293
320
|
*
|
@@ -301,14 +328,14 @@ export type GetContractReturnType<
|
|
301
328
|
* import { createWalletClient, getContract, http, parseAbi } from 'viem'
|
302
329
|
* import { mainnet } from 'viem/chains'
|
303
330
|
*
|
304
|
-
* const
|
331
|
+
* const walletClient = createWalletClient({
|
305
332
|
* chain: mainnet,
|
306
333
|
* transport: http(),
|
307
334
|
* })
|
308
335
|
* const contract = getContract({
|
309
336
|
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
310
337
|
* abi: parseAbi(['function mint(uint32 tokenId) nonpayable']),
|
311
|
-
*
|
338
|
+
* walletClient,
|
312
339
|
* })
|
313
340
|
* const hash = await contract.write.min([69420], {
|
314
341
|
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
@@ -317,12 +344,8 @@ export type GetContractReturnType<
|
|
317
344
|
write: {
|
318
345
|
[FunctionName in _WriteFunctionNames]: GetWriteFunction<
|
319
346
|
_Narrowable,
|
320
|
-
TWalletClient
|
321
|
-
|
322
|
-
: undefined,
|
323
|
-
TWalletClient extends WalletClient
|
324
|
-
? TWalletClient['account']
|
325
|
-
: undefined,
|
347
|
+
TWalletClient['chain'],
|
348
|
+
TWalletClient['account'],
|
326
349
|
TAbi,
|
327
350
|
FunctionName
|
328
351
|
>
|
@@ -434,32 +457,7 @@ export function getContract<
|
|
434
457
|
},
|
435
458
|
)
|
436
459
|
|
437
|
-
if (hasWriteFunction)
|
438
|
-
contract.estimateGas = new Proxy(
|
439
|
-
{},
|
440
|
-
{
|
441
|
-
get(_, functionName: string) {
|
442
|
-
return (
|
443
|
-
...parameters: [
|
444
|
-
args?: readonly unknown[],
|
445
|
-
options?: Omit<
|
446
|
-
EstimateContractGasParameters,
|
447
|
-
'abi' | 'address' | 'functionName' | 'args'
|
448
|
-
>,
|
449
|
-
]
|
450
|
-
) => {
|
451
|
-
const { args, options } = getFunctionParameters(parameters)
|
452
|
-
return estimateContractGas(publicClient, {
|
453
|
-
abi,
|
454
|
-
address,
|
455
|
-
functionName,
|
456
|
-
args,
|
457
|
-
...options,
|
458
|
-
} as EstimateContractGasParameters)
|
459
|
-
}
|
460
|
-
},
|
461
|
-
},
|
462
|
-
)
|
460
|
+
if (hasWriteFunction)
|
463
461
|
contract.simulate = new Proxy(
|
464
462
|
{},
|
465
463
|
{
|
@@ -485,7 +483,6 @@ export function getContract<
|
|
485
483
|
},
|
486
484
|
},
|
487
485
|
)
|
488
|
-
}
|
489
486
|
|
490
487
|
if (hasEvent) {
|
491
488
|
contract.createEventFilter = new Proxy(
|
@@ -587,6 +584,38 @@ export function getContract<
|
|
587
584
|
)
|
588
585
|
}
|
589
586
|
|
587
|
+
if (hasPublicClient || hasWalletClient)
|
588
|
+
if (hasWriteFunction)
|
589
|
+
contract.estimateGas = new Proxy(
|
590
|
+
{},
|
591
|
+
{
|
592
|
+
get(_, functionName: string) {
|
593
|
+
return (
|
594
|
+
...parameters: [
|
595
|
+
args?: readonly unknown[],
|
596
|
+
options?: Omit<
|
597
|
+
EstimateContractGasParameters,
|
598
|
+
'abi' | 'address' | 'functionName' | 'args'
|
599
|
+
>,
|
600
|
+
]
|
601
|
+
) => {
|
602
|
+
const { args, options } = getFunctionParameters(parameters)
|
603
|
+
const client = (publicClient ?? walletClient)!
|
604
|
+
return estimateContractGas(client, {
|
605
|
+
abi,
|
606
|
+
address,
|
607
|
+
functionName,
|
608
|
+
args,
|
609
|
+
...options,
|
610
|
+
account:
|
611
|
+
(options as EstimateContractGasParameters).account ??
|
612
|
+
(walletClient as WalletClient).account,
|
613
|
+
} as EstimateContractGasParameters)
|
614
|
+
}
|
615
|
+
},
|
616
|
+
},
|
617
|
+
)
|
618
|
+
|
590
619
|
return contract as unknown as GetContractReturnType<
|
591
620
|
TAbi,
|
592
621
|
TPublicClient,
|
@@ -659,6 +688,7 @@ type GetReadFunction<
|
|
659
688
|
type GetEstimateFunction<
|
660
689
|
Narrowable extends boolean,
|
661
690
|
TChain extends Chain | undefined,
|
691
|
+
TAccount extends Account | undefined,
|
662
692
|
TAbi extends Abi | readonly unknown[],
|
663
693
|
TFunctionName extends string,
|
664
694
|
TAbiFunction extends AbiFunction = TAbi extends Abi
|
@@ -667,20 +697,36 @@ type GetEstimateFunction<
|
|
667
697
|
Args = AbiParametersToPrimitiveTypes<TAbiFunction['inputs']>,
|
668
698
|
Options = Prettify<
|
669
699
|
Omit<
|
670
|
-
EstimateContractGasParameters<TAbi, TFunctionName, TChain>,
|
700
|
+
EstimateContractGasParameters<TAbi, TFunctionName, TChain, TAccount>,
|
671
701
|
'abi' | 'address' | 'args' | 'functionName'
|
672
702
|
>
|
673
703
|
>,
|
704
|
+
// For making `options` parameter required if `TAccount`
|
705
|
+
IsOptionsRequired = IsUndefined<TAccount>,
|
674
706
|
> = Narrowable extends true
|
675
707
|
? (
|
676
708
|
...parameters: Args extends readonly []
|
677
|
-
?
|
678
|
-
|
709
|
+
? IsOptionsRequired extends true
|
710
|
+
? [options: Options]
|
711
|
+
: [options?: Options]
|
712
|
+
: [
|
713
|
+
args: Args,
|
714
|
+
...parameters: IsOptionsRequired extends true
|
715
|
+
? [options: Options]
|
716
|
+
: [options?: Options],
|
717
|
+
]
|
679
718
|
) => Promise<EstimateContractGasReturnType>
|
680
719
|
: (
|
681
720
|
...parameters:
|
682
|
-
|
|
683
|
-
|
721
|
+
| (IsOptionsRequired extends true
|
722
|
+
? [options: Options]
|
723
|
+
: [options?: Options])
|
724
|
+
| [
|
725
|
+
args: readonly unknown[],
|
726
|
+
...parameters: IsOptionsRequired extends true
|
727
|
+
? [options: Options]
|
728
|
+
: [options?: Options],
|
729
|
+
]
|
684
730
|
) => Promise<EstimateContractGasReturnType>
|
685
731
|
|
686
732
|
type GetSimulateFunction<
|
@@ -759,13 +805,17 @@ type GetWriteFunction<
|
|
759
805
|
'abi' | 'address' | 'args' | 'functionName'
|
760
806
|
>
|
761
807
|
>,
|
762
|
-
Rest extends IsOptionsRequired extends true
|
763
|
-
? [options: Options]
|
764
|
-
: [options?: Options],
|
765
808
|
>(
|
766
809
|
...parameters: Args extends readonly []
|
767
|
-
?
|
768
|
-
|
810
|
+
? IsOptionsRequired extends true
|
811
|
+
? [options: Options]
|
812
|
+
: [options?: Options]
|
813
|
+
: [
|
814
|
+
args: Args,
|
815
|
+
...parameters: IsOptionsRequired extends true
|
816
|
+
? [options: Options]
|
817
|
+
: [options?: Options],
|
818
|
+
]
|
769
819
|
) => Promise<WriteContractReturnType>
|
770
820
|
: <
|
771
821
|
TChainOverride extends Chain | undefined,
|
@@ -7,7 +7,7 @@ import { createFilterRequestScope } from '../../utils/filters/createFilterReques
|
|
7
7
|
export type CreateBlockFilterReturnType = Filter<'block'>
|
8
8
|
|
9
9
|
/**
|
10
|
-
* Creates a [`Filter`](https://viem.sh/docs/glossary/types.html#filter) to listen for new block hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
|
10
|
+
* Creates a [`Filter`](https://viem.sh/docs/glossary/types.html#filter) to listen for new block hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html).
|
11
11
|
*
|
12
12
|
* - Docs: https://viem.sh/docs/actions/public/createBlockFilter.html
|
13
13
|
* - JSON-RPC Methods: [`eth_newBlockFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newBlockFilter)
|
@@ -52,7 +52,7 @@ export type CreateContractEventFilterReturnType<
|
|
52
52
|
> = Filter<'event', TAbi, TEventName, TArgs>
|
53
53
|
|
54
54
|
/**
|
55
|
-
* 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).
|
55
|
+
* 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).
|
56
56
|
*
|
57
57
|
* - Docs: https://viem.sh/docs/contract/createContractEventFilter.html
|
58
58
|
*
|
@@ -63,7 +63,7 @@ export type CreateEventFilterReturnType<
|
|
63
63
|
> = Prettify<Filter<'event', TAbi, TEventName, TArgs>>
|
64
64
|
|
65
65
|
/**
|
66
|
-
* 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).
|
66
|
+
* 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).
|
67
67
|
*
|
68
68
|
* - Docs: https://viem.sh/docs/actions/public/createEventFilter.html
|
69
69
|
* - JSON-RPC Methods: [`eth_newFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter)
|
@@ -7,7 +7,7 @@ import { createFilterRequestScope } from '../../utils/filters/createFilterReques
|
|
7
7
|
export type CreatePendingTransactionFilterReturnType = Filter<'transaction'>
|
8
8
|
|
9
9
|
/**
|
10
|
-
* Creates a Filter to listen for new pending transaction hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
|
10
|
+
* Creates a Filter to listen for new pending transaction hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges.html).
|
11
11
|
*
|
12
12
|
* - Docs: https://viem.sh/docs/actions/public/createPendingTransactionFilter.html
|
13
13
|
* - JSON-RPC Methods: [`eth_newPendingTransactionFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newpendingtransactionfilter)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { Abi } from 'abitype'
|
2
2
|
|
3
|
+
import type { Account } from '../../accounts/types.js'
|
3
4
|
import { parseAccount } from '../../accounts/utils/parseAccount.js'
|
4
5
|
import type { PublicClient } from '../../clients/createPublicClient.js'
|
5
6
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
@@ -12,14 +13,16 @@ import {
|
|
12
13
|
} from '../../utils/abi/encodeFunctionData.js'
|
13
14
|
import { getContractError } from '../../utils/errors/getContractError.js'
|
14
15
|
|
16
|
+
import type { WalletClient } from '../../clients/createWalletClient.js'
|
15
17
|
import { type EstimateGasParameters, estimateGas } from './estimateGas.js'
|
16
18
|
|
17
19
|
export type EstimateContractGasParameters<
|
18
20
|
TAbi extends Abi | readonly unknown[] = Abi,
|
19
21
|
TFunctionName extends string = string,
|
20
22
|
TChain extends Chain | undefined = Chain | undefined,
|
23
|
+
TAccount extends Account | undefined = undefined,
|
21
24
|
> = ContractFunctionConfig<TAbi, TFunctionName, 'payable' | 'nonpayable'> &
|
22
|
-
Omit<EstimateGasParameters<TChain>, 'data' | 'to' | 'value'> &
|
25
|
+
Omit<EstimateGasParameters<TChain, TAccount>, 'data' | 'to' | 'value'> &
|
23
26
|
GetValue<TAbi, TFunctionName, EstimateGasParameters<TChain>['value']>
|
24
27
|
|
25
28
|
export type EstimateContractGasReturnType = bigint
|
@@ -29,7 +32,7 @@ export type EstimateContractGasReturnType = bigint
|
|
29
32
|
*
|
30
33
|
* - Docs: https://viem.sh/docs/contract/estimateContractGas.html
|
31
34
|
*
|
32
|
-
* 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).
|
35
|
+
* 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).
|
33
36
|
*
|
34
37
|
* @param client - Client to use
|
35
38
|
* @param parameters - {@link EstimateContractGasParameters}
|
@@ -55,17 +58,19 @@ export async function estimateContractGas<
|
|
55
58
|
TAbi extends Abi | readonly unknown[],
|
56
59
|
TFunctionName extends string,
|
57
60
|
TChain extends Chain | undefined,
|
61
|
+
TAccount extends Account | undefined = undefined,
|
58
62
|
>(
|
59
|
-
client:
|
63
|
+
client:
|
64
|
+
| PublicClient<Transport, TChain>
|
65
|
+
| WalletClient<Transport, TChain, TAccount>,
|
60
66
|
{
|
61
67
|
abi,
|
62
68
|
address,
|
63
69
|
args,
|
64
70
|
functionName,
|
65
71
|
...request
|
66
|
-
}: EstimateContractGasParameters<TAbi, TFunctionName, TChain>,
|
72
|
+
}: EstimateContractGasParameters<TAbi, TFunctionName, TChain, TAccount>,
|
67
73
|
): Promise<EstimateContractGasReturnType> {
|
68
|
-
const account = parseAccount(request.account)
|
69
74
|
const data = encodeFunctionData({
|
70
75
|
abi,
|
71
76
|
args,
|
@@ -79,6 +84,7 @@ export async function estimateContractGas<
|
|
79
84
|
} as unknown as EstimateGasParameters<TChain>)
|
80
85
|
return gas
|
81
86
|
} catch (err) {
|
87
|
+
const account = request.account ? parseAccount(request.account) : undefined
|
82
88
|
throw getContractError(err as BaseError, {
|
83
89
|
abi: abi as Abi,
|
84
90
|
address,
|
@@ -86,11 +86,12 @@ export async function estimateGas<
|
|
86
86
|
| WalletClient<Transport, TChain, TAccount>,
|
87
87
|
args: EstimateGasParameters<TChain, TAccount>,
|
88
88
|
): Promise<EstimateGasReturnType> {
|
89
|
-
|
89
|
+
const account_ = args.account ?? (client as WalletClient).account
|
90
|
+
if (!account_)
|
90
91
|
throw new AccountNotFoundError({
|
91
92
|
docsPath: '/docs/actions/public/estimateGas',
|
92
93
|
})
|
93
|
-
const account = parseAccount(
|
94
|
+
const account = parseAccount(account_)
|
94
95
|
|
95
96
|
try {
|
96
97
|
const {
|
@@ -38,10 +38,10 @@ export type GetFilterChangesReturnType<
|
|
38
38
|
*
|
39
39
|
* A Filter can be created from the following actions:
|
40
40
|
*
|
41
|
-
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter)
|
42
|
-
* - [`createContractEventFilter`](https://viem.sh/docs/contract/createContractEventFilter)
|
43
|
-
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter)
|
44
|
-
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter)
|
41
|
+
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter.html)
|
42
|
+
* - [`createContractEventFilter`](https://viem.sh/docs/contract/createContractEventFilter.html)
|
43
|
+
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter.html)
|
44
|
+
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter.html)
|
45
45
|
*
|
46
46
|
* Depending on the type of filter, the return value will be different:
|
47
47
|
*
|
@@ -54,7 +54,7 @@ export type GetTransactionReturnType<TChain extends Chain | undefined = Chain> =
|
|
54
54
|
FormattedTransaction<TransactionFormatter<TChain>>
|
55
55
|
|
56
56
|
/**
|
57
|
-
* Returns information about a [Transaction](https://viem.sh/docs/glossary/terms#transaction) given a hash or block identifier.
|
57
|
+
* Returns information about a [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) given a hash or block identifier.
|
58
58
|
*
|
59
59
|
* - Docs: https://viem.sh/docs/actions/public/getTransaction.html
|
60
60
|
* - Example: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/fetching-transactions
|
@@ -27,7 +27,7 @@ export type GetTransactionCountParameters = {
|
|
27
27
|
export type GetTransactionCountReturnType = number
|
28
28
|
|
29
29
|
/**
|
30
|
-
* Returns the number of [Transactions](https://viem.sh/docs/glossary/terms#transaction) an Account has broadcast / sent.
|
30
|
+
* Returns the number of [Transactions](https://viem.sh/docs/glossary/terms.html#transaction) an Account has broadcast / sent.
|
31
31
|
*
|
32
32
|
* - Docs: https://viem.sh/docs/actions/public/getTransactionCount.html
|
33
33
|
* - JSON-RPC Methods: [`eth_getTransactionCount`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactioncount)
|
@@ -20,7 +20,7 @@ export type GetTransactionReceiptReturnType<
|
|
20
20
|
> = FormattedTransactionReceipt<TransactionReceiptFormatter<TChain>>
|
21
21
|
|
22
22
|
/**
|
23
|
-
* Returns the [Transaction Receipt](https://viem.sh/docs/glossary/terms#transaction-receipt) given a [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash.
|
23
|
+
* 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.
|
24
24
|
*
|
25
25
|
* - Docs: https://viem.sh/docs/actions/public/getTransactionReceipt.html
|
26
26
|
* - Example: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/fetching-transactions
|
@@ -41,7 +41,7 @@ export type MulticallReturnType<
|
|
41
41
|
> = MulticallResults<TContracts, TAllowFailure>
|
42
42
|
|
43
43
|
/**
|
44
|
-
* 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).
|
44
|
+
* 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).
|
45
45
|
*
|
46
46
|
* - Docs: https://viem.sh/docs/contract/multicall.html
|
47
47
|
*
|
@@ -39,7 +39,7 @@ export type ReadContractReturnType<
|
|
39
39
|
*
|
40
40
|
* 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.
|
41
41
|
*
|
42
|
-
* 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).
|
42
|
+
* 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).
|
43
43
|
*
|
44
44
|
* @param client - Client to use
|
45
45
|
* @param parameters - {@link ReadContractParameters}
|
@@ -68,9 +68,9 @@ export type SimulateContractReturnType<
|
|
68
68
|
* - Docs: https://viem.sh/docs/contract/simulateContract.html
|
69
69
|
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts
|
70
70
|
*
|
71
|
-
* 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.
|
71
|
+
* 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.
|
72
72
|
*
|
73
|
-
* 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).
|
73
|
+
* 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).
|
74
74
|
*
|
75
75
|
* @param client - Client to use
|
76
76
|
* @param parameters - {@link SimulateContractParameters}
|
@@ -15,9 +15,9 @@ export type UninstallFilterReturnType = boolean
|
|
15
15
|
* - JSON-RPC Methods: [`eth_uninstallFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_uninstallFilter)
|
16
16
|
*
|
17
17
|
* Destroys a Filter that was created from one of the following Actions:
|
18
|
-
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter)
|
19
|
-
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter)
|
20
|
-
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter)
|
18
|
+
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter.html)
|
19
|
+
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter.html)
|
20
|
+
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter.html)
|
21
21
|
*
|
22
22
|
* @param client - Client to use
|
23
23
|
* @param parameters - {@link UninstallFilterParameters}
|
@@ -64,7 +64,7 @@ export type WatchContractEventReturnType = () => void
|
|
64
64
|
*
|
65
65
|
* 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).
|
66
66
|
*
|
67
|
-
* `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.
|
67
|
+
* `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) instead.
|
68
68
|
*
|
69
69
|
* @param client - Client to use
|
70
70
|
* @param parameters - {@link WatchContractEventParameters}
|
@@ -62,7 +62,7 @@ export type WatchEventParameters<
|
|
62
62
|
export type WatchEventReturnType = () => void
|
63
63
|
|
64
64
|
/**
|
65
|
-
* Watches and returns emitted [Event Logs](https://viem.sh/docs/glossary/terms#event-log).
|
65
|
+
* Watches and returns emitted [Event Logs](https://viem.sh/docs/glossary/terms.html#event-log).
|
66
66
|
*
|
67
67
|
* - Docs: https://viem.sh/docs/actions/public/watchEvent.html
|
68
68
|
* - JSON-RPC Methods:
|
@@ -74,7 +74,7 @@ export type WatchEventReturnType = () => void
|
|
74
74
|
*
|
75
75
|
* 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).
|
76
76
|
*
|
77
|
-
* `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.
|
77
|
+
* `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.
|
78
78
|
*
|
79
79
|
* @param client - Client to use
|
80
80
|
* @param parameters - {@link WatchEventParameters}
|
@@ -11,7 +11,7 @@ export type SetBlockTimestampIntervalParameters = {
|
|
11
11
|
}
|
12
12
|
|
13
13
|
/**
|
14
|
-
* 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`.
|
14
|
+
* 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`.
|
15
15
|
*
|
16
16
|
* - Docs: https://viem.sh/docs/actions/test/setBlockTimestampInterval.html
|
17
17
|
*
|
@@ -13,7 +13,7 @@ export type StopImpersonatingAccountParameters = {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
/**
|
16
|
-
* Stop impersonating an account after having previously used [`impersonateAccount`](https://viem.sh/docs/actions/test/impersonateAccount).
|
16
|
+
* Stop impersonating an account after having previously used [`impersonateAccount`](https://viem.sh/docs/actions/test/impersonateAccount.html).
|
17
17
|
*
|
18
18
|
* - Docs: https://viem.sh/docs/actions/test/stopImpersonatingAccount.html
|
19
19
|
*
|
@@ -38,7 +38,7 @@ export type DeployContractReturnType = SendTransactionReturnType
|
|
38
38
|
*
|
39
39
|
* @param client - Client to use
|
40
40
|
* @param parameters - {@link DeployContractParameters}
|
41
|
-
* @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link DeployContractReturnType}
|
41
|
+
* @returns The [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash. {@link DeployContractReturnType}
|
42
42
|
*
|
43
43
|
* @example
|
44
44
|
* import { createWalletClient, http } from 'viem'
|
@@ -25,8 +25,8 @@ export type SignMessageReturnType = Hex
|
|
25
25
|
* - Local Accounts: Signs locally. No JSON-RPC request.
|
26
26
|
*
|
27
27
|
* With the calculated signature, you can:
|
28
|
-
* - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage) to verify the signature,
|
29
|
-
* - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress) to recover the signing address from a signature.
|
28
|
+
* - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage.html) to verify the signature,
|
29
|
+
* - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress.html) to recover the signing address from a signature.
|
30
30
|
*
|
31
31
|
* @param client - Client to use
|
32
32
|
* @param parameters - {@link SignMessageParameters}
|
@@ -42,15 +42,15 @@ export type WriteContractReturnType = SendTransactionReturnType
|
|
42
42
|
* - Docs: https://viem.sh/docs/contract/writeContract.html
|
43
43
|
* - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts
|
44
44
|
*
|
45
|
-
* 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.
|
45
|
+
* 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.
|
46
46
|
*
|
47
|
-
* 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).
|
47
|
+
* 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).
|
48
48
|
*
|
49
49
|
* __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.__
|
50
50
|
*
|
51
51
|
* @param client - Client to use
|
52
52
|
* @param parameters - {@link WriteContractParameters}
|
53
|
-
* @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms#hash). {@link WriteContractReturnType}
|
53
|
+
* @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms.html#hash). {@link WriteContractReturnType}
|
54
54
|
*
|
55
55
|
* @example
|
56
56
|
* import { createWalletClient, custom, parseAbi } from 'viem'
|
@@ -38,7 +38,7 @@ export type PublicClient<
|
|
38
38
|
>
|
39
39
|
|
40
40
|
/**
|
41
|
-
* Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
41
|
+
* Creates a Public Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html).
|
42
42
|
*
|
43
43
|
* - Docs: https://viem.sh/docs/clients/public.html
|
44
44
|
*
|
@@ -33,11 +33,11 @@ export type TestClient<
|
|
33
33
|
* @description Creates a test client with a given transport.
|
34
34
|
*/
|
35
35
|
/**
|
36
|
-
* Creates a Test Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
36
|
+
* Creates a Test Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html).
|
37
37
|
*
|
38
38
|
* - Docs: https://viem.sh/docs/clients/test.html
|
39
39
|
*
|
40
|
-
* A Test Client is an interface to "test" JSON-RPC API methods accessible through a local Ethereum test node such as [Anvil](https://book.getfoundry.sh/anvil/) or [Hardhat](https://hardhat.org/) such as mining blocks, impersonating accounts, setting fees, etc through [Test Actions](https://viem.sh/docs/actions/test/introduction).
|
40
|
+
* A Test Client is an interface to "test" JSON-RPC API methods accessible through a local Ethereum test node such as [Anvil](https://book.getfoundry.sh/anvil/) or [Hardhat](https://hardhat.org/) such as mining blocks, impersonating accounts, setting fees, etc through [Test Actions](https://viem.sh/docs/actions/test/introduction.html).
|
41
41
|
*
|
42
42
|
* @param config - {@link TestClientConfig}
|
43
43
|
* @returns A Test Client. {@link TestClient}
|
@@ -41,11 +41,11 @@ export type WalletClient<
|
|
41
41
|
>
|
42
42
|
|
43
43
|
/**
|
44
|
-
* Creates a Wallet Client with a given [Transport](https://viem.sh/docs/clients/intro) configured for a [Chain](https://viem.sh/docs/clients/chains).
|
44
|
+
* Creates a Wallet Client with a given [Transport](https://viem.sh/docs/clients/intro.html) configured for a [Chain](https://viem.sh/docs/clients/chains.html).
|
45
45
|
*
|
46
46
|
* - Docs: https://viem.sh/docs/clients/wallet.html
|
47
47
|
*
|
48
|
-
* A Wallet Client is an interface to interact with [Ethereum Account(s)](https://ethereum.org/en/glossary/#account) and provides the ability to retrieve accounts, execute transactions, sign messages, etc. through [Wallet Actions](https://viem.sh/docs/actions/wallet/introduction).
|
48
|
+
* A Wallet Client is an interface to interact with [Ethereum Account(s)](https://ethereum.org/en/glossary/#account) and provides the ability to retrieve accounts, execute transactions, sign messages, etc. through [Wallet Actions](https://viem.sh/docs/actions/wallet/introduction.html).
|
49
49
|
*
|
50
50
|
* The Wallet Client supports signing over:
|
51
51
|
* - [JSON-RPC Accounts](https://viem.sh/docs/clients/wallet.html#json-rpc-accounts) (e.g. Browser Extension Wallets, WalletConnect, etc).
|