### Example AI Assistant Prompts Source: https://docs.openocean.finance/docs/mcp-server/examples Sample prompts for performing common tasks like getting swap quotes, checking token lists, or building transactions. ```text # Get a swap quote "Get me a quote for swapping 1 ETH to USDC on Ethereum" # Check token list "What tokens are available on BSC?" # Get gas price "What's the current gas price on Polygon?" # Build a swap transaction "Build a swap transaction for 100 USDC to ETH on Arbitrum for address 0x..." # Check DEXes "What DEXes are supported on Avalanche?" ``` -------------------------------- ### Complete React Application Setup with OpenOcean Widget Source: https://docs.openocean.finance/docs/widget/complete-example This snippet shows the full `main.tsx` file for a React application. It includes setting up Wagmi for wallet management, configuring RainbowKit, and initializing the OpenOceanWidget with custom styling and wallet connection logic. Ensure all necessary dependencies like react-dom, @openocean.finance/widget, and @rainbow-me/rainbowkit are installed. ```typescript import { createRoot } from 'react-dom/client' import { OpenOceanWidget } from "@openocean.finance/widget"; import { useConnectModal, RainbowKitProvider } from '@rainbow-me/rainbowkit' import { http, createConfig, useAccount, WagmiProvider, useDisconnect } from 'wagmi' import { mainnet } from 'wagmi/chains' import { injected } from 'wagmi/connectors' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import '@rainbow-me/rainbowkit/styles.css' // Wagmi Configuration export const config = createConfig({ chains: [mainnet], connectors: [ injected({ shimDisconnect: true, }), ], transports: { [mainnet.id]: http(), }, }) const queryClient = new QueryClient() function App() { const { openConnectModal } = useConnectModal() const { isConnected } = useAccount() const { disconnect } = useDisconnect() const handleDisconnectWallet = () => { try { console.log("Attempting to disconnect wallet") disconnect() console.log("Wallet disconnected") } catch (error) { console.error("Disconnect failed:", error) } } const widgetConfig = { variant: "compact" as const, appearance: "dark" as const, subvariant: "split" as const, theme: { palette: { primary: { main: "#fb534f" }, secondary: { main: "#FFC800" }, background: { default: "#222037", paper: "#29273D" }, text: { primary: "#ffffff", secondary: "#8C7F8C" }, grey: { 200: "#EEEFF2", 300: "#D5DAE1", 700: "#555B62", 800: "#373F48" } }, shape: { borderRadius: 12, borderRadiusSecondary: 12, borderRadiusTertiary: 24 }, typography: { fontFamily: "Inter, sans-serif" }, container: { boxShadow: "0px 8px 32px rgba(0, 0, 0, 0.08)", borderRadius: "16px" }, components: { MuiCard: { defaultProps: { variant: "filled" } }, MuiTabs: { styleOverrides: { root: { backgroundColor: "#29273D", ".MuiTabs-indicator": { backgroundColor: "#17122b" } } } } } }, walletConfig: { onConnect: ()=> { openConnectModal?.() } } } return (
{!isConnected && } {isConnected && ( )}
) } const root = createRoot(document.getElementById('root')!) root.render( ) ``` -------------------------------- ### Get Swap Quote Examples Source: https://docs.openocean.finance/docs/ai-agents/skills Use the `/quote` command to get the best swap route and price for a token pair. This command only requires GET requests and no local installation. ```bash /quote 1 ETH to USDC on ethereum ``` ```bash /quote 100 USDC to WBTC on arbitrum ``` ```bash /quote 0.5 WBTC to DAI on polygon ``` -------------------------------- ### Install Dependencies Source: https://docs.openocean.finance/docs/widget/complete-example Command to install the necessary project dependencies. ```bash npm install ``` -------------------------------- ### Install Reown Dependencies Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the necessary packages for Reown (WalletConnect) integration. ```bash npm install @openocean.finance/widget @reown/appkit @reown/appkit-adapter-wagmi npm install wagmi viem @tanstack/react-query ``` -------------------------------- ### Example HTTP GET Request for Quote Source: https://docs.openocean.finance/docs/sdk/quote This is an example of how to directly call the Open API to quote a token exchange amount. Replace placeholder addresses and values with your specific requirements. ```http https://open-api.openocean.finance/v3/bsc/quote?inTokenAddress=0x55d398326f99059ff775485246999027b3197955&outTokenAddress=0xe9e7cea3dedca5984780bafc599bd69add087d56&amount=10&gasPrice=5 ``` -------------------------------- ### Remix Installation Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the OpenOcean widget and React Query for integration into a Remix project. ```shell npm install @openocean.finance/widget @tanstack/react-query ``` -------------------------------- ### Install ConnectKit Dependencies Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the necessary packages for OpenOcean widget and ConnectKit wallet integration. ```sh npm install @openocean.finance/widget @openocean.finance/wallet-management npm install connectkit wagmi viem @tanstack/react-query ``` -------------------------------- ### Start Development Server Source: https://docs.openocean.finance/docs/widget/complete-example Command to launch the local development server. ```bash npm run dev ``` -------------------------------- ### Example OpenOcean Widget Configuration Source: https://docs.openocean.finance/docs/widget/variants This example demonstrates a full widget configuration, including the 'compact' variant and 'bridge' subvariant, along with custom appearance and theme settings. It shows how to integrate the widget into your application using the OpenOceanWidget component. ```javascript const widgetConfig = { variant: "compact", subvariant: "bridge", // Enable cross-chain functionality appearance: "dark", theme: { container: { border: '1px solid rgb(234, 234, 234)', borderRadius: '16px', }, }, } ``` -------------------------------- ### Install SDK with yarn Source: https://docs.openocean.finance/docs/sdk/install Use this command to install the OpenOcean Aggregator SDK via yarn. ```bash yarn add @openocean.finance/openocean-sdk ``` -------------------------------- ### Install Privy Dependencies Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the required packages for Privy authentication and React Query. ```bash npm install @openocean.finance/widget @privy-io/react-auth npm install @tanstack/react-query ``` -------------------------------- ### Install Dynamic Dependencies Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the required packages for Dynamic Labs integration. ```bash npm install @openocean.finance/widget @dynamic-labs/sdk-react-core npm install @tanstack/react-query ``` -------------------------------- ### Install SDK with npm Source: https://docs.openocean.finance/docs/sdk/install Use this command to install the OpenOcean Aggregator SDK via npm. ```bash npm i @openocean.finance/openocean-sdk ``` -------------------------------- ### Install Additional Dependencies Source: https://docs.openocean.finance/docs/sdk/install Install web3 and bignumber.js if you plan to build wallet and contract objects yourself. These are required for manual object construction. ```bash npm install bignumber.js ``` ```bash npm install web3 ``` -------------------------------- ### Install RainbowKit Dependencies Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the necessary packages for OpenOcean widget and RainbowKit wallet integration. ```sh npm install @openocean.finance/widget @rainbow-me/rainbowkit wagmi viem npm install @tanstack/react-query ``` -------------------------------- ### Install Next.js Dependencies Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the widget SDK and MUI packages for Next.js projects. ```bash npm install @openocean.finance/widget @openocean.finance/widget-sdk npm install @mui/material-nextjs ``` -------------------------------- ### Install Widget for Deposit Flow Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Installs the OpenOcean widget package for the deposit flow implementation. ```sh npm install @openocean.finance/widget ``` -------------------------------- ### Install Dependencies for OpenOcean Widget Integration Source: https://docs.openocean.finance/docs/widget/complete-example Installs the necessary packages for integrating the OpenOcean Widget with Wagmi and RainbowKit. Ensure you have Node.js and npm/yarn/pnpm installed. ```bash npm install @openocean.finance/widget wagmi @tanstack/react-query @rainbow-me/rainbowkit react react-dom ``` -------------------------------- ### Svelte Installation Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the OpenOcean widget and necessary Vite plugins for Svelte integration. ```shell npm install @openocean.finance/widget npm install --save-dev @vitejs/plugin-react @vitejs/plugin-svelte ``` -------------------------------- ### Install Vite + React Dependencies Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Install the necessary widget, wallet management, and build-time polyfill packages for a Vite project. ```bash npm install @openocean.finance/widget @openocean.finance/wallet-management npm install @tanstack/react-query wagmi viem npm install --save-dev vite-plugin-node-polyfills ``` -------------------------------- ### Install Widget Dependencies Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Installs the required OpenOcean widget, Zustand, and Material UI packages. ```sh npm install @openocean.finance/widget zustand npm install @mui/material ``` -------------------------------- ### Get Ticket List Response Example Source: https://docs.openocean.finance/docs/ticket-api/api This JSON object demonstrates the response when retrieving a list of tickets associated with a referrer address. It includes details for each ticket, such as hash, question, process status, and creation time. ```json { "code": 200, "data": [ { "hash": "0xcaf525986a879ca5017ca9b934a402aa55232c5e983b245937d39a3583c2c49a", "remark": null, "process": "01", "question": "question", "answer": null, "params": { "quote": { "chain": "bsc", "inTokenAddress": "0x55d398326f99059ff775485246999027b3197955", "outTokenAddress": "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d", "amount": 5, "gasPrice": 1, "slippage": 1, "account": "0x2FF855378Cd29f120CDF9d675E959cb5422ec5f2", "referrer": "0xD4eb4cbB1ECbf96a1F0C67D958Ff6fBbB7B037BB", "referrerFee": "", "enabledDexIds": "", "disabledDexIds": "", "sender": "" } }, "account": "0x72f16Cae8F50Ad615AB5A8e231A496b2ace52532", "createAt": "2025-04-07T08:04:46.000Z" } ] } ``` -------------------------------- ### OpenOcean SDK Vue.js Integration Example Source: https://docs.openocean.finance/docs/sdk/examples This example demonstrates the full lifecycle of an OpenOcean integration, including wallet connection, token list retrieval, quoting, and swap execution. ```vue ``` -------------------------------- ### Connect Wallet via SDK Source: https://docs.openocean.finance/docs/swap-api/sdk Connects to a wallet using the swap SDK configuration. ```javascript async connectWallet () { try { let AllChainNames = config.chains.chainNames let AllWalletNames = config.wallets.walletList.map(item => item.key) // ["MetaMask","CryptoCom","TrustWallet",...] // ["eth","ropsten","rinkeby","bsc","solana","flow","polygon","avax",...] let data = await swapSdk.connectWallet({ chainName: this.chainName, walletName: this.walletName }) if (data) { this.myWallet = data.wallet // this.chain = data.chain // this.getBalance() } } catch (error) { this.myWallet = null this.chain = null } } ``` -------------------------------- ### Initialize OpenOcean SDK in Project Source: https://docs.openocean.finance/docs/swap-api/sdk Import and initialize the OpenOceanSdk in your JavaScript project. This sets up the SDK for use, providing access to its API and swap functionalities. ```javascript import { OpenoceanSdk } from '@openocean.finance/openocean-sdk' const openoceanSdk = new OpenoceanSdk() const { api, swapSdk, config } = openoceanSdk ``` -------------------------------- ### Project Directory Layout Source: https://docs.openocean.finance/docs/skills/structure Illustrates the hierarchical structure of the OpenOcean Skills project, including the placement of skill definitions, shared references, and test files. ```bash openocean-skills/ ├── skills/ │ ├── quote/# Get a swap quote │ │ └── SKILL.md │ ├── swap-build/# Build swap calldata (with confirmation) │ │ └── SKILL.md │ ├── swap-execute/# Execute a swap via Foundry cast (with confirmation) │ │ └── SKILL.md │ ├── swap-execute-fast/# Build and execute in one step (no confirmation) │ │ ├── SKILL.md │ │ └── scripts/ │ │ ├── fast-swap.sh# Token resolution and route building │ │ └── execute-swap.sh# Calls fast-swap.sh and then broadcasts │ └── error-handling/# Troubleshooting and error codes │ └── SKILL.md ├── references/# Shared docs │ ├── api-reference.md │ └── token-registry.md ├── test/# Prompt test cases │ └── agent-test-cases.md# English test prompts └── README.md ``` -------------------------------- ### Get Transaction Body via Swap Quote API Source: https://docs.openocean.finance/docs/overview/transaction-example Retrieves transaction calldata for a swap by sending a GET request to the OpenOcean API with specified token and chain parameters. ```javascript async function swap() { const params = { chain: 'bsc', inTokenAddress: '0x55d398326f99059ff775485246999027b3197955', outTokenAddress: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', slippage: 1, amount: 1, gasPrice: 1, account: '0xB3cbe...' }; const { data } = await axios({ url: `https://open-api.openocean.finance/v4/bsc/swap`, method: 'GET', params }); return data; } ``` -------------------------------- ### Connect Wallet via MetaMask Class Source: https://docs.openocean.finance/docs/swap-api/sdk Directly instantiates and connects to a MetaMask wallet. ```javascript import { MetaMask } from "@openocean.finance/wallet"; const connectWallet = async (params) => { const myWallet = new MetaMask() const result = await myWallet.requestConnect(params.chainId); // you can use the requestConnect function to trigger your wallet } ``` -------------------------------- ### Configure QueryClient Source: https://docs.openocean.finance/docs/widget/v2/integration-examples Initialize the React Query client for state management. ```ts import { QueryClient } from '@tanstack/react-query' export const queryClient = new QueryClient() ``` -------------------------------- ### Get Token List Source: https://docs.openocean.finance/docs/swap-api/v4 Retrieve a list of supported tokens for a specific chain. Use this endpoint to get token details like ID, code, name, address, decimals, symbol, and icon. ```HTTP https://open-api.openocean.finance/v4/bsc/tokenList ```