'use client'
import { BASE_NETWORK, ETH_NETWORK, withdraw } from 'privacycash-evm'
import { useAccount, useChainId } from 'wagmi'
export function WithdrawButton() {
const { address } = useAccount()
const chainId = useChainId()
const handleWithdraw = async () => {
if (!address) return
const network = chainId === 1 ? ETH_NETWORK : chainId === 8453 ? BASE_NETWORK : undefined
if (!network) {
alert('Switch to Base or Ethereum mainnet.')
return
}
const signature = localStorage.getItem(`evm_sign_${address}`)
if (!signature) {
alert('Please sign in first.')
return
}
const recipient = '0xRECIPIENT_ADDRESS'
const txHash = await withdraw({
withdrawAmountInput: 0.05, // Total including fees
recipient,
keyBasePath: '/circuit',
signature,
address,
token: 'eth',
network,
})
console.log('Withdraw tx:', txHash)
}
return <button onClick={handleWithdraw}>Withdraw 0.05 ETH</button>
}