viem 1.15.5 → 1.16.0
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 +8 -0
- package/_cjs/actions/public/getProof.js +16 -0
- package/_cjs/actions/public/getProof.js.map +1 -0
- package/_cjs/clients/decorators/public.js +2 -0
- package/_cjs/clients/decorators/public.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/types/eip1193.js.map +1 -1
- package/_cjs/types/proof.js +3 -0
- package/_cjs/types/proof.js.map +1 -0
- package/_cjs/types/withdrawal.js +3 -0
- package/_cjs/types/withdrawal.js.map +1 -0
- package/_cjs/utils/formatters/proof.js +22 -0
- package/_cjs/utils/formatters/proof.js.map +1 -0
- package/_esm/actions/public/getProof.js +37 -0
- package/_esm/actions/public/getProof.js.map +1 -0
- package/_esm/clients/decorators/public.js +2 -0
- package/_esm/clients/decorators/public.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/types/eip1193.js.map +1 -1
- package/_esm/types/proof.js +2 -0
- package/_esm/types/proof.js.map +1 -0
- package/_esm/types/withdrawal.js +2 -0
- package/_esm/types/withdrawal.js.map +1 -0
- package/_esm/utils/formatters/proof.js +18 -0
- package/_esm/utils/formatters/proof.js.map +1 -0
- package/_types/actions/public/getProof.d.ts +57 -0
- package/_types/actions/public/getProof.d.ts.map +1 -0
- package/_types/chains/celo/formatters.d.ts +2 -0
- package/_types/chains/celo/formatters.d.ts.map +1 -1
- package/_types/chains/definitions/base.d.ts +2 -0
- package/_types/chains/definitions/base.d.ts.map +1 -1
- package/_types/chains/definitions/baseGoerli.d.ts +2 -0
- package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/celo.d.ts +2 -0
- package/_types/chains/definitions/celo.d.ts.map +1 -1
- package/_types/chains/definitions/celoAlfajores.d.ts +2 -0
- package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
- package/_types/chains/definitions/celoCannoli.d.ts +2 -0
- package/_types/chains/definitions/celoCannoli.d.ts.map +1 -1
- package/_types/chains/definitions/optimism.d.ts +2 -0
- package/_types/chains/definitions/optimism.d.ts.map +1 -1
- package/_types/chains/definitions/optimismGoerli.d.ts +2 -0
- package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/optimismSepolia.d.ts +2 -0
- package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/zora.d.ts +2 -0
- package/_types/chains/definitions/zora.d.ts.map +1 -1
- package/_types/chains/definitions/zoraTestnet.d.ts +2 -0
- package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
- package/_types/chains/optimism/formatters.d.ts +2 -0
- package/_types/chains/optimism/formatters.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +26 -0
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +1 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/types/block.d.ts +5 -0
- package/_types/types/block.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +21 -1
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/types/proof.d.ts +18 -0
- package/_types/types/proof.d.ts.map +1 -0
- package/_types/types/rpc.d.ts +2 -0
- package/_types/types/rpc.d.ts.map +1 -1
- package/_types/types/withdrawal.d.ts +8 -0
- package/_types/types/withdrawal.d.ts.map +1 -0
- package/_types/utils/formatters/proof.d.ts +6 -0
- package/_types/utils/formatters/proof.d.ts.map +1 -0
- package/actions/public/getProof.ts +93 -0
- package/clients/decorators/public.ts +31 -0
- package/errors/version.ts +1 -1
- package/index.ts +1 -0
- package/package.json +1 -1
- package/types/block.ts +5 -0
- package/types/eip1193.ts +21 -0
- package/types/proof.ts +20 -0
- package/types/rpc.ts +2 -0
- package/types/withdrawal.ts +8 -0
- package/utils/formatters/proof.ts +24 -0
@@ -126,6 +126,11 @@ import {
|
|
126
126
|
type GetLogsReturnType,
|
127
127
|
getLogs,
|
128
128
|
} from '../../actions/public/getLogs.js'
|
129
|
+
import {
|
130
|
+
type GetProofParameters,
|
131
|
+
type GetProofReturnType,
|
132
|
+
getProof,
|
133
|
+
} from '../../actions/public/getProof.js'
|
129
134
|
import {
|
130
135
|
type GetStorageAtParameters,
|
131
136
|
type GetStorageAtReturnType,
|
@@ -1065,6 +1070,31 @@ export type PublicActions<
|
|
1065
1070
|
) => Promise<
|
1066
1071
|
GetLogsReturnType<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock>
|
1067
1072
|
>
|
1073
|
+
/**
|
1074
|
+
* Returns the account and storage values of the specified account including the Merkle-proof.
|
1075
|
+
*
|
1076
|
+
* - Docs: https://viem.sh/docs/actions/public/getProof.html
|
1077
|
+
* - JSON-RPC Methods:
|
1078
|
+
* - Calls [`eth_getProof`](https://eips.ethereum.org/EIPS/eip-1186)
|
1079
|
+
*
|
1080
|
+
* @param client - Client to use
|
1081
|
+
* @param parameters - {@link GetProofParameters}
|
1082
|
+
* @returns Proof data. {@link GetProofReturnType}
|
1083
|
+
*
|
1084
|
+
* @example
|
1085
|
+
* import { createPublicClient, http } from 'viem'
|
1086
|
+
* import { mainnet } from 'viem/chains'
|
1087
|
+
*
|
1088
|
+
* const client = createPublicClient({
|
1089
|
+
* chain: mainnet,
|
1090
|
+
* transport: http(),
|
1091
|
+
* })
|
1092
|
+
* const block = await client.getProof({
|
1093
|
+
* address: '0x...',
|
1094
|
+
* storageKeys: ['0x...'],
|
1095
|
+
* })
|
1096
|
+
*/
|
1097
|
+
getProof: (args: GetProofParameters) => Promise<GetProofReturnType>
|
1068
1098
|
/**
|
1069
1099
|
* Returns an estimate for the max priority fee per gas (in wei) for a transaction
|
1070
1100
|
* to be included in the next block.
|
@@ -1684,6 +1714,7 @@ export function publicActions<
|
|
1684
1714
|
getFilterLogs: (args) => getFilterLogs(client, args),
|
1685
1715
|
getGasPrice: () => getGasPrice(client),
|
1686
1716
|
getLogs: (args) => getLogs(client, args as any),
|
1717
|
+
getProof: (args) => getProof(client, args),
|
1687
1718
|
estimateMaxPriorityFeePerGas: (args) =>
|
1688
1719
|
estimateMaxPriorityFeePerGas(client, args),
|
1689
1720
|
getStorageAt: (args) => getStorageAt(client, args),
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '1.
|
1
|
+
export const version = '1.16.0'
|
package/index.ts
CHANGED
@@ -948,6 +948,7 @@ export type {
|
|
948
948
|
RpcTransactionRequest,
|
949
949
|
RpcUncle,
|
950
950
|
} from './types/rpc.js'
|
951
|
+
export type { Withdrawal } from './types/withdrawal.js'
|
951
952
|
export { labelhash, type LabelhashErrorType } from './utils/ens/labelhash.js'
|
952
953
|
export { namehash, type NamehashErrorType } from './utils/ens/namehash.js'
|
953
954
|
export {
|
package/package.json
CHANGED
package/types/block.ts
CHANGED
@@ -2,6 +2,7 @@ import type { Address } from 'abitype'
|
|
2
2
|
|
3
3
|
import type { Hash, Hex } from './misc.js'
|
4
4
|
import type { Transaction } from './transaction.js'
|
5
|
+
import type { Withdrawal } from './withdrawal.js'
|
5
6
|
|
6
7
|
export type Block<
|
7
8
|
TQuantity = bigint,
|
@@ -56,6 +57,10 @@ export type Block<
|
|
56
57
|
transactionsRoot: Hash
|
57
58
|
/** List of uncle hashes */
|
58
59
|
uncles: Hash[]
|
60
|
+
/** List of withdrawal objects */
|
61
|
+
withdrawals?: Withdrawal[]
|
62
|
+
/** Root of the this block’s withdrawals trie */
|
63
|
+
withdrawalsRoot?: Hex
|
59
64
|
}
|
60
65
|
|
61
66
|
export type BlockIdentifier<TQuantity = bigint> = {
|
package/types/eip1193.ts
CHANGED
@@ -9,6 +9,7 @@ import type {
|
|
9
9
|
RpcBlockNumber as BlockNumber,
|
10
10
|
RpcFeeHistory as FeeHistory,
|
11
11
|
RpcLog as Log,
|
12
|
+
RpcProof as Proof,
|
12
13
|
RpcTransaction as Transaction,
|
13
14
|
RpcTransactionReceipt as TransactionReceipt,
|
14
15
|
RpcTransactionRequest as TransactionRequest,
|
@@ -447,6 +448,26 @@ export type PublicRpcSchema = [
|
|
447
448
|
]
|
448
449
|
ReturnType: Log[]
|
449
450
|
},
|
451
|
+
/**
|
452
|
+
* @description Returns the account and storage values of the specified account including the Merkle-proof.
|
453
|
+
* @link https://eips.ethereum.org/EIPS/eip-1186
|
454
|
+
* @example
|
455
|
+
* provider.request({ method: 'eth_getProof', params: ['0x...', ['0x...'], 'latest'] })
|
456
|
+
* // => {
|
457
|
+
* // ...
|
458
|
+
* // }
|
459
|
+
*/
|
460
|
+
{
|
461
|
+
Method: 'eth_getProof'
|
462
|
+
Parameters: [
|
463
|
+
/** Address of the account. */
|
464
|
+
address: Address,
|
465
|
+
/** An array of storage-keys that should be proofed and included. */
|
466
|
+
storageKeys: Hash[],
|
467
|
+
block: BlockNumber | BlockTag,
|
468
|
+
]
|
469
|
+
ReturnType: Proof
|
470
|
+
},
|
450
471
|
/**
|
451
472
|
* @description Returns the value from a storage position at an address
|
452
473
|
* @link https://eips.ethereum.org/EIPS/eip-1474
|
package/types/proof.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
import type { Hash } from './misc.js'
|
3
|
+
|
4
|
+
export type AccountProof = Hash
|
5
|
+
|
6
|
+
export type StorageProof<TQuantity = bigint> = {
|
7
|
+
key: Hash
|
8
|
+
proof: Hash[]
|
9
|
+
value: TQuantity
|
10
|
+
}
|
11
|
+
|
12
|
+
export type Proof<TQuantity = bigint, TIndex = number> = {
|
13
|
+
address: Address
|
14
|
+
balance: TQuantity
|
15
|
+
codeHash: Hash
|
16
|
+
nonce: TIndex
|
17
|
+
storageHash: Hash
|
18
|
+
accountProof: AccountProof[]
|
19
|
+
storageProof: StorageProof<TQuantity>[]
|
20
|
+
}
|
package/types/rpc.ts
CHANGED
@@ -7,6 +7,7 @@ import type {
|
|
7
7
|
} from './block.js'
|
8
8
|
import type { FeeHistory, FeeValues } from './fee.js'
|
9
9
|
import type { Log } from './log.js'
|
10
|
+
import type { Proof } from './proof.js'
|
10
11
|
import type {
|
11
12
|
TransactionEIP1559,
|
12
13
|
TransactionEIP2930,
|
@@ -34,6 +35,7 @@ export type RpcUncle = Uncle<Quantity>
|
|
34
35
|
export type RpcFeeHistory = FeeHistory<Quantity>
|
35
36
|
export type RpcFeeValues = FeeValues<Quantity>
|
36
37
|
export type RpcLog = Log<Quantity, Index>
|
38
|
+
export type RpcProof = Proof<Quantity, Index>
|
37
39
|
export type RpcTransactionReceipt = TransactionReceipt<
|
38
40
|
Quantity,
|
39
41
|
Index,
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { ErrorType } from '../../errors/utils.js'
|
2
|
+
import type { Proof } from '../../types/proof.js'
|
3
|
+
import type { RpcProof } from '../../types/rpc.js'
|
4
|
+
import { hexToNumber } from '../index.js'
|
5
|
+
|
6
|
+
export type FormatProofErrorType = ErrorType
|
7
|
+
|
8
|
+
function formatStorageProof(storageProof: RpcProof['storageProof']) {
|
9
|
+
return storageProof.map((proof) => ({
|
10
|
+
...proof,
|
11
|
+
value: BigInt(proof.value),
|
12
|
+
}))
|
13
|
+
}
|
14
|
+
|
15
|
+
export function formatProof(proof: Partial<RpcProof>) {
|
16
|
+
return {
|
17
|
+
...proof,
|
18
|
+
balance: proof.balance ? BigInt(proof.balance) : undefined,
|
19
|
+
nonce: proof.nonce ? hexToNumber(proof.nonce) : undefined,
|
20
|
+
storageProof: proof.storageProof
|
21
|
+
? formatStorageProof(proof.storageProof)
|
22
|
+
: undefined,
|
23
|
+
} as Proof
|
24
|
+
}
|