前置条件
- 已安装 Keplr 的浏览器环境(推荐使用
create-next-app) - Node.js 和 npm
初始化客户端
要开始集成 Skip Go API,请先使用
setClientOptions 或 setApiOptions 对该库进行一次性配置。完成配置后,你可以直接导入并调用 route 和 executeRoute 等函数。获取路由
现在,我们可以使用
route 函数请求报价和路由,将 Noble 上的 USDC 交换为 Celestia 上的 TIA。理解路由响应路由响应包含与交换流程相关的重要信息:
amountOut:用户在交换后预计收到的数量,已扣除所有费用和价格影响requiredChainAddresses:生成交易时需要提供用户地址的链 IDoperations:从源代币移动到目标代币所涉及的步骤
获取所需地址
生成路由后,你需要为所需链提供用户地址。
routeResult.requiredChainAddresses 数组列出了需要地址的链 ID。我们建议存储用户地址,并创建一个类似 getAddress 的函数,根据链 ID 获取对应地址(示例见这里)。For a more in-depth guide, check out our detailed walkthrough, which covers both Solana and EVM transactions. You can also explore more about EVM Transactions or dive into the specifics of SVM Transactions.
Prerequisites
- Browser environment setup with Keplr installed (
create-next-appis recommended) - Node.js and npm
Initialize Client
To start integrating with the Skip Go API, configure the library once using
setClientOptions or setApiOptions. After configuration, you import and call functions like route and executeRoute directly.Get a Route
Now, we can use the
route function to request a quote and route to swap USDC on Noble to TIA on Celestia.Understanding the Route ResponseThe route response contains important information about the swap process:
amountOut: The estimated amount the user will receive after the swap, net of all fees and price impactrequiredChainAddresses: Chain IDs where you need to provide user addresses when generating the transactionoperations: Steps involved in moving from the source to the destination token
Get Required Addresses
After generating a route, you need to provide user addresses for the required chains. The
routeResult.requiredChainAddresses array lists the chain IDs for which addresses are needed.We recommend storing the user’s addresses and creating a function like getAddress that retrieves the address based on the chain ID (see an example here).Execute the Route
Once you have a route, you can execute it in a single function call by passing in the route, the user addresses for at least the chains the route includes, and optional callback functions. This also registers the transaction for tracking.Once the transaction is complete, you’ll have new TIA in your Celestia address!