获取代币余额

要查询代币余额,你可以使用 balances 函数,或通过 REST API 进行查询。你可以指定一组要查询的 token denom,也可以将数组留空,以获取某个地址关联的所有 denom 的余额。
  • 未指定 denoms 时:响应只会包含你当前有余额的 denoms。
  • 指定 denoms 时:响应会包含所有指定 denoms 的余额。如果某个 denom 没有余额,也会返回该 denom,且余额为零。
如果在获取某个 denom 时发生错误(例如链不可用),响应中会包含该 denom 对应的错误信息。
当前的余额查询兼容所有 Skip Go 支持的资产,但不包括 cw20 资产,覆盖 svm、evm 和 Cosmos 链。
const balances = await balances({
  chains: {
  "noble-1": {
    address: noble.address, // noblef8js...
    denoms: ["uusdc"]
  },
  "osmosis-1": {
    address: osmosis.address, // osmois8fo...
    denoms: [] // Fetch all denoms for address
  },
  apiUrl: "https://api.skip.build"
}
});

获取 gas 和费用信息

视频概览这里有一份关于我们的 gas 和交易费用工具的视频概览。
这些函数可用于获取默认 gas 和费用值的信息,或者估算某笔特定交易的费用(例如用来构建可用的 MAX 按钮)。

getRecommendedGasPrice

该函数会返回 API 针对某条链上的交易建议使用的 gas price(即单个 gas 单位的价格)。
async getRecommendedGasPrice({chainId, apiUrl, apiKey}: {chainId: string, apiUrl?:string, apiKey?: string}) -> GasPrice
GasPrice 是一个 cosmjs 类型,用于给出建议的费用 denom 和建议的价格数量(fee/gas):
type GasPrice = {
  denom: string;
  amount: Decimal
}

getFeeInfoForChain

该函数会根据 chainId 返回某条链的高、中、低 gas price,以及默认费用 denom,对应为一个 FeeAsset 对象:
async getFeeInfoForChain({chainId, apiUrl, apiKey}: {chainId: string, apiUrl?:string, apiKey?: string}) -> FeeAsset
type FeeAsset = {
  denom: string;
  gasPrice: GasPriceInfo;
};

type GasPriceInfo = {
  low: string;
  average: string;
  high: string;
};
如果返回值为 undefined,表示 API 无法找到该链的最新 gas price 信息。

在 ExecuteRouteOptions 中自定义交易 gas 和费用的设置项

ExecuteRouteOptions.getGasPrice

ExecuteRouteOptions 中的这个字段允许你按链覆盖路由器为交易创建时使用的默认 gas price(例如在 executeRoute 中): getGasPrice?: (chainId: string) => Promise<GasPrice | undefined>; 该参数是一个函数,接收链 ID,并以来自 CosmJS 的 GasPrice 对象形式返回该链的 gas price。
type GasPrice = {
  denom: string;
  amount: Decimal
}
如果你提供的函数只为部分链返回价格,那么在缺失的情况下,路由器会使用它自己的默认价格。如果它也找不到某条链的默认价格,则会报错。

ExecuteRouteOptions.gasAmountMultiplier

ExecuteRouteOptions 中的这个字段允许你覆盖 SDK 默认使用的 gas multiplier。默认值为 1.5。提高这个值可以更有把握避免交易在执行过程中耗尽 gas,但也会增加最终用户需要支付的费用。 gas multiplier 会以乘法方式增加交易的 gasAmount。为了得到最终的 gas 数量,路由器会:
  • 模拟一笔交易以获取初始 gasAmount
  • 将模拟中消耗的 gas 乘以 gasAmountMultiplier

Getting token balances

To query token balances, you can use the balances function or via the REST API. You have the option to specify a set of token denoms to query or leave the array empty to fetch balances for all denoms associated with an address.
  • When no denoms are specified: The response will include only the denoms for which you have a balance.
  • When denoms are specified: The response will include balances for all the specified denoms. If you have no balance for a given denom, it will be included with a balance of zero.
If there is an error fetching a given denom (e.g. the chain is down), the response will include an error message for that denom.
The balance query is currently compatible with all Skip Go-supported assets, excluding cw20 assets, across svm, evm, and Cosmos chains.
const balances = await balances({
  chains: {
  "noble-1": {
    address: noble.address, // noblef8js...
    denoms: ["uusdc"]
  },
  "osmosis-1": {
    address: osmosis.address, // osmois8fo...
    denoms: [] // Fetch all denoms for address
  },
  apiUrl: "https://api.skip.build"
}
});

Getting info about gas and fees

Video OverviewHere’s a video overview of our gas and transaction fee tooling.
These functions are useful for getting information about our default gas and fee values or for estimating the fee for a particular transaction (e.g. so you can build a working MAX button).

getRecommendedGasPrice

This returns the gas price (i.e. the price of a single unit of gas) the API recommends you use for transactions on a particular chain.
async getRecommendedGasPrice({chainId, apiUrl, apiKey}: {chainId: string, apiUrl?:string, apiKey?: string}) -> GasPrice
GasPrice is a cosmjs type giving the recommended fee denom and recommend price amount (fee/gas):
type GasPrice = {
  denom: string;
  amount: Decimal
}

getFeeInfoForChain

This will return high, medium, and low gas prices for a particular chain, given by chainId, along with the default fee denom as a FeeAsset object:
async getFeeInfoForChain({chainId, apiUrl, apiKey}: {chainId: string, apiUrl?:string, apiKey?: string}) -> FeeAsset
type FeeAsset = {
  denom: string;
  gasPrice: GasPriceInfo;
};

type GasPriceInfo = {
  low: string;
  average: string;
  high: string;
};
An undefined response indicates that the API cannot find up-to-date gas price information for the chain.

Settings on ExecuteRouteOptions for customizing how gas & fees are set on transactions

ExecuteRouteOptions.getGasPrice

This field in ExecuteRouteOptions allows you to override our default gas price on a per chain basis for any transactions created in the router (e.g. in executeRoute): getGasPrice?: (chainId: string) => Promise<GasPrice | undefined>; The argument is a function that takes in a chain ID and returns a gas price for that chain as a GasPrice object from CosmJS
type GasPrice = {
  denom: string;
  amount: Decimal
}
If you provide a function that only returns a price for a subset of chains, the router will use its default price in cases where yours is missing. If it can’t find a default price for a chain, it will error.

ExecuteRouteOptions.gasAmountMultiplier

This field in ExecuteRouteOptions allows you to override the default gas multiplier used by default in the SDK. The default value is 1.5. Increasing this value provides higher confidence that transactions will not run out of gas while executing, but increases the fee for the end user. The gas multiplier increases a transaction’s gasAmount multiplicatively. To get a final gas amount, the router:
  • Simulates a transaction to get an initial gasAmount
  • Multiplies the gas consumed in the simulation by gasAmountMultiplier