import { createWalletClient, Hex, http, WalletClient, type Account, type HttpTransport, } from "viem" import { privateKeyToAccount } from "viem/accounts" import { TransactionSender, TransactionSenderResponse, type TransactionSenderRequest, } from "./TransactionSender" import { getChainById } from "./chains" export default class LocalTransactionSender implements TransactionSender { readonly #walletClient: WalletClient constructor(relayerPrivateKey: Hex) { const transport = http("http://localhost:8545") const account = privateKeyToAccount(relayerPrivateKey) this.#walletClient = createWalletClient({ account, transport, }) } async sendTransaction( tx: TransactionSenderRequest, ): Promise { const hash = await this.#walletClient.sendTransaction({ to: tx.to, data: tx.data, chain: getChainById(tx.chainId), }) return { hash } } }