import { useSwapModal } from '@0xsequence/checkout'
import { encodeFunctionData, parseAbi } from 'viem'
function App() {
const { openSwapModal } = useSwapModal()
const handleSwap = () => {
// Target token information
const chainId = 137 // Polygon
const toTokenAddress = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359' // USDC on Polygon
const toTokenAmount = '20000' // 0.02 USDC (in smallest units)
// Optional: Transaction to execute after swap is completed
const data = encodeFunctionData({
abi: parseAbi(['function demo()']),
functionName: 'demo',
args: []
})
// Open the swap modal
openSwapModal({
onSuccess: () => {
console.log('swap successful!')
},
chainId,
toTokenAddress,
toTokenAmount,
postSwapTransactions: [
{
to: '0x37470dac8a0255141745906c972e414b1409b470',
data
}
],
title: 'Swap and Pay',
description: 'Select a token in your wallet to swap to 0.2 USDC.'
})
}
return (
<button onClick={handleSwap}>
Swap with Sequence Pay
</button>
)
}