import type { Account } from '../../../accounts/types.js' import { sendTransaction as sendTransaction_ } from '../../../actions/wallet/sendTransaction.js' import type { SendTransactionErrorType as SendTransactionErrorType_, SendTransactionParameters as SendTransactionParameters_, SendTransactionReturnType as SendTransactionReturnType_, } from '../../../actions/wallet/sendTransaction.js' import type { Client } from '../../../clients/createClient.js' import type { Transport } from '../../../clients/transports/createTransport.js' import { type ChainEIP712 } from '../types/chain.js' import { isEIP712Transaction } from '../utils/isEip712Transaction.js' import { sendEip712Transaction } from './sendEip712Transaction.js' export type SendTransactionParameters< TChain extends ChainEIP712 | undefined = ChainEIP712 | undefined, TAccount extends Account | undefined = Account | undefined, TChainOverride extends ChainEIP712 | undefined = ChainEIP712 | undefined, > = SendTransactionParameters_ export type SendTransactionReturnType = SendTransactionReturnType_ export type SendTransactionErrorType = SendTransactionErrorType_ /** * Creates, signs, and sends a new transaction to the network. * * - Docs: https://viem.sh/docs/zksync/actions/sendTransaction * - JSON-RPC Methods: * - JSON-RPC Accounts: [`eth_sendTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendtransaction) * - Local Accounts: [`eth_sendRawTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendrawtransaction) * * @param client - Client to use * @param parameters - {@link SendTransactionParameters} * @returns The [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash. {@link SendTransactionReturnType} * * @example * import { createWalletClient, custom } from 'viem' * import { zkSync } from 'viem/chains' * import { sendTransaction } from 'viem/zksync' * * const client = createWalletClient({ * chain: zkSync, * transport: custom(window.ethereum), * }) * const hash = await sendTransaction(client, { * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * value: 1000000000000000000n, * }) * * @example * // Account Hoisting * import { createWalletClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { zkSync } from 'viem/chains' * import { sendTransaction } from 'viem/zksync' * * const client = createWalletClient({ * account: privateKeyToAccount('0x…'), * chain: zkSync, * transport: http(), * }) * const hash = await sendTransaction(client, { * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * value: 1000000000000000000n, * }) */ export async function sendTransaction< TChain extends ChainEIP712 | undefined, TAccount extends Account | undefined, TChainOverride extends ChainEIP712 | undefined = undefined, >( client: Client, args: SendTransactionParameters, ): Promise { if (isEIP712Transaction(args)) return sendEip712Transaction(client, args) return sendTransaction_(client, args) }