MsgTransfer
可替代代币的跨链转移可通过使用 MsgTransfer 来实现:
SourcePort无效(参见 24-host naming requirements)。SourceChannel无效(参见 24-host naming requirements)。Token无效:Amount不是正数。Denom不是有效的 IBC denomination。
Sender为空。Receiver为空,或包含超过 2048 字节。Memo包含超过 32768 字节。- 对于 IBC Classic,
TimeoutHeight和TimeoutTimestamp同时为零。- 请注意,
TimeoutHeight这一概念在 IBC v2 中已被移除,因此这里必须始终省略,并且只能使用TimeoutTimestamp。
- 请注意,
SourcePort 和 SourceChannel 的 Channel End 相连接的对手方 Channel End 表示。请注意,在 IBC v2 中,连接的是一对客户端,而 SourceChannel 指的是源 ClientID。
用于转账的 denomination 应与该链上表示的 denomination 相对应。接收链会在需要时添加相应的前缀。
如果将 Amount 设置为 256 位无符号整数的最大值(即 2^256 - 1),则会转移对应 denomination 的全部余额。transfer 模块 types 包中的辅助函数 UnboundedSpendLimit 提供了可用于此目的的哨兵值。
Memo
添加 memo 字段是为了让应用和用户能够为 transfer packet 附加元数据。该字段是可选的,可以留空。当它用于为特定中间件附加元数据时,memo 字段应表示为一个 json 对象,不同中间件使用不同的 json 键。 例如,以下 memo 字段由 callbacks 中间件使用,用于为 transfer packet 附加源回调:Encoding
在 IBC v2 中,应用使用的编码方式具有更高的灵活性,因为它是在Payload 中指定的,而不是像 IBC classic 那样在通道握手期间协商并固定。某些编码类型可能更适合特定区块链,例如对于 EVM,ABI 编码的解码 gas 成本比 JSON 或 Protobuf 更低。
在 ibc-go 中,支持 JSON、protobuf 和 ABI 编码并可直接使用,参见 transfer packet types。
MsgTransfer
A fungible token cross chain transfer is achieved by using the MsgTransfer:
SourcePortis invalid (see 24-host naming requirements.SourceChannelis invalid (see 24-host naming requirements).Tokenis invalid:Amountis not positive.Denomis not a valid IBC denomination.
Senderis empty.Receiveris empty or contains more than 2048 bytes.Memocontains more than 32768 bytes.TimeoutHeightandTimeoutTimestampare both zero for IBC Classic.- Note that
TimeoutHeightas a concept is removed in IBC v2, hence this must always be emitted and onlyTimeoutTimestampused.
- Note that
SourcePort and SourceChannel. Note that in IBC v2 a pair of clients are connected and the SourceChannel is referring to the source ClientID.
The denomination provided for transfer should correspond to the same denomination represented on this chain. The prefixes will be added as necessary upon by the receiving chain.
If the Amount is set to the maximum value for a 256-bit unsigned integer (i.e. 2^256 - 1), then the whole balance of the corresponding denomination will be transferred. The helper function UnboundedSpendLimit in the types package of the transfer module provides the sentinel value that can be used.
Memo
The memo field was added to allow applications and users to attach metadata to transfer packets. The field is optional and may be left empty. When it is used to attach metadata for a particular middleware, the memo field should be represented as a json object where different middlewares use different json keys. For example, the following memo field is used by the callbacks middleware to attach a source callback to a transfer packet:Encoding
In IBC v2, the encoding method used by an application has more flexibility as it is specified within aPayload, rather than negotiated and fixed during an IBC classic channel handshake. Certain encoding types may be more suited to specific blockchains, e.g. ABI encoding is more gas efficient to decode in an EVM than JSON or Protobuf.
Within ibc-go, JSON, protobuf and ABI encoding are supported and can be used, see the transfer packet types.