layerzero-messaging

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LayerZero Messaging (Hedera)

LayerZero 消息传递(Hedera)

OFT pattern: deploy paired Omnichain Fungible Tokens — a standard
OFT
on the EVM side and an HTS connector OFT on Hedera — then
setPeer
both ways and send with LayerZero V2 fees.
text
OFT (EVM)  ←setPeer→  HTSConnectorOFT (Hedera)
  │ send / quoteSend          │ _debit burn / _credit mint (HTS 0x167)
  └──────── Endpoint V2 + ULN + DVN + Executor ────────┘
This skill focuses on LayerZero V2 OApp/OFT + Hedera HTS. Educational templates may use simple workers and a manual/UI
lzReceive
relay — not the same as production LayerZero Labs verification.
OFT模式: 部署配对的全链同质化代币——EVM侧为标准
OFT
,Hedera侧为HTS连接器OFT——之后双向执行
setPeer
,并支付LayerZero V2费用进行消息发送。
text
OFT (EVM)  ←setPeer→  HTSConnectorOFT (Hedera)
  │ send / quoteSend          │ _debit burn / _credit mint (HTS 0x167)
  └──────── Endpoint V2 + ULN + DVN + Executor ────────┘
本技能聚焦于LayerZero V2 OApp/OFT + Hedera HTS。教学模板可能会使用简单工作节点和手动/UI式
lzReceive
中继——这与生产环境的LayerZero Labs验证机制不同。

Quick Reference

快速参考

ConceptRule
Endpoint
ILayerZeroEndpointV2
per chain
Peer
setPeer(remoteEid, bytes32(uint256(uint160(remoteOApp))))
on both sides
Send
quoteSend(SendParam, payInLzToken)
→
send{value: nativeFee}(SendParam, fee, refund)
Receiver
to
in
SendParam
is
bytes32
(padded address)
Hedera OFTHTS-backed connector — create HTS token, burn on send, mint on receive
HTS feeDeploy connector with native value to pay
createFungibleToken
ApprovalUser must
approve(connector, amount)
on the HTS token before Hedera → EVM
send
IDsUse LayerZero EIDs in peers/
dstEid
— not EVM chain IDs
See references/hedera-endpoints.md for where to source Endpoint/ULN/DVN addresses. See references/examples.md for wire and send sketches.
概念规则
Endpoint每条链对应一个
ILayerZeroEndpointV2
Peer需在两端执行
setPeer(remoteEid, bytes32(uint256(uint160(remoteOApp))))
Send先调用
quoteSend(SendParam, payInLzToken)
询价,再调用
send{value: nativeFee}(SendParam, fee, refund)
发送
Receiver
SendParam
中的
to
字段为
bytes32
类型(补零填充的地址)
Hedera OFTHTS支撑的连接器——创建HTS代币,发送时销毁,接收时铸造
HTS fee部署连接器时附带原生代币价值,用于支付
createFungibleToken
费用
Approval在Hedera向EVM执行
send
前,用户必须对HTS代币执行
approve(connector, amount)
授权
IDs在对等节点/
dstEid
中使用LayerZero EIDs,而非EVM链ID
Endpoint/ULN/DVN地址的获取方式请参考references/hedera-endpoints.md。连接配置与发送流程的示例请参考references/examples.md。

Critical: Wire Both Directions

关键注意事项:双向配置连接

Incomplete peer config bricks the pathway. For each local OApp:
  1. setPeer(remoteEid, remoteOAppAsBytes32)
  2. setSendLibrary
    /
    setReceiveLibrary
    (ULN302)
  3. setConfig
    — ExecutorConfig (type
    1
    ) on send lib; UlnConfig (type
    2
    ) on send + receive libs
  4. setEnforcedOptions
    — e.g.
    lzReceive
    gas for msgType
    1
    (token send)
Verify with
peers(remoteEid)
on both chains before sending.
对等节点配置不完整会导致通路完全失效。对于每个本地OApp,需完成以下配置:
  1. setPeer(remoteEid, remoteOAppAsBytes32)
  2. 配置
    setSendLibrary
    /
    setReceiveLibrary
    (使用ULN302)
  3. 执行
    setConfig
    ——发送库配置ExecutorConfig(类型
    1
    );发送库与接收库均需配置UlnConfig(类型
    2
    )
  4. 配置
    setEnforcedOptions
    ——例如为消息类型
    1
    (代币发送)设置
    lzReceive
    的gas上限
发送前,请在两条链上分别调用
peers(remoteEid)
验证配置是否正确。

Critical: Hedera HTS Connector Semantics

关键注意事项:Hedera HTS连接器语义

On Hedera, do not use a plain ERC-20 OFT as the primary path. Use an HTS-backed connector:
  • Constructor creates fungible HTS via precompile
    0x167
    (supply key = connector)
  • _debit
    : transfer HTS in → burn
  • _credit
    : mint → transfer HTS out
  • Amounts must fit
    int64
    for HTS mint/burn/transfer
  • Associate the receiver account with the HTS token before EVM → Hedera receives
solidity
// Deploy with value so createFungibleToken fee is paid
new HTSConnectorOFT{ value: htsCreateValue }(name, symbol, lzEndpoint, owner);
在Hedera上,请勿使用普通ERC-20 OFT作为主通路,应使用HTS支撑的连接器:
  • 构造函数通过预编译合约
    0x167
    创建同质化HTS代币(供应密钥为连接器合约)
  • _debit
    :转入HTS → 销毁
  • _credit
    :铸造 → 转出HTS
  • HTS的铸造/销毁/转账金额必须在
    int64
    范围内
  • 在EVM向Hedera转账前,需将接收方账户与HTS代币进行关联
solidity
// Deploy with value so createFungibleToken fee is paid
new HTSConnectorOFT{ value: htsCreateValue }(name, symbol, lzEndpoint, owner);

Send Flow

发送流程

solidity
SendParam memory sendParam = SendParam({
    dstEid: remoteEid,
    to: bytes32(uint256(uint160(receiver))),
    amountLD: amountLD,
    minAmountLD: (amountLD * 9) / 10,
    extraOptions: OptionsBuilder.newOptions().addExecutorLzReceiveOption(lzReceiveGas, 0),
    composeMsg: "",
    oftCmd: ""
});

MessagingFee memory fee = IOFT(localOFT).quoteSend(sendParam, false);
IOFT(localOFT).send{ value: fee.nativeFee }(sendParam, fee, payable(refundTo));
Hedera → EVM note: forge fee simulation can disagree with Hedera JSON-RPC wei/tinybar scaling — often
quote
via
cast
+ scaled native fee for that direction.
solidity
SendParam memory sendParam = SendParam({
    dstEid: remoteEid,
    to: bytes32(uint256(uint160(receiver))),
    amountLD: amountLD,
    minAmountLD: (amountLD * 9) / 10,
    extraOptions: OptionsBuilder.newOptions().addExecutorLzReceiveOption(lzReceiveGas, 0),
    composeMsg: "",
    oftCmd: ""
});

MessagingFee memory fee = IOFT(localOFT).quoteSend(sendParam, false);
IOFT(localOFT).send{ value: fee.nativeFee }(sendParam, fee, payable(refundTo));
Hedera → EVM注意事项: forge的费用模拟结果可能与Hedera JSON-RPC的wei/tinybar换算比例不一致——该方向通常使用
cast
调用
quote
并按比例调整原生代币费用。

Deploy Checklist (generic)

部署检查清单(通用)

  1. Deploy EVM
    OFT
    (optional premint)
  2. Deploy Hedera HTS connector OFT with HTS create value
  3. Deploy workers (Labs DVN/executor or educational simple workers)
  4. Wire both OApps (
    setPeer
    + libraries + config + enforced options)
  5. Associate Hedera account with
    htsTokenAddress()
  6. Sync frontend config if applicable; fund relay key if using UI auto-relay
  7. Send small amount; track on LayerZero Scan (testnet/mainnet as appropriate)
  1. 部署EVM端
    OFT
    (可选择预铸造)
  2. 附带HTS创建费用,部署Hedera HTS连接器OFT
  3. 部署工作节点(可使用Labs DVN/执行器或教学用简单工作节点)
  4. 配置两个OApp的双向连接(
    setPeer
    + 库配置 + 参数配置 + 强制选项)
  5. 将Hedera账户与
    htsTokenAddress()
    对应的代币关联
  6. 如适用,同步前端配置;如使用UI自动中继,为中继密钥充值
  7. 发送小额测试;在LayerZero Scan上追踪交易(根据环境选择测试网/主网)

Educational Relay

教学用中继

Some templates use simple DVN/executor mocks and an explicit
lzReceive
relay step. Treat that as a learning aid — production apps rely on LayerZero’s verification network, not a custom relayer key in the app server.
部分模板使用简易DVN/执行器模拟程序和显式的
lzReceive
中继步骤。这仅作为学习辅助——生产应用应依赖LayerZero的验证网络,而非应用服务器中自定义的中继密钥。

Checklist

检查清单

  • Peers set both ways with correct EIDs (not EVM chain IDs)
  • Send/receive libraries + ULN/executor config applied
  • Hedera side is HTS connector; create fee paid; supply key is connector
  • Receiver associated with HTS token before inbound transfers
  • quoteSend
    native fee attached to
    send
  • Receiver address encoded as
    bytes32
  • Educational disclaimer: not audited / not for mainnet funds
  • 已双向配置对等节点,且使用正确的EIDs(而非EVM链ID)
  • 已配置发送/接收库 + ULN/执行器参数
  • Hedera端为HTS连接器;已支付创建费用;供应密钥为连接器合约
  • 入账前,接收方已与HTS代币关联
  • send
    调用已附带
    quoteSend
    计算出的原生代币费用
  • 接收方地址已编码为
    bytes32
    格式
  • 教学免责声明:未经过审计/不可用于主网资金

References

参考资料