MsgTransfer

可替代代币的跨链转移可通过使用 MsgTransfer 来实现:
type MsgTransfer struct {
    SourcePort        string
  / 在 IBC v2 中,SourceChannel 将是一个 client ID
  SourceChannel     string 
  Token             sdk.Coin
  Sender            string
  Receiver          string
  / 如果你使用 IBC v1 协议发送,则必须设置 timeout_height 或 timeout_timestamp 之一。
  / 如果你使用 IBC v2 协议发送,则必须设置 timeout_timestamp,并且必须省略 timeout_height。
  TimeoutHeight     ibcexported.Height
  / 自 Unix 纪元以来的绝对纳秒超时时间戳。
  TimeoutTimestamp  uint64
  / 可选的 Memo 字段
  Memo              string
  / 可选的 Encoding 字段 
  Encoding          string
}
在以下情况下,此消息预期会失败:
  • 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 附加源回调:
{
  "src_callback": {
  "address": "callbackAddressString",
    / 可选
    "gas_limit": "userDefinedGasLimitString",
  }
}
你可以在 chain registry 中找到更多关于使用 memo 字段的其他应用的信息。

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:
type MsgTransfer struct {
    SourcePort        string
  / with IBC v2 SourceChannel will be a client ID
  SourceChannel     string 
  Token             sdk.Coin
  Sender            string
  Receiver          string
  / If you are sending with IBC v1 protocol, either timeout_height or timeout_timestamp must be set.
  / If you are sending with IBC v2 protocol, timeout_timestamp must be set, and timeout_height must be omitted. 
  TimeoutHeight     ibcexported.Height
  / Timeout timestamp in absolute nanoseconds since unix epoch.
  TimeoutTimestamp  uint64
  / optional Memo field
  Memo              string
  / optional Encoding field 
  Encoding          string
}
This message is expected to fail if:
  • SourcePort is invalid (see 24-host naming requirements.
  • SourceChannel is invalid (see 24-host naming requirements).
  • Token is invalid:
    • Amount is not positive.
    • Denom is not a valid IBC denomination.
  • Sender is empty.
  • Receiver is empty or contains more than 2048 bytes.
  • Memo contains more than 32768 bytes.
  • TimeoutHeight and TimeoutTimestamp are both zero for IBC Classic.
    • Note that TimeoutHeight as a concept is removed in IBC v2, hence this must always be emitted and only TimeoutTimestamp used.
This message will send a fungible token to the counterparty chain represented by the counterparty Channel End connected to the Channel End with the identifiers 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:
{
  "src_callback": {
  "address": "callbackAddressString",
    / optional
    "gas_limit": "userDefinedGasLimitString",
  }
}
You can find more information about other applications that use the memo field in the chain registry.

Encoding

In IBC v2, the encoding method used by an application has more flexibility as it is specified within a Payload, 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.