viem 1.6.7 → 1.8.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/README.md +6 -0
- package/dist/cjs/actions/index.js +8 -2
- package/dist/cjs/actions/index.js.map +1 -1
- package/dist/cjs/actions/public/estimateFeesPerGas.js +60 -0
- package/dist/cjs/actions/public/estimateFeesPerGas.js.map +1 -0
- package/dist/cjs/actions/public/estimateGas.js +2 -2
- package/dist/cjs/actions/public/estimateGas.js.map +1 -1
- package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js +44 -0
- package/dist/cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -0
- package/dist/cjs/actions/public/verifyHash.js.map +1 -1
- package/dist/cjs/actions/public/verifyMessage.js.map +1 -1
- package/dist/cjs/actions/public/verifyTypedData.js.map +1 -1
- package/dist/cjs/actions/public/watchContractEvent.js +10 -7
- package/dist/cjs/actions/public/watchContractEvent.js.map +1 -1
- package/dist/cjs/actions/wallet/deployContract.js.map +1 -1
- package/dist/cjs/actions/wallet/prepareTransactionRequest.js +70 -0
- package/dist/cjs/actions/wallet/prepareTransactionRequest.js.map +1 -0
- package/dist/cjs/actions/wallet/sendRawTransaction.js +11 -0
- package/dist/cjs/actions/wallet/sendRawTransaction.js.map +1 -0
- package/dist/cjs/actions/wallet/sendTransaction.js +6 -6
- package/dist/cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/cjs/actions/wallet/signTransaction.js +47 -0
- package/dist/cjs/actions/wallet/signTransaction.js.map +1 -0
- package/dist/cjs/actions/wallet/writeContract.js.map +1 -1
- package/dist/cjs/chains/celo/formatters.js +4 -1
- package/dist/cjs/chains/celo/formatters.js.map +1 -1
- package/dist/cjs/clients/createTestClient.js.map +1 -1
- package/dist/cjs/clients/decorators/public.js +8 -0
- package/dist/cjs/clients/decorators/public.js.map +1 -1
- package/dist/cjs/clients/decorators/wallet.js +6 -0
- package/dist/cjs/clients/decorators/wallet.js.map +1 -1
- package/dist/cjs/errors/fee.js +42 -0
- package/dist/cjs/errors/fee.js.map +1 -0
- package/dist/cjs/errors/version.js +1 -1
- package/dist/cjs/index.js +9 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/public.js +5 -1
- package/dist/cjs/public.js.map +1 -1
- package/dist/cjs/utils/data/isBytesEqual.js +4 -3
- package/dist/cjs/utils/data/isBytesEqual.js.map +1 -1
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js +2 -2
- package/dist/cjs/utils/ens/encodedLabelToLabelhash.js.map +1 -1
- package/dist/cjs/utils/formatters/transactionRequest.js +9 -1
- package/dist/cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/cjs/utils/index.js +3 -3
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/esm/actions/index.js +3 -0
- package/dist/esm/actions/index.js.map +1 -1
- package/dist/esm/actions/public/estimateFeesPerGas.js +78 -0
- package/dist/esm/actions/public/estimateFeesPerGas.js.map +1 -0
- package/dist/esm/actions/public/estimateGas.js +2 -2
- package/dist/esm/actions/public/estimateGas.js.map +1 -1
- package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js +64 -0
- package/dist/esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -0
- package/dist/esm/actions/public/verifyHash.js.map +1 -1
- package/dist/esm/actions/public/verifyMessage.js.map +1 -1
- package/dist/esm/actions/public/verifyTypedData.js.map +1 -1
- package/dist/esm/actions/public/watchContractEvent.js +5 -2
- package/dist/esm/actions/public/watchContractEvent.js.map +1 -1
- package/dist/esm/actions/wallet/deployContract.js.map +1 -1
- package/dist/esm/actions/wallet/prepareTransactionRequest.js +109 -0
- package/dist/esm/actions/wallet/prepareTransactionRequest.js.map +1 -0
- package/dist/esm/actions/wallet/sendRawTransaction.js +31 -0
- package/dist/esm/actions/wallet/sendRawTransaction.js.map +1 -0
- package/dist/esm/actions/wallet/sendTransaction.js +6 -6
- package/dist/esm/actions/wallet/sendTransaction.js.map +1 -1
- package/dist/esm/actions/wallet/signTransaction.js +87 -0
- package/dist/esm/actions/wallet/signTransaction.js.map +1 -0
- package/dist/esm/actions/wallet/writeContract.js.map +1 -1
- package/dist/esm/chains/celo/formatters.js +4 -1
- package/dist/esm/chains/celo/formatters.js.map +1 -1
- package/dist/esm/clients/createTestClient.js.map +1 -1
- package/dist/esm/clients/decorators/public.js +8 -0
- package/dist/esm/clients/decorators/public.js.map +1 -1
- package/dist/esm/clients/decorators/wallet.js +6 -0
- package/dist/esm/clients/decorators/wallet.js.map +1 -1
- package/dist/esm/errors/fee.js +36 -0
- package/dist/esm/errors/fee.js.map +1 -0
- package/dist/esm/errors/version.js +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/public.js +2 -0
- package/dist/esm/public.js.map +1 -1
- package/dist/esm/utils/data/isBytesEqual.js +2 -1
- package/dist/esm/utils/data/isBytesEqual.js.map +1 -1
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js +1 -1
- package/dist/esm/utils/ens/encodedLabelToLabelhash.js.map +1 -1
- package/dist/esm/utils/formatters/transactionRequest.js +8 -0
- package/dist/esm/utils/formatters/transactionRequest.js.map +1 -1
- package/dist/esm/utils/index.js +3 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/types/actions/index.d.ts +3 -0
- package/dist/types/actions/index.d.ts.map +1 -1
- package/dist/types/actions/public/estimateFeesPerGas.d.ts +48 -0
- package/dist/types/actions/public/estimateFeesPerGas.d.ts.map +1 -0
- package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts +37 -0
- package/dist/types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -0
- package/dist/types/actions/public/verifyHash.d.ts +1 -1
- package/dist/types/actions/public/verifyHash.d.ts.map +1 -1
- package/dist/types/actions/public/verifyMessage.d.ts +2 -2
- package/dist/types/actions/public/verifyMessage.d.ts.map +1 -1
- package/dist/types/actions/public/verifyTypedData.d.ts +2 -2
- package/dist/types/actions/public/verifyTypedData.d.ts.map +1 -1
- package/dist/types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/dist/types/actions/wallet/deployContract.d.ts +2 -1
- package/dist/types/actions/wallet/deployContract.d.ts.map +1 -1
- package/dist/types/actions/wallet/prepareTransactionRequest.d.ts +52 -0
- package/dist/types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -0
- package/dist/types/actions/wallet/sendRawTransaction.d.ts +38 -0
- package/dist/types/actions/wallet/sendRawTransaction.d.ts.map +1 -0
- package/dist/types/actions/wallet/sendTransaction.d.ts +2 -1
- package/dist/types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/dist/types/actions/wallet/signTransaction.d.ts +55 -0
- package/dist/types/actions/wallet/signTransaction.d.ts.map +1 -0
- package/dist/types/actions/wallet/writeContract.d.ts +2 -1
- package/dist/types/actions/wallet/writeContract.d.ts.map +1 -1
- package/dist/types/chains/celo/formatters.d.ts +303 -5
- package/dist/types/chains/celo/formatters.d.ts.map +1 -1
- package/dist/types/chains/celo/types.d.ts +43 -17
- package/dist/types/chains/celo/types.d.ts.map +1 -1
- package/dist/types/chains/index.d.ts +1084 -190
- package/dist/types/chains/index.d.ts.map +1 -1
- package/dist/types/chains/utils.d.ts +1 -1
- package/dist/types/chains/utils.d.ts.map +1 -1
- package/dist/types/clients/createTestClient.d.ts +1 -1
- package/dist/types/clients/createTestClient.d.ts.map +1 -1
- package/dist/types/clients/decorators/public.d.ts +112 -0
- package/dist/types/clients/decorators/public.d.ts.map +1 -1
- package/dist/types/clients/decorators/wallet.d.ts +111 -0
- package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
- package/dist/types/errors/fee.d.ts +16 -0
- package/dist/types/errors/fee.d.ts.map +1 -0
- package/dist/types/errors/version.d.ts +1 -1
- package/dist/types/index.d.ts +22 -16
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/public.d.ts +2 -0
- package/dist/types/public.d.ts.map +1 -1
- package/dist/types/types/chain.d.ts +64 -11
- package/dist/types/types/chain.d.ts.map +1 -1
- package/dist/types/types/eip1193.d.ts +13 -1
- package/dist/types/types/eip1193.d.ts.map +1 -1
- package/dist/types/types/fee.d.ts +1 -0
- package/dist/types/types/fee.d.ts.map +1 -1
- package/dist/types/utils/data/isBytesEqual.d.ts +1 -1
- package/dist/types/utils/data/isBytesEqual.d.ts.map +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts +1 -1
- package/dist/types/utils/ens/encodeLabelhash.d.ts.map +1 -1
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts +1 -1
- package/dist/types/utils/ens/encodedLabelToLabelhash.d.ts.map +1 -1
- package/dist/types/utils/formatters/transactionRequest.d.ts +5 -0
- package/dist/types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +3 -1
- package/dist/types/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/actions/index.ts +15 -0
- package/src/actions/public/estimateFeesPerGas.ts +154 -0
- package/src/actions/public/estimateGas.ts +5 -5
- package/src/actions/public/estimateMaxPriorityFeePerGas.ts +98 -0
- package/src/actions/public/verifyHash.ts +1 -1
- package/src/actions/public/verifyMessage.ts +3 -2
- package/src/actions/public/verifyTypedData.ts +3 -2
- package/src/actions/public/watchContractEvent.ts +9 -6
- package/src/actions/wallet/deployContract.ts +2 -1
- package/src/actions/wallet/prepareTransactionRequest.ts +179 -0
- package/src/actions/wallet/sendRawTransaction.ts +48 -0
- package/src/actions/wallet/sendTransaction.ts +8 -7
- package/src/actions/wallet/signTransaction.ts +137 -0
- package/src/actions/wallet/writeContract.ts +2 -1
- package/src/chains/celo/formatters.ts +11 -12
- package/src/chains/celo/types.ts +86 -30
- package/src/chains/utils.ts +4 -4
- package/src/clients/createTestClient.ts +2 -1
- package/src/clients/decorators/public.ts +145 -0
- package/src/clients/decorators/wallet.ts +133 -0
- package/src/errors/fee.ts +27 -0
- package/src/errors/rpc.ts +1 -1
- package/src/errors/version.ts +1 -1
- package/src/index.ts +45 -25
- package/src/public.ts +10 -0
- package/src/types/chain.ts +80 -12
- package/src/types/eip1193.ts +13 -1
- package/src/types/fee.ts +2 -0
- package/src/utils/data/isBytesEqual.ts +4 -1
- package/src/utils/ens/encodeLabelhash.ts +1 -1
- package/src/utils/ens/encodedLabelToLabelhash.ts +2 -2
- package/src/utils/formatters/transactionRequest.ts +10 -0
- package/src/utils/index.ts +4 -1
- package/chains/dist/cjs/celo/formatters.js +0 -58
- package/chains/dist/cjs/celo/formatters.js.map +0 -1
- package/chains/dist/cjs/celo/parsers.js +0 -72
- package/chains/dist/cjs/celo/parsers.js.map +0 -1
- package/chains/dist/cjs/celo/serializers.js +0 -75
- package/chains/dist/cjs/celo/serializers.js.map +0 -1
- package/chains/dist/cjs/celo/types.js +0 -3
- package/chains/dist/cjs/celo/types.js.map +0 -1
- package/chains/dist/cjs/index.js +0 -135
- package/chains/dist/cjs/index.js.map +0 -1
- package/chains/dist/cjs/optimism/fees.js +0 -7
- package/chains/dist/cjs/optimism/fees.js.map +0 -1
- package/chains/dist/cjs/optimism/formatters.js +0 -52
- package/chains/dist/cjs/optimism/formatters.js.map +0 -1
- package/chains/dist/cjs/optimism/types.js +0 -3
- package/chains/dist/cjs/optimism/types.js.map +0 -1
- package/chains/dist/cjs/types.js +0 -3
- package/chains/dist/cjs/types.js.map +0 -1
- package/chains/dist/cjs/utils.js +0 -49
- package/chains/dist/cjs/utils.js.map +0 -1
- package/chains/dist/tsconfig.build.tsbuildinfo +0 -1
- package/chains/node_modules/.bin/tsc +0 -17
- package/chains/node_modules/.bin/tsserver +0 -17
- package/chains/tsconfig.tsbuildinfo +0 -1
- package/dist/cjs/utils/transaction/prepareRequest.js +0 -64
- package/dist/cjs/utils/transaction/prepareRequest.js.map +0 -1
- package/dist/esm/utils/transaction/prepareRequest.js +0 -64
- package/dist/esm/utils/transaction/prepareRequest.js.map +0 -1
- package/dist/types/utils/transaction/prepareRequest.d.ts +0 -20
- package/dist/types/utils/transaction/prepareRequest.d.ts.map +0 -1
- package/src/utils/transaction/prepareRequest.ts +0 -143
@@ -0,0 +1,137 @@
|
|
1
|
+
import type { Account } from '../../accounts/types.js'
|
2
|
+
import { parseAccount } from '../../accounts/utils/parseAccount.js'
|
3
|
+
import type { Client } from '../../clients/createClient.js'
|
4
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
5
|
+
import { AccountNotFoundError } from '../../errors/account.js'
|
6
|
+
import type { GetAccountParameter } from '../../types/account.js'
|
7
|
+
import type { Chain, GetChain } from '../../types/chain.js'
|
8
|
+
import { type RpcTransactionRequest } from '../../types/rpc.js'
|
9
|
+
import type {
|
10
|
+
TransactionRequest,
|
11
|
+
TransactionSerializable,
|
12
|
+
TransactionSerialized,
|
13
|
+
} from '../../types/transaction.js'
|
14
|
+
import type { UnionOmit } from '../../types/utils.js'
|
15
|
+
import { assertCurrentChain } from '../../utils/chain.js'
|
16
|
+
import {
|
17
|
+
type FormattedTransactionRequest,
|
18
|
+
formatTransactionRequest,
|
19
|
+
} from '../../utils/formatters/transactionRequest.js'
|
20
|
+
import { numberToHex } from '../../utils/index.js'
|
21
|
+
import { assertRequest } from '../../utils/transaction/assertRequest.js'
|
22
|
+
import { getChainId } from '../public/getChainId.js'
|
23
|
+
|
24
|
+
export type SignTransactionParameters<
|
25
|
+
TChain extends Chain | undefined = Chain | undefined,
|
26
|
+
TAccount extends Account | undefined = Account | undefined,
|
27
|
+
TChainOverride extends Chain | undefined = Chain | undefined,
|
28
|
+
> = UnionOmit<
|
29
|
+
FormattedTransactionRequest<
|
30
|
+
TChainOverride extends Chain ? TChainOverride : TChain
|
31
|
+
>,
|
32
|
+
'from'
|
33
|
+
> &
|
34
|
+
GetAccountParameter<TAccount> &
|
35
|
+
GetChain<TChain, TChainOverride>
|
36
|
+
|
37
|
+
export type SignTransactionReturnType = TransactionSerialized
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Signs a transaction.
|
41
|
+
*
|
42
|
+
* - Docs: https://viem.sh/docs/actions/wallet/signTransaction.html
|
43
|
+
* - JSON-RPC Methods:
|
44
|
+
* - JSON-RPC Accounts: [`eth_signTransaction`](https://ethereum.github.io/execution-apis/api-documentation/)
|
45
|
+
* - Local Accounts: Signs locally. No JSON-RPC request.
|
46
|
+
*
|
47
|
+
* @param args - {@link SignTransactionParameters}
|
48
|
+
* @returns The signed serialized tranasction. {@link SignTransactionReturnType}
|
49
|
+
*
|
50
|
+
* @example
|
51
|
+
* import { createWalletClient, custom } from 'viem'
|
52
|
+
* import { mainnet } from 'viem/chains'
|
53
|
+
* import { signTransaction } from 'viem/actions'
|
54
|
+
*
|
55
|
+
* const client = createWalletClient({
|
56
|
+
* chain: mainnet,
|
57
|
+
* transport: custom(window.ethereum),
|
58
|
+
* })
|
59
|
+
* const signature = await signTransaction(client, {
|
60
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
61
|
+
* to: '0x0000000000000000000000000000000000000000',
|
62
|
+
* value: 1n,
|
63
|
+
* })
|
64
|
+
*
|
65
|
+
* @example
|
66
|
+
* // Account Hoisting
|
67
|
+
* import { createWalletClient, http } from 'viem'
|
68
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
69
|
+
* import { mainnet } from 'viem/chains'
|
70
|
+
* import { signTransaction } from 'viem/actions'
|
71
|
+
*
|
72
|
+
* const client = createWalletClient({
|
73
|
+
* account: privateKeyToAccount('0x…'),
|
74
|
+
* chain: mainnet,
|
75
|
+
* transport: custom(window.ethereum),
|
76
|
+
* })
|
77
|
+
* const signature = await signTransaction(client, {
|
78
|
+
* to: '0x0000000000000000000000000000000000000000',
|
79
|
+
* value: 1n,
|
80
|
+
* })
|
81
|
+
*/
|
82
|
+
export async function signTransaction<
|
83
|
+
TChain extends Chain | undefined,
|
84
|
+
TAccount extends Account | undefined,
|
85
|
+
TChainOverride extends Chain | undefined,
|
86
|
+
>(
|
87
|
+
client: Client<Transport, TChain, TAccount>,
|
88
|
+
args: SignTransactionParameters<TChain, TAccount, TChainOverride>,
|
89
|
+
): Promise<SignTransactionReturnType> {
|
90
|
+
const {
|
91
|
+
account: account_ = client.account,
|
92
|
+
chain = client.chain,
|
93
|
+
...transaction
|
94
|
+
} = args
|
95
|
+
|
96
|
+
if (!account_)
|
97
|
+
throw new AccountNotFoundError({
|
98
|
+
docsPath: '/docs/actions/wallet/signTransaction',
|
99
|
+
})
|
100
|
+
const account = parseAccount(account_)
|
101
|
+
|
102
|
+
assertRequest({
|
103
|
+
account,
|
104
|
+
...args,
|
105
|
+
})
|
106
|
+
|
107
|
+
const chainId = await getChainId(client)
|
108
|
+
if (chain !== null)
|
109
|
+
assertCurrentChain({
|
110
|
+
currentChainId: chainId,
|
111
|
+
chain,
|
112
|
+
})
|
113
|
+
|
114
|
+
const formatters = chain?.formatters || client.chain?.formatters
|
115
|
+
const format =
|
116
|
+
formatters?.transactionRequest?.format || formatTransactionRequest
|
117
|
+
|
118
|
+
if (account.type === 'local')
|
119
|
+
return account.signTransaction(
|
120
|
+
{
|
121
|
+
chainId,
|
122
|
+
...transaction,
|
123
|
+
} as unknown as TransactionSerializable,
|
124
|
+
{ serializer: client.chain?.serializers?.transaction },
|
125
|
+
) as Promise<SignTransactionReturnType>
|
126
|
+
|
127
|
+
return await client.request({
|
128
|
+
method: 'eth_signTransaction',
|
129
|
+
params: [
|
130
|
+
{
|
131
|
+
...format(transaction as unknown as TransactionRequest),
|
132
|
+
chainId: numberToHex(chainId),
|
133
|
+
from: account.address,
|
134
|
+
} as unknown as RpcTransactionRequest,
|
135
|
+
],
|
136
|
+
})
|
137
|
+
}
|
@@ -4,7 +4,8 @@ import type { Account } from '../../accounts/types.js'
|
|
4
4
|
import type { Client } from '../../clients/createClient.js'
|
5
5
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
6
6
|
import type { GetAccountParameter } from '../../types/account.js'
|
7
|
-
import type { Chain
|
7
|
+
import type { Chain } from '../../types/chain.js'
|
8
|
+
import type { GetChain } from '../../types/chain.js'
|
8
9
|
import type { ContractFunctionConfig, GetValue } from '../../types/contract.js'
|
9
10
|
import type { Hex } from '../../types/misc.js'
|
10
11
|
import type { UnionOmit } from '../../types/utils.js'
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { type ChainFormatters } from '../../types/chain.js'
|
2
2
|
import type { Hash } from '../../types/misc.js'
|
3
|
+
import type { RpcTransaction } from '../../types/rpc.js'
|
3
4
|
import { hexToBigInt } from '../../utils/encoding/fromHex.js'
|
4
5
|
import { numberToHex } from '../../utils/encoding/toHex.js'
|
5
6
|
import { defineBlock } from '../../utils/formatters/block.js'
|
@@ -12,13 +13,11 @@ import { defineTransactionRequest } from '../../utils/formatters/transactionRequ
|
|
12
13
|
import type {
|
13
14
|
CeloBlockOverrides,
|
14
15
|
CeloRpcTransaction,
|
15
|
-
CeloRpcTransactionOverrides,
|
16
16
|
CeloRpcTransactionReceiptOverrides,
|
17
|
-
|
17
|
+
CeloRpcTransactionRequest,
|
18
18
|
CeloTransaction,
|
19
|
-
CeloTransactionOverrides,
|
20
19
|
CeloTransactionReceiptOverrides,
|
21
|
-
|
20
|
+
CeloTransactionRequest,
|
22
21
|
} from './types.js'
|
23
22
|
|
24
23
|
export const formattersCelo = {
|
@@ -34,7 +33,7 @@ export const formattersCelo = {
|
|
34
33
|
const transactions = args.transactions?.map((transaction) => {
|
35
34
|
if (typeof transaction === 'string') return transaction
|
36
35
|
return {
|
37
|
-
...formatTransaction(transaction),
|
36
|
+
...formatTransaction(transaction as RpcTransaction),
|
38
37
|
feeCurrency: transaction.feeCurrency,
|
39
38
|
gatewayFee: transaction.gatewayFee
|
40
39
|
? hexToBigInt(transaction.gatewayFee)
|
@@ -49,12 +48,12 @@ export const formattersCelo = {
|
|
49
48
|
},
|
50
49
|
}),
|
51
50
|
transaction: /*#__PURE__*/ defineTransaction({
|
52
|
-
format(args:
|
51
|
+
format(args: CeloRpcTransaction): CeloTransaction {
|
53
52
|
return {
|
54
53
|
feeCurrency: args.feeCurrency,
|
55
54
|
gatewayFee: args.gatewayFee ? hexToBigInt(args.gatewayFee) : null,
|
56
55
|
gatewayFeeRecipient: args.gatewayFeeRecipient,
|
57
|
-
}
|
56
|
+
} as CeloTransaction
|
58
57
|
},
|
59
58
|
}),
|
60
59
|
transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({
|
@@ -69,17 +68,17 @@ export const formattersCelo = {
|
|
69
68
|
},
|
70
69
|
}),
|
71
70
|
transactionRequest: /*#__PURE__*/ defineTransactionRequest({
|
72
|
-
format(
|
73
|
-
|
74
|
-
): CeloRpcTransactionRequestOverrides {
|
75
|
-
return {
|
71
|
+
format(args: CeloTransactionRequest): CeloRpcTransactionRequest {
|
72
|
+
const request = {
|
76
73
|
feeCurrency: args.feeCurrency,
|
77
74
|
gatewayFee:
|
78
75
|
typeof args.gatewayFee !== 'undefined'
|
79
76
|
? numberToHex(args.gatewayFee)
|
80
77
|
: undefined,
|
81
78
|
gatewayFeeRecipient: args.gatewayFeeRecipient,
|
82
|
-
}
|
79
|
+
} as CeloRpcTransactionRequest
|
80
|
+
if (args.type === 'cip42') request.type = '0x7c'
|
81
|
+
return request
|
83
82
|
},
|
84
83
|
}),
|
85
84
|
} as const satisfies ChainFormatters
|
package/src/chains/celo/types.ts
CHANGED
@@ -4,17 +4,21 @@ import type { Block, BlockTag } from '../../types/block.js'
|
|
4
4
|
import type { FeeValuesEIP1559 } from '../../types/fee.js'
|
5
5
|
import type { Hex } from '../../types/misc.js'
|
6
6
|
import type {
|
7
|
+
Index,
|
8
|
+
Quantity,
|
7
9
|
RpcBlock,
|
8
|
-
RpcTransaction,
|
10
|
+
RpcTransaction as RpcTransaction_,
|
9
11
|
RpcTransactionReceipt,
|
10
|
-
RpcTransactionRequest,
|
12
|
+
RpcTransactionRequest as RpcTransactionRequest_,
|
11
13
|
TransactionType,
|
12
14
|
} from '../../types/rpc.js'
|
13
15
|
import type {
|
14
16
|
AccessList,
|
15
|
-
Transaction,
|
17
|
+
Transaction as Transaction_,
|
18
|
+
TransactionBase,
|
16
19
|
TransactionReceipt,
|
17
|
-
TransactionRequest,
|
20
|
+
TransactionRequest as TransactionRequest_,
|
21
|
+
TransactionRequestBase,
|
18
22
|
TransactionSerializable,
|
19
23
|
TransactionSerializableBase,
|
20
24
|
TransactionSerialized,
|
@@ -68,13 +72,9 @@ export type CeloRpcBlock<
|
|
68
72
|
> &
|
69
73
|
CeloRpcBlockOverrides
|
70
74
|
|
71
|
-
export type CeloRpcTransactionOverrides = {
|
72
|
-
feeCurrency: Address | null
|
73
|
-
gatewayFee: Hex | null
|
74
|
-
gatewayFeeRecipient: Address | null
|
75
|
-
}
|
76
75
|
export type CeloRpcTransaction<TPending extends boolean = boolean> =
|
77
|
-
RpcTransaction<TPending>
|
76
|
+
| RpcTransaction<TPending>
|
77
|
+
| RpcTransactionCIP42<TPending>
|
78
78
|
|
79
79
|
export type CeloRpcTransactionReceiptOverrides = {
|
80
80
|
feeCurrency: Address | null
|
@@ -84,21 +84,13 @@ export type CeloRpcTransactionReceiptOverrides = {
|
|
84
84
|
export type CeloRpcTransactionReceipt = RpcTransactionReceipt &
|
85
85
|
CeloRpcTransactionReceiptOverrides
|
86
86
|
|
87
|
-
export type
|
88
|
-
|
89
|
-
|
90
|
-
gatewayFeeRecipient?: Address
|
91
|
-
}
|
92
|
-
export type CeloRpcTransactionRequest = RpcTransactionRequest &
|
93
|
-
CeloRpcTransactionRequestOverrides
|
87
|
+
export type CeloRpcTransactionRequest =
|
88
|
+
| RpcTransactionRequest
|
89
|
+
| RpcTransactionRequestCIP42
|
94
90
|
|
95
|
-
export type CeloTransactionOverrides = {
|
96
|
-
feeCurrency: Address | null
|
97
|
-
gatewayFee: bigint | null
|
98
|
-
gatewayFeeRecipient: Address | null
|
99
|
-
}
|
100
91
|
export type CeloTransaction<TPending extends boolean = boolean> =
|
101
|
-
Transaction<TPending>
|
92
|
+
| Transaction<TPending>
|
93
|
+
| TransactionCIP42<TPending>
|
102
94
|
|
103
95
|
export type CeloTransactionReceiptOverrides = {
|
104
96
|
feeCurrency: Address | null
|
@@ -108,13 +100,9 @@ export type CeloTransactionReceiptOverrides = {
|
|
108
100
|
export type CeloTransactionReceipt = TransactionReceipt &
|
109
101
|
CeloTransactionReceiptOverrides
|
110
102
|
|
111
|
-
export type
|
112
|
-
|
113
|
-
|
114
|
-
gatewayFeeRecipient?: Address
|
115
|
-
}
|
116
|
-
export type CeloTransactionRequest = TransactionRequest &
|
117
|
-
CeloTransactionRequestOverrides
|
103
|
+
export type CeloTransactionRequest =
|
104
|
+
| TransactionRequest
|
105
|
+
| TransactionRequestCIP42
|
118
106
|
|
119
107
|
export type CeloTransactionSerializable =
|
120
108
|
| TransactionSerializableCIP42
|
@@ -126,6 +114,74 @@ export type CeloTransactionSerialized<
|
|
126
114
|
|
127
115
|
export type CeloTransactionType = TransactionType | 'cip42'
|
128
116
|
|
117
|
+
type RpcTransaction<TPending extends boolean = boolean> =
|
118
|
+
RpcTransaction_<TPending> & {
|
119
|
+
feeCurrency: Address | null
|
120
|
+
gatewayFee: Hex | null
|
121
|
+
gatewayFeeRecipient: Address | null
|
122
|
+
}
|
123
|
+
|
124
|
+
type RpcTransactionRequest = RpcTransactionRequest_ & {
|
125
|
+
feeCurrency?: Address
|
126
|
+
gatewayFee?: Hex
|
127
|
+
gatewayFeeRecipient?: Address
|
128
|
+
}
|
129
|
+
|
130
|
+
export type RpcTransactionCIP42<TPending extends boolean = boolean> =
|
131
|
+
TransactionBase<Quantity, Index, TPending> &
|
132
|
+
FeeValuesEIP1559<Quantity> & {
|
133
|
+
feeCurrency: Address | null
|
134
|
+
gatewayFee: Hex | null
|
135
|
+
gatewayFeeRecipient: Address | null
|
136
|
+
type: '0x7c'
|
137
|
+
}
|
138
|
+
|
139
|
+
export type RpcTransactionRequestCIP42 = TransactionRequestBase<
|
140
|
+
Quantity,
|
141
|
+
Index
|
142
|
+
> &
|
143
|
+
Partial<FeeValuesEIP1559<Quantity>> & {
|
144
|
+
accessList?: AccessList
|
145
|
+
feeCurrency?: Address
|
146
|
+
gatewayFee?: Hex
|
147
|
+
gatewayFeeRecipient?: Address
|
148
|
+
type?: '0x7c'
|
149
|
+
}
|
150
|
+
|
151
|
+
type Transaction<TPending extends boolean = boolean> = Transaction_<
|
152
|
+
bigint,
|
153
|
+
number,
|
154
|
+
TPending
|
155
|
+
> & {
|
156
|
+
feeCurrency: Address | null
|
157
|
+
gatewayFee: bigint | null
|
158
|
+
gatewayFeeRecipient: Address | null
|
159
|
+
}
|
160
|
+
|
161
|
+
export type TransactionCIP42<TPending extends boolean = boolean> =
|
162
|
+
TransactionBase<bigint, number, TPending> &
|
163
|
+
FeeValuesEIP1559 & {
|
164
|
+
feeCurrency: Address | null
|
165
|
+
gatewayFee: bigint | null
|
166
|
+
gatewayFeeRecipient: Address | null
|
167
|
+
type: 'cip42'
|
168
|
+
}
|
169
|
+
|
170
|
+
type TransactionRequest = TransactionRequest_ & {
|
171
|
+
feeCurrency?: Address
|
172
|
+
gatewayFee?: bigint
|
173
|
+
gatewayFeeRecipient?: Address
|
174
|
+
}
|
175
|
+
|
176
|
+
export type TransactionRequestCIP42 = TransactionRequestBase &
|
177
|
+
Partial<FeeValuesEIP1559> & {
|
178
|
+
accessList?: AccessList
|
179
|
+
feeCurrency?: Address
|
180
|
+
gatewayFee?: bigint
|
181
|
+
gatewayFeeRecipient?: Address
|
182
|
+
type?: 'cip42'
|
183
|
+
}
|
184
|
+
|
129
185
|
export type TransactionSerializableCIP42<
|
130
186
|
TQuantity = bigint,
|
131
187
|
TIndex = number,
|
package/src/chains/utils.ts
CHANGED
@@ -10,20 +10,20 @@ export type {
|
|
10
10
|
CeloRpcBlock,
|
11
11
|
CeloRpcBlockOverrides,
|
12
12
|
CeloRpcTransaction,
|
13
|
-
CeloRpcTransactionOverrides,
|
14
13
|
CeloRpcTransactionReceipt,
|
15
14
|
CeloRpcTransactionReceiptOverrides,
|
16
15
|
CeloRpcTransactionRequest,
|
17
|
-
CeloRpcTransactionRequestOverrides,
|
18
16
|
CeloTransaction,
|
19
|
-
CeloTransactionOverrides,
|
20
17
|
CeloTransactionReceipt,
|
21
18
|
CeloTransactionReceiptOverrides,
|
22
19
|
CeloTransactionRequest,
|
23
|
-
CeloTransactionRequestOverrides,
|
24
20
|
CeloTransactionSerializable,
|
25
21
|
CeloTransactionSerialized,
|
26
22
|
CeloTransactionType,
|
23
|
+
RpcTransactionCIP42,
|
24
|
+
RpcTransactionRequestCIP42,
|
25
|
+
TransactionCIP42,
|
26
|
+
TransactionRequestCIP42,
|
27
27
|
TransactionSerializableCIP42,
|
28
28
|
TransactionSerializedCIP42,
|
29
29
|
} from './celo/types.js'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
2
|
+
|
1
3
|
import type { Account } from '../accounts/types.js'
|
2
4
|
import type { ParseAccount } from '../types/account.js'
|
3
5
|
import type { Chain } from '../types/chain.js'
|
@@ -6,7 +8,6 @@ import type { Prettify } from '../types/utils.js'
|
|
6
8
|
import { type Client, type ClientConfig, createClient } from './createClient.js'
|
7
9
|
import { type TestActions, testActions } from './decorators/test.js'
|
8
10
|
import type { Transport } from './transports/createTransport.js'
|
9
|
-
import type { Address } from 'abitype'
|
10
11
|
|
11
12
|
export type TestClientMode = 'anvil' | 'hardhat' | 'ganache'
|
12
13
|
|
@@ -53,11 +53,21 @@ import {
|
|
53
53
|
type EstimateContractGasReturnType,
|
54
54
|
estimateContractGas,
|
55
55
|
} from '../../actions/public/estimateContractGas.js'
|
56
|
+
import {
|
57
|
+
type EstimateFeesPerGasParameters,
|
58
|
+
type EstimateFeesPerGasReturnType,
|
59
|
+
estimateFeesPerGas,
|
60
|
+
} from '../../actions/public/estimateFeesPerGas.js'
|
56
61
|
import {
|
57
62
|
type EstimateGasParameters,
|
58
63
|
type EstimateGasReturnType,
|
59
64
|
estimateGas,
|
60
65
|
} from '../../actions/public/estimateGas.js'
|
66
|
+
import {
|
67
|
+
type EstimateMaxPriorityFeePerGasParameters,
|
68
|
+
type EstimateMaxPriorityFeePerGasReturnType,
|
69
|
+
estimateMaxPriorityFeePerGas,
|
70
|
+
} from '../../actions/public/estimateMaxPriorityFeePerGas.js'
|
61
71
|
import {
|
62
72
|
type GetBalanceParameters,
|
63
73
|
type GetBalanceReturnType,
|
@@ -196,6 +206,16 @@ import {
|
|
196
206
|
type WatchPendingTransactionsReturnType,
|
197
207
|
watchPendingTransactions,
|
198
208
|
} from '../../actions/public/watchPendingTransactions.js'
|
209
|
+
import {
|
210
|
+
type PrepareTransactionRequestParameters,
|
211
|
+
type PrepareTransactionRequestReturnType,
|
212
|
+
prepareTransactionRequest,
|
213
|
+
} from '../../actions/wallet/prepareTransactionRequest.js'
|
214
|
+
import {
|
215
|
+
type SendRawTransactionParameters,
|
216
|
+
type SendRawTransactionReturnType,
|
217
|
+
sendRawTransaction,
|
218
|
+
} from '../../actions/wallet/sendRawTransaction.js'
|
199
219
|
import type { Account } from '../../types/account.js'
|
200
220
|
import type { BlockNumber, BlockTag } from '../../types/block.js'
|
201
221
|
import type { Chain } from '../../types/chain.js'
|
@@ -204,6 +224,7 @@ import type {
|
|
204
224
|
MaybeAbiEventName,
|
205
225
|
MaybeExtractEventArgsFromAbi,
|
206
226
|
} from '../../types/contract.js'
|
227
|
+
import type { FeeValuesType } from '../../types/fee.js'
|
207
228
|
import type { FilterType } from '../../types/filter.js'
|
208
229
|
import type { Client } from '../createClient.js'
|
209
230
|
import type { Transport } from '../transports/createTransport.js'
|
@@ -764,6 +785,33 @@ export type PublicActions<
|
|
764
785
|
getFeeHistory: (
|
765
786
|
args: GetFeeHistoryParameters,
|
766
787
|
) => Promise<GetFeeHistoryReturnType>
|
788
|
+
/**
|
789
|
+
* Returns an estimate for the fees per gas for a transaction to be included
|
790
|
+
* in the next block.
|
791
|
+
*
|
792
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateFeesPerGas.html
|
793
|
+
*
|
794
|
+
* @param client - Client to use
|
795
|
+
* @param parameters - {@link EstimateFeesPerGasParameters}
|
796
|
+
* @returns An estimate (in wei) for the fees per gas. {@link EstimateFeesPerGasReturnType}
|
797
|
+
*
|
798
|
+
* @example
|
799
|
+
* import { createPublicClient, http } from 'viem'
|
800
|
+
* import { mainnet } from 'viem/chains'
|
801
|
+
*
|
802
|
+
* const client = createPublicClient({
|
803
|
+
* chain: mainnet,
|
804
|
+
* transport: http(),
|
805
|
+
* })
|
806
|
+
* const maxPriorityFeePerGas = await client.estimateFeesPerGas()
|
807
|
+
* // { maxFeePerGas: ..., maxPriorityFeePerGas: ... }
|
808
|
+
*/
|
809
|
+
estimateFeesPerGas: <
|
810
|
+
TChainOverride extends Chain | undefined,
|
811
|
+
TType extends FeeValuesType = 'eip1559',
|
812
|
+
>(
|
813
|
+
args?: EstimateFeesPerGasParameters<TChain, TChainOverride, TType>,
|
814
|
+
) => Promise<EstimateFeesPerGasReturnType>
|
767
815
|
/**
|
768
816
|
* Returns a list of logs or hashes based on a [Filter](/docs/glossary/terms#filter) since the last time it was called.
|
769
817
|
*
|
@@ -970,6 +1018,29 @@ export type PublicActions<
|
|
970
1018
|
) => Promise<
|
971
1019
|
GetLogsReturnType<TAbiEvent, TAbiEvents, TStrict, TFromBlock, TToBlock>
|
972
1020
|
>
|
1021
|
+
/**
|
1022
|
+
* Returns an estimate for the max priority fee per gas (in wei) for a transaction
|
1023
|
+
* to be included in the next block.
|
1024
|
+
*
|
1025
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateMaxPriorityFeePerGas.html
|
1026
|
+
*
|
1027
|
+
* @param client - Client to use
|
1028
|
+
* @returns An estimate (in wei) for the max priority fee per gas. {@link EstimateMaxPriorityFeePerGasReturnType}
|
1029
|
+
*
|
1030
|
+
* @example
|
1031
|
+
* import { createPublicClient, http } from 'viem'
|
1032
|
+
* import { mainnet } from 'viem/chains'
|
1033
|
+
*
|
1034
|
+
* const client = createPublicClient({
|
1035
|
+
* chain: mainnet,
|
1036
|
+
* transport: http(),
|
1037
|
+
* })
|
1038
|
+
* const maxPriorityFeePerGas = await client.estimateMaxPriorityFeePerGas()
|
1039
|
+
* // 10000000n
|
1040
|
+
*/
|
1041
|
+
estimateMaxPriorityFeePerGas: <TChainOverride extends Chain | undefined,>(
|
1042
|
+
args?: EstimateMaxPriorityFeePerGasParameters<TChain, TChainOverride>,
|
1043
|
+
) => Promise<EstimateMaxPriorityFeePerGasReturnType>
|
973
1044
|
/**
|
974
1045
|
* Returns the value from a storage slot at a given address.
|
975
1046
|
*
|
@@ -1138,6 +1209,47 @@ export type PublicActions<
|
|
1138
1209
|
>(
|
1139
1210
|
args: MulticallParameters<TContracts, TAllowFailure>,
|
1140
1211
|
) => Promise<MulticallReturnType<TContracts, TAllowFailure>>
|
1212
|
+
/**
|
1213
|
+
* Prepares a transaction request for signing.
|
1214
|
+
*
|
1215
|
+
* - Docs: https://viem.sh/docs/actions/wallet/prepareTransactionRequest.html
|
1216
|
+
*
|
1217
|
+
* @param args - {@link PrepareTransactionRequestParameters}
|
1218
|
+
* @returns The transaction request. {@link PrepareTransactionRequestReturnType}
|
1219
|
+
*
|
1220
|
+
* @example
|
1221
|
+
* import { createWalletClient, custom } from 'viem'
|
1222
|
+
* import { mainnet } from 'viem/chains'
|
1223
|
+
*
|
1224
|
+
* const client = createWalletClient({
|
1225
|
+
* chain: mainnet,
|
1226
|
+
* transport: custom(window.ethereum),
|
1227
|
+
* })
|
1228
|
+
* const request = await client.prepareTransactionRequest({
|
1229
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
1230
|
+
* to: '0x0000000000000000000000000000000000000000',
|
1231
|
+
* value: 1n,
|
1232
|
+
* })
|
1233
|
+
*
|
1234
|
+
* @example
|
1235
|
+
* // Account Hoisting
|
1236
|
+
* import { createWalletClient, http } from 'viem'
|
1237
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
1238
|
+
* import { mainnet } from 'viem/chains'
|
1239
|
+
*
|
1240
|
+
* const client = createWalletClient({
|
1241
|
+
* account: privateKeyToAccount('0x…'),
|
1242
|
+
* chain: mainnet,
|
1243
|
+
* transport: custom(window.ethereum),
|
1244
|
+
* })
|
1245
|
+
* const request = await client.prepareTransactionRequest({
|
1246
|
+
* to: '0x0000000000000000000000000000000000000000',
|
1247
|
+
* value: 1n,
|
1248
|
+
* })
|
1249
|
+
*/
|
1250
|
+
prepareTransactionRequest: <TChainOverride extends Chain | undefined,>(
|
1251
|
+
args: PrepareTransactionRequestParameters<TChain, TAccount, TChainOverride>,
|
1252
|
+
) => Promise<PrepareTransactionRequestReturnType>
|
1141
1253
|
/**
|
1142
1254
|
* Calls a read-only function on a contract, and returns the response.
|
1143
1255
|
*
|
@@ -1175,6 +1287,33 @@ export type PublicActions<
|
|
1175
1287
|
>(
|
1176
1288
|
args: ReadContractParameters<TAbi, TFunctionName>,
|
1177
1289
|
) => Promise<ReadContractReturnType<TAbi, TFunctionName>>
|
1290
|
+
/**
|
1291
|
+
* Sends a **signed** transaction to the network
|
1292
|
+
*
|
1293
|
+
* - Docs: https://viem.sh/docs/actions/wallet/sendRawTransaction.html
|
1294
|
+
* - JSON-RPC Method: [`eth_sendRawTransaction`](https://ethereum.github.io/execution-apis/api-documentation/)
|
1295
|
+
*
|
1296
|
+
* @param client - Client to use
|
1297
|
+
* @param parameters - {@link SendRawTransactionParameters}
|
1298
|
+
* @returns The transaction hash. {@link SendRawTransactionReturnType}
|
1299
|
+
*
|
1300
|
+
* @example
|
1301
|
+
* import { createWalletClient, custom } from 'viem'
|
1302
|
+
* import { mainnet } from 'viem/chains'
|
1303
|
+
* import { sendRawTransaction } from 'viem/wallet'
|
1304
|
+
*
|
1305
|
+
* const client = createWalletClient({
|
1306
|
+
* chain: mainnet,
|
1307
|
+
* transport: custom(window.ethereum),
|
1308
|
+
* })
|
1309
|
+
*
|
1310
|
+
* const hash = await client.sendRawTransaction({
|
1311
|
+
* serializedTransaction: '0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33'
|
1312
|
+
* })
|
1313
|
+
*/
|
1314
|
+
sendRawTransaction: (
|
1315
|
+
args: SendRawTransactionParameters,
|
1316
|
+
) => Promise<SendRawTransactionReturnType>
|
1178
1317
|
/**
|
1179
1318
|
* Simulates/validates a contract interaction. This is useful for retrieving **return data** and **revert reasons** of contract write functions.
|
1180
1319
|
*
|
@@ -1492,10 +1631,13 @@ export function publicActions<
|
|
1492
1631
|
getEnsResolver: (args) => getEnsResolver(client, args),
|
1493
1632
|
getEnsText: (args) => getEnsText(client, args),
|
1494
1633
|
getFeeHistory: (args) => getFeeHistory(client, args),
|
1634
|
+
estimateFeesPerGas: (args) => estimateFeesPerGas(client, args),
|
1495
1635
|
getFilterChanges: (args) => getFilterChanges(client, args),
|
1496
1636
|
getFilterLogs: (args) => getFilterLogs(client, args),
|
1497
1637
|
getGasPrice: () => getGasPrice(client),
|
1498
1638
|
getLogs: (args) => getLogs(client, args as any),
|
1639
|
+
estimateMaxPriorityFeePerGas: (args) =>
|
1640
|
+
estimateMaxPriorityFeePerGas(client, args),
|
1499
1641
|
getStorageAt: (args) => getStorageAt(client, args),
|
1500
1642
|
getTransaction: (args) => getTransaction(client, args),
|
1501
1643
|
getTransactionConfirmations: (args) =>
|
@@ -1503,7 +1645,10 @@ export function publicActions<
|
|
1503
1645
|
getTransactionCount: (args) => getTransactionCount(client, args),
|
1504
1646
|
getTransactionReceipt: (args) => getTransactionReceipt(client, args),
|
1505
1647
|
multicall: (args) => multicall(client, args as any) as any,
|
1648
|
+
prepareTransactionRequest: (args) =>
|
1649
|
+
prepareTransactionRequest(client as any, args as any),
|
1506
1650
|
readContract: (args) => readContract(client, args),
|
1651
|
+
sendRawTransaction: (args) => sendRawTransaction(client, args),
|
1507
1652
|
simulateContract: (args) => simulateContract(client, args),
|
1508
1653
|
verifyMessage: (args) => verifyMessage(client, args),
|
1509
1654
|
verifyTypedData: (args) => verifyTypedData(client, args),
|