获取代币余额
要查询代币余额,你可以使用balances 函数,或通过 REST API 进行查询。你可以指定一组要查询的 token denom,也可以将数组留空,以获取某个地址关联的所有 denom 的余额。
- 未指定 denoms 时:响应只会包含你当前有余额的 denoms。
- 指定 denoms 时:响应会包含所有指定 denoms 的余额。如果某个 denom 没有余额,也会返回该 denom,且余额为零。
获取 gas 和费用信息
视频概览这里有一份关于我们的 gas 和交易费用工具的视频概览。
MAX 按钮)。
getRecommendedGasPrice
该函数会返回 API 针对某条链上的交易建议使用的 gas price(即单个 gas 单位的价格)。
GasPrice 是一个 cosmjs 类型,用于给出建议的费用 denom 和建议的价格数量(fee/gas):
getFeeInfoForChain
该函数会根据 chainId 返回某条链的高、中、低 gas price,以及默认费用 denom,对应为一个 FeeAsset 对象:
在 ExecuteRouteOptions 中自定义交易 gas 和费用的设置项
ExecuteRouteOptions.getGasPrice
ExecuteRouteOptions 中的这个字段允许你按链覆盖路由器为交易创建时使用的默认 gas price(例如在 executeRoute 中):
getGasPrice?: (chainId: string) => Promise<GasPrice | undefined>;
该参数是一个函数,接收链 ID,并以来自 CosmJS 的 GasPrice 对象形式返回该链的 gas price。
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 thebalances 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.
Getting info about gas and fees
Video OverviewHere’s a video overview of our gas and transaction fee tooling.
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.
GasPrice is a cosmjs type giving the recommended fee denom and recommend price amount (fee/gas):
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:
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
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