viem 2.0.0-alpha.10 → 2.0.0-alpha.11
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/_cjs/actions/getContract.js +16 -0
- package/_cjs/actions/getContract.js.map +1 -1
- package/_cjs/actions/public/getContractEvents.js +26 -0
- package/_cjs/actions/public/getContractEvents.js.map +1 -0
- package/_cjs/actions/public/watchContractEvent.js +4 -7
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/chains/definitions/moonbeamDev.js +25 -0
- package/_cjs/chains/definitions/moonbeamDev.js.map +1 -0
- package/_cjs/chains/definitions/optimismSepolia.js +39 -0
- package/_cjs/chains/definitions/optimismSepolia.js.map +1 -0
- package/_cjs/chains/definitions/sepolia.js +1 -1
- package/_cjs/chains/definitions/sepolia.js.map +1 -1
- package/_cjs/chains/index.js +6 -2
- package/_cjs/chains/index.js.map +1 -1
- 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 +5 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/utils/hash/getEventSelector.js +5 -6
- package/_cjs/utils/hash/getEventSelector.js.map +1 -1
- package/_cjs/utils/hash/getEventSignature.js +9 -0
- package/_cjs/utils/hash/getEventSignature.js.map +1 -0
- package/_cjs/utils/hash/getFunctionSelector.js +5 -6
- package/_cjs/utils/hash/getFunctionSelector.js.map +1 -1
- package/_cjs/utils/hash/getFunctionSignature.js +15 -0
- package/_cjs/utils/hash/getFunctionSignature.js.map +1 -0
- package/_cjs/utils/hash/hashFunction.js +2 -4
- package/_cjs/utils/hash/hashFunction.js.map +1 -1
- package/_esm/actions/getContract.js +16 -0
- package/_esm/actions/getContract.js.map +1 -1
- package/_esm/actions/public/getContractEvents.js +48 -0
- package/_esm/actions/public/getContractEvents.js.map +1 -0
- package/_esm/actions/public/watchContractEvent.js +4 -7
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/chains/definitions/moonbeamDev.js +22 -0
- package/_esm/chains/definitions/moonbeamDev.js.map +1 -0
- package/_esm/chains/definitions/optimismSepolia.js +36 -0
- package/_esm/chains/definitions/optimismSepolia.js.map +1 -0
- package/_esm/chains/definitions/sepolia.js +1 -1
- package/_esm/chains/definitions/sepolia.js.map +1 -1
- package/_esm/chains/index.js +2 -0
- package/_esm/chains/index.js.map +1 -1
- 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 +2 -0
- package/_esm/index.js.map +1 -1
- package/_esm/utils/hash/getEventSelector.js +5 -6
- package/_esm/utils/hash/getEventSelector.js.map +1 -1
- package/_esm/utils/hash/getEventSignature.js +5 -0
- package/_esm/utils/hash/getEventSignature.js.map +1 -0
- package/_esm/utils/hash/getFunctionSelector.js +5 -6
- package/_esm/utils/hash/getFunctionSelector.js.map +1 -1
- package/_esm/utils/hash/getFunctionSignature.js +11 -0
- package/_esm/utils/hash/getFunctionSignature.js.map +1 -0
- package/_esm/utils/hash/hashFunction.js +2 -4
- package/_esm/utils/hash/hashFunction.js.map +1 -1
- package/_types/actions/getContract.d.ts +29 -0
- package/_types/actions/getContract.d.ts.map +1 -1
- package/_types/actions/public/createContractEventFilter.d.ts +1 -1
- package/_types/actions/public/createContractEventFilter.d.ts.map +1 -1
- package/_types/actions/public/getContractEvents.d.ts +62 -0
- package/_types/actions/public/getContractEvents.d.ts.map +1 -0
- package/_types/actions/public/watchContractEvent.d.ts +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/chains/definitions/moonbeamDev.d.ts +24 -0
- package/_types/chains/definitions/moonbeamDev.d.ts.map +1 -0
- package/_types/chains/definitions/optimismSepolia.d.ts +1524 -0
- package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -0
- package/_types/chains/definitions/sepolia.d.ts +1 -1
- package/_types/chains/index.d.ts +2 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +27 -0
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/utils/abi/decodeEventLog.d.ts +2 -2
- package/_types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/_types/utils/hash/getEventSelector.d.ts +1 -2
- package/_types/utils/hash/getEventSelector.d.ts.map +1 -1
- package/_types/utils/hash/getEventSignature.d.ts +3 -0
- package/_types/utils/hash/getEventSignature.d.ts.map +1 -0
- package/_types/utils/hash/getFunctionSelector.d.ts.map +1 -1
- package/_types/utils/hash/getFunctionSignature.d.ts +3 -0
- package/_types/utils/hash/getFunctionSignature.d.ts.map +1 -0
- package/_types/utils/hash/hashFunction.d.ts.map +1 -1
- package/actions/getContract.ts +95 -0
- package/actions/public/createContractEventFilter.ts +1 -1
- package/actions/public/getContractEvents.ts +155 -0
- package/actions/public/watchContractEvent.ts +10 -13
- package/chains/definitions/moonbeamDev.ts +22 -0
- package/chains/definitions/optimismSepolia.ts +39 -0
- package/chains/definitions/sepolia.ts +1 -1
- package/chains/index.ts +2 -0
- package/clients/decorators/public.ts +48 -0
- package/errors/version.ts +1 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/utils/abi/decodeEventLog.ts +2 -2
- package/utils/hash/getEventSelector.ts +7 -6
- package/utils/hash/getEventSignature.ts +7 -0
- package/utils/hash/getFunctionSelector.ts +7 -5
- package/utils/hash/getFunctionSignature.ts +17 -0
- package/utils/hash/hashFunction.ts +2 -7
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Abi,
|
1
|
+
import type { Abi, Address, ExtractAbiEvent } from 'abitype'
|
2
2
|
|
3
3
|
import type { Client } from '../../clients/createClient.js'
|
4
4
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
@@ -21,18 +21,17 @@ import {
|
|
21
21
|
type EncodeEventTopicsParameters,
|
22
22
|
encodeEventTopics,
|
23
23
|
} from '../../utils/abi/encodeEventTopics.js'
|
24
|
-
import {
|
25
|
-
type GetAbiItemParameters,
|
26
|
-
getAbiItem,
|
27
|
-
} from '../../utils/abi/getAbiItem.js'
|
28
24
|
import { formatLog } from '../../utils/formatters/log.js'
|
29
25
|
import { observe } from '../../utils/observe.js'
|
30
26
|
import { poll } from '../../utils/poll.js'
|
31
27
|
import { stringify } from '../../utils/stringify.js'
|
32
28
|
import { createContractEventFilter } from './createContractEventFilter.js'
|
33
29
|
import { getBlockNumber } from './getBlockNumber.js'
|
30
|
+
import {
|
31
|
+
type GetContractEventsParameters,
|
32
|
+
getContractEvents,
|
33
|
+
} from './getContractEvents.js'
|
34
34
|
import { getFilterChanges } from './getFilterChanges.js'
|
35
|
-
import { getLogs } from './getLogs.js'
|
36
35
|
import { uninstallFilter } from './uninstallFilter.js'
|
37
36
|
|
38
37
|
export type WatchContractEventOnLogsParameter<
|
@@ -85,7 +84,7 @@ export type WatchContractEventParameters<
|
|
85
84
|
* Whether or not the logs must match the indexed/non-indexed arguments on `event`.
|
86
85
|
* @default false
|
87
86
|
*/
|
88
|
-
strict?: strict | undefined
|
87
|
+
strict?: strict | boolean | undefined
|
89
88
|
} & GetPollOptions<transport>
|
90
89
|
|
91
90
|
export type WatchContractEventReturnType = () => void
|
@@ -194,16 +193,14 @@ export function watchContractEvent<
|
|
194
193
|
// If the block number doesn't exist, we are yet to reach the first poll interval,
|
195
194
|
// so do not emit any logs.
|
196
195
|
if (previousBlockNumber && previousBlockNumber !== blockNumber) {
|
197
|
-
logs = await
|
196
|
+
logs = await getContractEvents(client, {
|
197
|
+
abi,
|
198
198
|
address,
|
199
199
|
args: args as any,
|
200
200
|
fromBlock: previousBlockNumber + 1n,
|
201
201
|
toBlock: blockNumber,
|
202
|
-
|
203
|
-
|
204
|
-
name: eventName,
|
205
|
-
} as unknown as GetAbiItemParameters) as AbiEvent,
|
206
|
-
})
|
202
|
+
strict,
|
203
|
+
} as {} as GetContractEventsParameters)
|
207
204
|
} else {
|
208
205
|
logs = []
|
209
206
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { defineChain } from '../../utils/chain.js'
|
2
|
+
|
3
|
+
export const moonbeamDev = /*#__PURE__*/ defineChain({
|
4
|
+
id: 1281,
|
5
|
+
name: 'Moonbeam Development Node',
|
6
|
+
network: 'development',
|
7
|
+
nativeCurrency: {
|
8
|
+
decimals: 18,
|
9
|
+
name: 'DEV',
|
10
|
+
symbol: 'DEV',
|
11
|
+
},
|
12
|
+
rpcUrls: {
|
13
|
+
default: {
|
14
|
+
http: ['http://127.0.0.1:9944'],
|
15
|
+
webSocket: ['wss://127.0.0.1:9944'],
|
16
|
+
},
|
17
|
+
public: {
|
18
|
+
http: ['http://127.0.0.1:9944'],
|
19
|
+
webSocket: ['wss://127.0.0.1:9944'],
|
20
|
+
},
|
21
|
+
},
|
22
|
+
})
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { defineChain } from '../../utils/chain.js'
|
2
|
+
import { formattersOptimism } from '../optimism/formatters.js'
|
3
|
+
|
4
|
+
export const optimismSepolia = /*#__PURE__*/ defineChain(
|
5
|
+
{
|
6
|
+
id: 11155420,
|
7
|
+
name: 'Optimism Sepolia',
|
8
|
+
network: 'optimism-sepolia',
|
9
|
+
nativeCurrency: { name: 'Sepolia Ether', symbol: 'ETH', decimals: 18 },
|
10
|
+
rpcUrls: {
|
11
|
+
default: {
|
12
|
+
http: ['https://sepolia.optimism.io'],
|
13
|
+
},
|
14
|
+
public: {
|
15
|
+
http: ['https://sepolia.optimism.io'],
|
16
|
+
},
|
17
|
+
},
|
18
|
+
blockExplorers: {
|
19
|
+
blockscout: {
|
20
|
+
name: 'Blockscout',
|
21
|
+
url: 'https://optimism-sepolia.blockscout.com',
|
22
|
+
},
|
23
|
+
default: {
|
24
|
+
name: 'Blockscout',
|
25
|
+
url: 'https://optimism-sepolia.blockscout.com',
|
26
|
+
},
|
27
|
+
},
|
28
|
+
contracts: {
|
29
|
+
multicall3: {
|
30
|
+
address: '0xca11bde05977b3631167028862be2a173976ca11',
|
31
|
+
blockCreated: 1620204,
|
32
|
+
},
|
33
|
+
},
|
34
|
+
testnet: true,
|
35
|
+
},
|
36
|
+
{
|
37
|
+
formatters: formattersOptimism,
|
38
|
+
},
|
39
|
+
)
|
@@ -34,7 +34,7 @@ export const sepolia = /*#__PURE__*/ defineChain({
|
|
34
34
|
contracts: {
|
35
35
|
multicall3: {
|
36
36
|
address: '0xca11bde05977b3631167028862be2a173976ca11',
|
37
|
-
blockCreated:
|
37
|
+
blockCreated: 751532,
|
38
38
|
},
|
39
39
|
ensRegistry: { address: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e' },
|
40
40
|
ensUniversalResolver: {
|
package/chains/index.ts
CHANGED
@@ -80,6 +80,7 @@ export { mevTestnet } from './definitions/mevTestnet.js'
|
|
80
80
|
export { modeTestnet } from './definitions/modeTestnet.js'
|
81
81
|
export { moonbaseAlpha } from './definitions/moonbaseAlpha.js'
|
82
82
|
export { moonbeam } from './definitions/moonbeam.js'
|
83
|
+
export { moonbeamDev } from './definitions/moonbeamDev.js'
|
83
84
|
export { moonriver } from './definitions/moonriver.js'
|
84
85
|
export { neonDevnet } from './definitions/neonDevnet.js'
|
85
86
|
export { nexi } from './definitions/nexi.js'
|
@@ -88,6 +89,7 @@ export { oasys } from './definitions/oasys.js'
|
|
88
89
|
export { okc } from './definitions/okc.js'
|
89
90
|
export { optimism } from './definitions/optimism.js'
|
90
91
|
export { optimismGoerli } from './definitions/optimismGoerli.js'
|
92
|
+
export { optimismSepolia } from './definitions/optimismSepolia.js'
|
91
93
|
export { opBNB } from './definitions/opBNB.js'
|
92
94
|
export { opBNBTestnet } from './definitions/opBNBTestnet.js'
|
93
95
|
export { plinga } from './definitions/plinga.js'
|
@@ -97,6 +97,11 @@ import {
|
|
97
97
|
type GetChainIdReturnType,
|
98
98
|
getChainId,
|
99
99
|
} from '../../actions/public/getChainId.js'
|
100
|
+
import {
|
101
|
+
type GetContractEventsParameters,
|
102
|
+
type GetContractEventsReturnType,
|
103
|
+
getContractEvents,
|
104
|
+
} from '../../actions/public/getContractEvents.js'
|
100
105
|
import {
|
101
106
|
type GetFeeHistoryParameters,
|
102
107
|
type GetFeeHistoryReturnType,
|
@@ -624,6 +629,48 @@ export type PublicActions<
|
|
624
629
|
* // 1
|
625
630
|
*/
|
626
631
|
getChainId: () => Promise<GetChainIdReturnType>
|
632
|
+
/**
|
633
|
+
* Returns a list of event logs emitted by a contract.
|
634
|
+
*
|
635
|
+
* - Docs: https://viem.sh/docs/actions/public/getContractEvents.html
|
636
|
+
* - JSON-RPC Methods: [`eth_getLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs)
|
637
|
+
*
|
638
|
+
* @param client - Client to use
|
639
|
+
* @param parameters - {@link GetContractEventsParameters}
|
640
|
+
* @returns A list of event logs. {@link GetContractEventsReturnType}
|
641
|
+
*
|
642
|
+
* @example
|
643
|
+
* import { createPublicClient, http } from 'viem'
|
644
|
+
* import { mainnet } from 'viem/chains'
|
645
|
+
* import { wagmiAbi } from './abi'
|
646
|
+
*
|
647
|
+
* const client = createPublicClient({
|
648
|
+
* chain: mainnet,
|
649
|
+
* transport: http(),
|
650
|
+
* })
|
651
|
+
* const logs = await client.getContractEvents(client, {
|
652
|
+
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
653
|
+
* abi: wagmiAbi,
|
654
|
+
* eventName: 'Transfer'
|
655
|
+
* })
|
656
|
+
*/
|
657
|
+
getContractEvents: <
|
658
|
+
const abi extends Abi | readonly unknown[],
|
659
|
+
eventName extends ContractEventName<abi> | undefined = undefined,
|
660
|
+
strict extends boolean | undefined = undefined,
|
661
|
+
fromBlock extends BlockNumber | BlockTag | undefined = undefined,
|
662
|
+
toBlock extends BlockNumber | BlockTag | undefined = undefined,
|
663
|
+
>(
|
664
|
+
args: GetContractEventsParameters<
|
665
|
+
abi,
|
666
|
+
eventName,
|
667
|
+
strict,
|
668
|
+
fromBlock,
|
669
|
+
toBlock
|
670
|
+
>,
|
671
|
+
) => Promise<
|
672
|
+
GetContractEventsReturnType<abi, eventName, strict, fromBlock, toBlock>
|
673
|
+
>
|
627
674
|
/**
|
628
675
|
* Gets address for ENS name.
|
629
676
|
*
|
@@ -1645,6 +1692,7 @@ export function publicActions<
|
|
1645
1692
|
getBlockTransactionCount: (args) => getBlockTransactionCount(client, args),
|
1646
1693
|
getBytecode: (args) => getBytecode(client, args),
|
1647
1694
|
getChainId: () => getChainId(client),
|
1695
|
+
getContractEvents: (args) => getContractEvents(client, args),
|
1648
1696
|
getEnsAddress: (args) => getEnsAddress(client, args),
|
1649
1697
|
getEnsAvatar: (args) => getEnsAvatar(client, args),
|
1650
1698
|
getEnsName: (args) => getEnsName(client, args),
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '2.0.0-alpha.
|
1
|
+
export const version = '2.0.0-alpha.11'
|
package/index.ts
CHANGED
@@ -868,7 +868,9 @@ export { fromRlp } from './utils/encoding/fromRlp.js'
|
|
868
868
|
export { getAddress } from './utils/address/getAddress.js'
|
869
869
|
export { getContractError } from './utils/errors/getContractError.js'
|
870
870
|
export { getEventSelector } from './utils/hash/getEventSelector.js'
|
871
|
+
export { getEventSignature } from './utils/hash/getEventSignature.js'
|
871
872
|
export { getFunctionSelector } from './utils/hash/getFunctionSelector.js'
|
873
|
+
export { getFunctionSignature } from './utils/hash/getFunctionSignature.js'
|
872
874
|
export { hashMessage } from './utils/signature/hashMessage.js'
|
873
875
|
export { isAddress } from './utils/address/isAddress.js'
|
874
876
|
export { isAddressEqual } from './utils/address/isAddressEqual.js'
|
package/package.json
CHANGED
@@ -31,9 +31,9 @@ export type DecodeEventLogParameters<
|
|
31
31
|
strict extends boolean = true,
|
32
32
|
> = {
|
33
33
|
abi: abi
|
34
|
-
data?: data
|
34
|
+
data?: data | undefined
|
35
35
|
eventName?: eventName | ContractEventName<abi>
|
36
|
-
strict?: strict
|
36
|
+
strict?: strict | boolean | undefined
|
37
37
|
topics: [signature: Hex, ...args: topics] | []
|
38
38
|
}
|
39
39
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import type { AbiEvent } from 'abitype'
|
2
|
-
import type { EventDefinition } from '../../types/contract.js'
|
3
2
|
|
4
|
-
import {
|
3
|
+
import { toBytes } from '../encoding/toBytes.js'
|
4
|
+
import { getEventSignature } from './getEventSignature.js'
|
5
|
+
import { keccak256 } from './keccak256.js'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
const hash = (value: string) => keccak256(toBytes(value))
|
8
|
+
|
9
|
+
export const getEventSelector = (fn: string | AbiEvent) =>
|
10
|
+
hash(getEventSignature(fn))
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import type { AbiFunction } from 'abitype'
|
2
2
|
import { slice } from '../data/slice.js'
|
3
3
|
|
4
|
-
import {
|
4
|
+
import { toBytes } from '../encoding/toBytes.js'
|
5
|
+
import { getFunctionSignature } from './getFunctionSignature.js'
|
6
|
+
import { keccak256 } from './keccak256.js'
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
const hash = (value: string) => keccak256(toBytes(value))
|
9
|
+
|
10
|
+
export const getFunctionSelector = (fn: string | AbiFunction) =>
|
11
|
+
slice(hash(getFunctionSignature(fn)), 0, 4)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { AbiFunction } from 'abitype'
|
2
|
+
|
3
|
+
import { formatAbiItem } from '../abi/formatAbiItem.js'
|
4
|
+
import {
|
5
|
+
extractFunctionName,
|
6
|
+
extractFunctionParams,
|
7
|
+
} from '../contract/extractFunctionParts.js'
|
8
|
+
|
9
|
+
export const getFunctionSignature = (fn: string | AbiFunction) => {
|
10
|
+
if (typeof fn === 'string') {
|
11
|
+
const name = extractFunctionName(fn)
|
12
|
+
const params = extractFunctionParams(fn) || []
|
13
|
+
return `${name}(${params.map(({ type }) => type).join(',')})`
|
14
|
+
}
|
15
|
+
|
16
|
+
return formatAbiItem(fn)
|
17
|
+
}
|
@@ -1,19 +1,14 @@
|
|
1
1
|
import type { AbiEvent, AbiFunction } from 'abitype'
|
2
2
|
import { formatAbiItem } from '../abi/formatAbiItem.js'
|
3
|
-
import {
|
4
|
-
extractFunctionName,
|
5
|
-
extractFunctionParams,
|
6
|
-
} from '../contract/extractFunctionParts.js'
|
7
3
|
import { toBytes } from '../encoding/toBytes.js'
|
8
4
|
|
5
|
+
import { getFunctionSignature } from './getFunctionSignature.js'
|
9
6
|
import { keccak256 } from './keccak256.js'
|
10
7
|
|
11
8
|
const hash = (value: string) => keccak256(toBytes(value))
|
12
9
|
|
13
10
|
export function hashFunction(def: string) {
|
14
|
-
|
15
|
-
const params = extractFunctionParams(def) || []
|
16
|
-
return hash(`${name}(${params.map(({ type }) => type).join(',')})`)
|
11
|
+
return hash(getFunctionSignature(def))
|
17
12
|
}
|
18
13
|
|
19
14
|
export function hashAbiItem(abiItem: AbiFunction | AbiEvent) {
|