Returns
UseSwapReturnType
UseSwapReturnType
function useSwap(): UseSwapReturnType;
UseSwapReturnType
UseSwapReturnType
import { useSwap } from "@coinbase/cdp-hooks";
function SwapComponent() {
const { swap, data, status, error } = useSwap();
const handleSwap = () => {
swap({
network: "base",
fromToken: "0x4200000000000000000000000000000000000006",
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
fromAmount: "100000000000000000",
slippageBps: 100,
});
};
return (
<div>
<button onClick={handleSwap} disabled={status === "pending"}>
{status === "pending" ? "Swapping..." : "Swap"}
</button>
{status === "success" && data && <p>Swap confirmed!</p>}
{error && <p>Error: {error.message}</p>}
</div>
);
}
Was this page helpful?