viem 2.19.6 → 2.19.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/_cjs/actions/wallet/writeContract.js +27 -6
  3. package/_cjs/actions/wallet/writeContract.js.map +1 -1
  4. package/_cjs/chains/definitions/b3.js +27 -0
  5. package/_cjs/chains/definitions/b3.js.map +1 -0
  6. package/_cjs/chains/definitions/b3Sepolia.js +1 -1
  7. package/_cjs/chains/definitions/b3Sepolia.js.map +1 -1
  8. package/_cjs/chains/definitions/cronoszkEVM.js +23 -0
  9. package/_cjs/chains/definitions/cronoszkEVM.js.map +1 -0
  10. package/_cjs/chains/definitions/immutableZkEvm.js +1 -0
  11. package/_cjs/chains/definitions/immutableZkEvm.js.map +1 -1
  12. package/_cjs/chains/index.js +11 -7
  13. package/_cjs/chains/index.js.map +1 -1
  14. package/_cjs/errors/version.js +1 -1
  15. package/_cjs/experimental/eip7702/utils/hashAuthorization.js +1 -5
  16. package/_cjs/experimental/eip7702/utils/hashAuthorization.js.map +1 -1
  17. package/_cjs/experimental/eip7702/utils/serializeAuthorizationList.js +1 -1
  18. package/_cjs/experimental/eip7702/utils/serializeAuthorizationList.js.map +1 -1
  19. package/_cjs/index.js.map +1 -1
  20. package/_esm/actions/wallet/writeContract.js +27 -6
  21. package/_esm/actions/wallet/writeContract.js.map +1 -1
  22. package/_esm/chains/definitions/b3.js +24 -0
  23. package/_esm/chains/definitions/b3.js.map +1 -0
  24. package/_esm/chains/definitions/b3Sepolia.js +1 -1
  25. package/_esm/chains/definitions/b3Sepolia.js.map +1 -1
  26. package/_esm/chains/definitions/cronoszkEVM.js +20 -0
  27. package/_esm/chains/definitions/cronoszkEVM.js.map +1 -0
  28. package/_esm/chains/definitions/immutableZkEvm.js +1 -0
  29. package/_esm/chains/definitions/immutableZkEvm.js.map +1 -1
  30. package/_esm/chains/index.js +2 -0
  31. package/_esm/chains/index.js.map +1 -1
  32. package/_esm/errors/version.js +1 -1
  33. package/_esm/experimental/eip7702/utils/hashAuthorization.js +1 -5
  34. package/_esm/experimental/eip7702/utils/hashAuthorization.js.map +1 -1
  35. package/_esm/experimental/eip7702/utils/serializeAuthorizationList.js +1 -1
  36. package/_esm/experimental/eip7702/utils/serializeAuthorizationList.js.map +1 -1
  37. package/_esm/index.js.map +1 -1
  38. package/_types/actions/wallet/writeContract.d.ts +4 -1
  39. package/_types/actions/wallet/writeContract.d.ts.map +1 -1
  40. package/_types/chains/definitions/b3.d.ts +35 -0
  41. package/_types/chains/definitions/b3.d.ts.map +1 -0
  42. package/_types/chains/definitions/b3Sepolia.d.ts +1 -1
  43. package/_types/chains/definitions/cronoszkEVM.d.ts +35 -0
  44. package/_types/chains/definitions/cronoszkEVM.d.ts.map +1 -0
  45. package/_types/chains/definitions/immutableZkEvm.d.ts +1 -0
  46. package/_types/chains/definitions/immutableZkEvm.d.ts.map +1 -1
  47. package/_types/chains/index.d.ts +2 -0
  48. package/_types/chains/index.d.ts.map +1 -1
  49. package/_types/errors/version.d.ts +1 -1
  50. package/_types/experimental/eip7702/utils/hashAuthorization.d.ts.map +1 -1
  51. package/_types/index.d.ts +1 -1
  52. package/_types/index.d.ts.map +1 -1
  53. package/actions/wallet/writeContract.ts +54 -12
  54. package/chains/definitions/b3.ts +25 -0
  55. package/chains/definitions/b3Sepolia.ts +1 -1
  56. package/chains/definitions/cronoszkEVM.ts +20 -0
  57. package/chains/definitions/immutableZkEvm.ts +1 -0
  58. package/chains/index.ts +2 -0
  59. package/errors/version.ts +1 -1
  60. package/experimental/eip7702/utils/hashAuthorization.ts +1 -5
  61. package/experimental/eip7702/utils/serializeAuthorizationList.ts +1 -1
  62. package/index.ts +1 -0
  63. package/package.json +1 -1
@@ -1,8 +1,17 @@
1
1
  import type { Abi } from 'abitype'
2
2
 
3
3
  import type { Account } from '../../accounts/types.js'
4
+ import {
5
+ type ParseAccountErrorType,
6
+ parseAccount,
7
+ } from '../../accounts/utils/parseAccount.js'
4
8
  import type { Client } from '../../clients/createClient.js'
5
9
  import type { Transport } from '../../clients/transports/createTransport.js'
10
+ import {
11
+ AccountNotFoundError,
12
+ type AccountNotFoundErrorType,
13
+ } from '../../errors/account.js'
14
+ import type { BaseError } from '../../errors/base.js'
6
15
  import type { ErrorType } from '../../errors/utils.js'
7
16
  import type { GetAccountParameter } from '../../types/account.js'
8
17
  import type {
@@ -22,6 +31,10 @@ import {
22
31
  type EncodeFunctionDataParameters,
23
32
  encodeFunctionData,
24
33
  } from '../../utils/abi/encodeFunctionData.js'
34
+ import {
35
+ type GetContractErrorReturnType,
36
+ getContractError,
37
+ } from '../../utils/errors/getContractError.js'
25
38
  import type { FormattedTransactionRequest } from '../../utils/formatters/transactionRequest.js'
26
39
  import { getAction } from '../../utils/getAction.js'
27
40
  import type { GetMutabilityAwareValue } from '../public/simulateContract.js'
@@ -81,7 +94,9 @@ export type WriteContractReturnType = SendTransactionReturnType
81
94
 
82
95
  export type WriteContractErrorType =
83
96
  | EncodeFunctionDataErrorType
84
- | SendTransactionErrorType
97
+ | AccountNotFoundErrorType
98
+ | ParseAccountErrorType
99
+ | GetContractErrorReturnType<SendTransactionErrorType>
85
100
  | ErrorType
86
101
 
87
102
  /**
@@ -156,20 +171,47 @@ export async function writeContract<
156
171
  chainOverride
157
172
  >,
158
173
  ): Promise<WriteContractReturnType> {
159
- const { abi, address, args, dataSuffix, functionName, ...request } =
160
- parameters as WriteContractParameters
174
+ const {
175
+ abi,
176
+ account: account_ = client.account,
177
+ address,
178
+ args,
179
+ dataSuffix,
180
+ functionName,
181
+ ...request
182
+ } = parameters as WriteContractParameters
183
+
184
+ if (!account_)
185
+ throw new AccountNotFoundError({
186
+ docsPath: '/docs/contract/writeContract',
187
+ })
188
+ const account = parseAccount(account_)
189
+
161
190
  const data = encodeFunctionData({
162
191
  abi,
163
192
  args,
164
193
  functionName,
165
194
  } as EncodeFunctionDataParameters)
166
- return getAction(
167
- client,
168
- sendTransaction,
169
- 'sendTransaction',
170
- )({
171
- data: `${data}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
172
- to: address,
173
- ...request,
174
- })
195
+
196
+ try {
197
+ return await getAction(
198
+ client,
199
+ sendTransaction,
200
+ 'sendTransaction',
201
+ )({
202
+ data: `${data}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
203
+ to: address,
204
+ account,
205
+ ...request,
206
+ })
207
+ } catch (error) {
208
+ throw getContractError(error as BaseError, {
209
+ abi,
210
+ address,
211
+ args,
212
+ docsPath: '/docs/contract/writeContract',
213
+ functionName,
214
+ sender: account.address,
215
+ })
216
+ }
175
217
  }
@@ -0,0 +1,25 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ const sourceId = 8453 // base
4
+
5
+ export const b3 = /*#__PURE__*/ defineChain({
6
+ id: 8333,
7
+ name: 'B3',
8
+ nativeCurrency: {
9
+ name: 'Ether',
10
+ symbol: 'ETH',
11
+ decimals: 18,
12
+ },
13
+ rpcUrls: {
14
+ default: {
15
+ http: ['https://mainnet-rpc.b3.fun/http'],
16
+ },
17
+ },
18
+ blockExplorers: {
19
+ default: {
20
+ name: 'Blockscout',
21
+ url: 'https://explorer.b3.fun',
22
+ },
23
+ },
24
+ sourceId,
25
+ })
@@ -12,7 +12,7 @@ export const b3Sepolia = /*#__PURE__*/ defineChain({
12
12
  },
13
13
  rpcUrls: {
14
14
  default: {
15
- http: ['https://sepolia.b3.fun'],
15
+ http: ['https://sepolia.b3.fun/http'],
16
16
  },
17
17
  },
18
18
  blockExplorers: {
@@ -0,0 +1,20 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const cronoszkEVM = /*#__PURE__*/ defineChain({
4
+ id: 388,
5
+ name: 'Cronos zkEVM Mainnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'Cronos zkEVM CRO',
9
+ symbol: 'zkCRO',
10
+ },
11
+ rpcUrls: {
12
+ default: { http: ['https://mainnet.zkevm.cronos.org'] },
13
+ },
14
+ blockExplorers: {
15
+ default: {
16
+ name: 'Cronos zkEVM (Mainnet) Chain Explorer',
17
+ url: 'https://explorer.zkevm.cronos.org',
18
+ },
19
+ },
20
+ })
@@ -17,6 +17,7 @@ export const immutableZkEvm = /*#__PURE__*/ defineChain({
17
17
  default: {
18
18
  name: 'Immutable Explorer',
19
19
  url: 'https://explorer.immutable.com',
20
+ apiUrl: 'https://explorer.immutable.com/api',
20
21
  },
21
22
  },
22
23
  contracts: {
package/chains/index.ts CHANGED
@@ -25,6 +25,7 @@ export { auroria } from './definitions/auroria.js'
25
25
  export { avalanche } from './definitions/avalanche.js'
26
26
  export { avalancheFuji } from './definitions/avalancheFuji.js'
27
27
  export { b3Sepolia } from './definitions/b3Sepolia.js'
28
+ export { b3 } from './definitions/b3.js'
28
29
  export { bahamut } from './definitions/bahamut.js'
29
30
  export { base } from './definitions/base.js'
30
31
  export { baseGoerli } from './definitions/baseGoerli.js'
@@ -66,6 +67,7 @@ export { confluxESpaceTestnet } from './definitions/confluxESpaceTestnet.js'
66
67
  export { coreDao } from './definitions/coreDao.js'
67
68
  export { crab } from './definitions/crab.js'
68
69
  export { cronos } from './definitions/cronos.js'
70
+ export { cronoszkEVM } from './definitions/cronoszkEVM.js'
69
71
  export { cronoszkEVMTestnet } from './definitions/cronoszkEVMTestnet.js'
70
72
  export { cronosTestnet } from './definitions/cronosTestnet.js'
71
73
  export { crossbell } from './definitions/crossbell.js'
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.19.6'
1
+ export const version = '2.19.7'
@@ -48,11 +48,7 @@ export function hashAuthorization<to extends To = 'hex'>(
48
48
  const hash = keccak256(
49
49
  concatHex([
50
50
  '0x05',
51
- toRlp([
52
- numberToHex(chainId),
53
- contractAddress,
54
- [nonce ? numberToHex(nonce) : '0x'],
55
- ]),
51
+ toRlp([numberToHex(chainId), contractAddress, numberToHex(nonce)]),
56
52
  ]),
57
53
  )
58
54
  if (to === 'bytes') return hexToBytes(hash) as HashAuthorizationReturnType<to>
@@ -24,7 +24,7 @@ export function serializeAuthorizationList(
24
24
  serializedAuthorizationList.push([
25
25
  toHex(chainId),
26
26
  contractAddress,
27
- [nonce ? toHex(nonce) : '0x'],
27
+ toHex(nonce),
28
28
  ...toYParitySignatureArray({}, signature),
29
29
  ])
30
30
  }
package/index.ts CHANGED
@@ -1049,6 +1049,7 @@ export type {
1049
1049
  ProviderConnectInfo,
1050
1050
  ProviderMessage,
1051
1051
  PublicRpcSchema,
1052
+ PaymasterRpcSchema,
1052
1053
  NetworkSync,
1053
1054
  RpcSchema,
1054
1055
  RpcSchemaOverride,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.19.6",
4
+ "version": "2.19.7",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",