简介
- 当用户需要从 SVM 链(例如 Solana)发起转账或兑换时,Skip Go API 会返回一个
SvmTx类型,供开发者传递给用户进行签名。 - 本文面向尚不熟悉 SVM 中交易构造概念、但需要使用
SvmTx帮助用户在 Solana 与其他 SVM 链之间转入或转出的 CosmosSDK 和 EVM 开发者。 - 由于在网络高度拥堵时,将 Solana 交易上链本身较为困难,我们强烈建议使用
/submit端点,以避免处理复杂的重试逻辑和/或为提升提交可靠性而接入多个 RPC 提供方。Skip Go API 的/submit端点已经为你实现了 Solana 交易提交的最佳实践。
与 Solana 钱包交互
我们建议使用 @solana/wallet-adapter 与 Solana 钱包交互并构建交易。它提供了一个标准化的Adapter 对象,对所有主流 Solana 钱包(例如 Phantom、Backpack 等)进行了封装,同时也提供了用于钱包选择的可视化 React 组件。支持的钱包列表可查看这里。
配置 SkipClient 以使用 Solana 钱包
你只需要在 SkipClient.options 中初始化 getSVMSigner 方法,从用户当前连接的钱包中提取 @solana/wallet-adapter-base:
TypeScript
SkipClient 的 route、executeRoute 以及其他方法。
本文其余部分将介绍底层数据结构的细节,以便你在需要时进一步理解。
理解 SvmTx 数据结构
SvmTx 有 2 个开发者需要理解的字段:
chain_id:该交易应提交到的链 ID。tx:这是交易的 base64 编码字节内容,你应当让最终用户对其进行签名。
关于 SvmTx.tx 的说明
这是一个已经完整构造好的交易。你不需要对它做任何修改,也不需要额外添加内容来准备签名。你只需要对其签名,并让用户在大约 1 分钟内将其提交上链(否则 nonce 会过期)。
更具体地说,该交易已经包含:
- 用户的 nonce(在 Solana 中,默认情况下这实际上是一个 recent blockhash)
- 指令(相当于 Solana 中的消息)
- 基础交易费(默认设置为每个签名 500 lamports)
- 优先费(下文会进一步说明我们的设置方式)
对 tx 进行签名
Skip Go Client 会处理 SvmTx.tx 中返回交易的全部签名复杂性。
你只需要在 SkipClient 构造函数中的 SkipClientOptions 对象里设置好 getSVMSigner 方法,然后使用 executeRoute 或 executeTxs。
优先费是如何设置的
Solana 的“优先费”会影响交易被打包进区块的可能性。与许多其他主流区块链网络不同,Solana 的优先费是在“局部”范围内评估的。换句话说,费用高低是相对于访问同一批状态的其他交易来比较的(例如同一个 DEX 池、同一个代币合约等):- 如果相对于其他访问相同状态的交易来说费用较低,那么该交易很可能不会被打包。
- 如果相对于这些访问相似状态的其他交易来说费用较高,那么它就更有可能被打包。
有问题或反馈?欢迎帮助我们做得更好!加入我们的 Discord,并选择 “Skip Go Developer” 角色来分享你的问题和反馈。
Intro
- When a user needs to transfer or swap from an SVM chain (e.g. Solana), the Skip Go API will return an
SvmTxtype for the developer to pass to the user for signing - This doc is intended for CosmosSDK and EVM developers who aren’t already familiar with the concepts of transaction construction in the SVM and need to use
SvmTxto help their users move from/to Solana and other SVM chains. - Due to the difficult nature of including Solana transactions on chain during times of high network congestion, we HIGHLY recommend using the
/submitendpoint to avoid dealing with complex retry logic and/or multiple RPC providers for submission reliability. Skip Go API’s/submitendpoint implements best practices for Solana transactions submission for you!
Interact with Solana Wallets
We recommend using @solana/wallet-adapter to interact with Solana wallets and build transactions. It provides a standardizedAdapter object that wraps all major Solana wallets (e.g. Phantom, Backpack, etc…), as well as visual React components for wallet selection. See here for all the supported wallets.
Set up the SkipClient to use a Solana wallet
All you need to do is initialize the getSVMSigner method in SkipClient.options to extract the @solana/wallet-adapter-base from the user’s connected wallet of choice:
TypeScript
route, executeRoute, and the other methods of SkipClient as you normally would.
The rest of these docs cover the underlying details of the data structures, in case you need them.
Understand SvmTx Data Structure
The SvmTx has 2 fields that the developer needs to understand:
chain_id: The ID of the chain that this transaction should be submitted totx: This is the base64 encoded bytes of the transaction you should have the end user sign.
Info on SvmTx.tx
This is a fully constructed transaction. You don’t need to change it or add anything to it to prepare it for signing. You just need to sign it and have the user submit it on chain within about 1 minute (or the nonce will expire).
For more detail, the transaction already includes:
- User’s nonce (In Solana, this is actually a recent blockhash by default)
- Instructions (Solana’s equivalent to messages)
- Base transaction fees (Set to the default of 500 lamports per signature)
- Priority fees (More info on how we set these below)
Signing tx
Skip Go Client takes care of all of the complexity of signing the transaction that gets returned in SvmTx.tx.
You just need to have set the getSVMSigner method in the SkipClientOptions object in the SkipClient constructor then use executeRoute or executeTxs.
How Priority Fees are Set
Solana “priority fees” affect how likely it is a transaction gets included in a block. Unlike for many other major blockchain networks, Solana’s priority fees are evaluated “locally”. In other words, the size of the fee is compared to other transactions that access the same pieces of state (e.g. the same DEX pool, the same token contract etc…):- If the fee is low relative to other transactions that access the same state, the transaction is unlikely to get included.
- If its high relative to these other transactions accessing similar state, its likely to be included
Have questions or feedback? Help us get better!Join our Discord and select the “Skip Go Developer” role to share your questions and feedback.