初始化库
要开始集成 Skip Go API,你不再需要初始化一个
SkipClient 实例。相反,你只需配置一次库,然后直接导入并使用各个独立函数。初始化选项
可以使用setClientOptions 或 setApiOptions 来初始化该库。这两个函数都接受 apiUrl 和 apiKey。setClientOptions(options): 如果你计划使用executeRoute,请使用这个函数。它会配置你的 API 凭据,并允许你提供链级别的设置,例如 endpoints、Amino types 和 registry types。setApiOptions(options): 如果你主要需要配置 API 交互(apiUrl、apiKey)或设置 affiliate fees(chainIdsToAffiliates),请使用这个函数。该选项不会配置endpointOptions、aminoTypes或registryTypes。
Import and Initialize
配置参数
以下是常见的配置参数。完整细节请参考setClientOptions 或 setApiOptions 对应的 options 类型定义。apiUrl?: string:覆盖默认 API URL。可以传给setClientOptions或setApiOptions,如果没有调用这两个初始化函数,也可以直接传给各个 API 函数。apiKey?: string:你的 Skip API key。可以传给setClientOptions或setApiOptions,如果没有调用这两个初始化函数,也可以直接传给各个 API 函数。某些功能需要提供该参数。endpointOptions?: EndpointOptions:为特定链提供 RPC 和 REST endpoints(由setClientOptions使用)。aminoTypes?: AminoConverters:用于消息编码的额外 amino types(由setClientOptions使用)。registryTypes?: Iterable<[string, GeneratedType]>:额外的 registry types(由setClientOptions使用)。cacheDurationMs?: number:为chains和assets等函数的响应设置缓存时长,单位为毫秒(由setClientOptions使用)。
设置签名器
查询基础信息
获取路由
获取所需地址
生成路由后,你需要为所需链提供用户地址。
route.requiredChainAddresses 数组列出了需要地址的链 ID。我们建议存储用户地址,并创建一个类似 getAddress 的函数,根据链 ID 获取地址。执行路由
拿到路由后,你可以通过一次函数调用执行它:传入路由、至少覆盖该路由所包含链的用户地址,以及可选的回调函数。这也会注册该交易以便跟踪。对于由多笔交易组成的路由,
executeRoute 会监控每一笔交易,直到其完成,然后为下一步生成交易,并提示用户使用相应的 signer 进行签名。或者,你也可以使用各个单独的函数手动处理消息生成、签名和提交:
messages:生成交易消息。messagesDirect:一个便捷函数,将/route和/msgs的功能合并为一次调用。它会返回执行多链兑换或转账所需的最少消息数。broadcastTx:将交易广播到网络。submitTransaction:提交并跟踪交易。 关于这些更底层函数的详细信息,请参考 API 文档。
交易跟踪
交易注册为可跟踪后(通过
executeRoute、submitTransaction 或 trackTransaction),你可以轮询其状态:- 检查状态:
transactionStatus- 接收txHash和chainId,并返回当前的跨链状态。
executeRoute(步骤 7),它会自动处理交易生命周期,包括等待完成。手动跟踪函数(submitTransaction、trackTransaction、transactionStatus)主要适用于你不使用 executeRoute 进行完整执行的场景(例如直接使用 submitTransaction),或者你需要对跟踪和状态轮询过程进行更细粒度控制的情况。有问题或反馈?帮助我们做得更好!加入我们的 Discord,并选择 “Skip Go Developer” 角色来分享你的问题和反馈。
Install Library
Install the library using npm or yarn:
If you’re using
yarn (or another package manager that doesn’t install peer dependencies by default)
you may need to install these peer dependencies as well:Initialize Library
To start integrating with the Skip Go API, you no longer initialize a
SkipClient instance. Instead, you configure the library once and then import and use individual functions directly.Initialization Options
The library can be initialized usingsetClientOptions or setApiOptions. Both functions accept apiUrl and apiKey.setClientOptions(options): Use this if you plan to useexecuteRoute. It configures your API credentials and lets you provide chain-specific settings like endpoints, Amino types, and registry types.setApiOptions(options): Use this if you primarily need to configure API interaction (apiUrl,apiKey) or set up affiliate fees (chainIdsToAffiliates). This option does not configureendpointOptions,aminoTypes, orregistryTypes.
Import and Initialize
Configuration Parameters
Below are the common configuration parameters. Refer to the specificoptions type for setClientOptions or setApiOptions for full details.apiUrl?: string: Override the default API URL. Can be passed tosetClientOptionsorsetApiOptions, or directly to individual API functions if neither initialization function is called.apiKey?: string: Your Skip API key. Can be passed tosetClientOptionsorsetApiOptions, or directly to individual API functions if neither initialization function is called. Required for certain features.endpointOptions?: EndpointOptions: Provide RPC and REST endpoints for specific chains (used bysetClientOptions).aminoTypes?: AminoConverters: Additional amino types for message encoding (used bysetClientOptions).registryTypes?: Iterable<[string, GeneratedType]>: Additional registry types (used bysetClientOptions).cacheDurationMs?: number: Duration in milliseconds to cache responses for functions likechainsandassets(used bysetClientOptions).
Setup Signers
To execute transactions, you need to set up signers for the ecosystems you plan to interact with. Below are examples for Cosmos SDK, EVM, and Solana (SVM). Note that for EVM and SVM, you’ll need to install additional libraries.
Signer Setup
Query Basic Info
With the library initialized, you can query balances, supported chains and assets using the imported functions.
Query Examples
Get a Route
Once you’ve selected your source and destination chains and tokens, you can generate a route and get a quote using the
route function. See it in context here.Route Examples
Read more about affiliate fees, Smart Relay and EVM Swaps.
Get Required Addresses
After generating a route, you need to provide user addresses for the required chains. The
route.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.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.For routes that consist of multiple transactions,
executeRoute will monitor each transaction until it completes, then generate the transaction for the next step and prompt the user to sign it using the appropriate signer.Alternatively, you can handle message generation, signing, and submission manually using the individual functions:
messages: Generate transaction messages.messagesDirect: A convenience function that combines the functionality of/routeand/msgsinto a single call. It returns the minimal number of messages required to execute a multi-chain swap or transfer.broadcastTx: Broadcast transactions to the network.submitTransaction: Submit and track transactions. Refer to the API documentation for details on these lower-level functions.
Transaction Tracking
After a transaction is registered for tracking (either via
executeRoute, submitTransaction, or trackTransaction), you can poll for its status:- Check Status:
transactionStatus- Takes atxHashandchainIdand returns the current cross-chain status.
executeRoute (Step 7), it automatically handles the transaction lifecycle, including waiting for completion. The manual tracking functions (submitTransaction, trackTransaction, transactionStatus) are primarily for scenarios where you are not using executeRoute for full execution (e.g., if you use submitTransaction directly) or if you need more granular control over the tracking and status polling process.Have questions or feedback? Help us get better!Join our Discord and select the “Skip Go Developer” role to share your questions and feedback.