消息协议
LayerZero、CCIP
消息协议 是 CoddyKit 上的免费 Web3 & DApp Development Fundamentals 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Web3 & DApp Development Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Beyond Token Bridges
Moving tokens is just the start. Cross-chain messaging protocols let contracts on one chain send arbitrary data and trigger functions on another.
This generalizes bridging into full cross-chain application logic.
What Is a Messaging Protocol?
A messaging protocol is infrastructure that delivers a payload from a source-chain contract to a destination-chain contract, with some security guarantee about authenticity.
Developers build on top of it instead of operating their own validators.
Generic Message Passing
With generic message passing (GMP), you can send any encoded data — not just token amounts.
A single message can instruct a destination contract to mint, vote, update state, or call any function.
sendMessage(
destChainId,
destContract,
abi.encode("setReward", 500)
);LayerZero
LayerZero is a messaging protocol that uses two independent parties: an Oracle (delivers block headers) and a Relayer (delivers proofs).
A message is valid only if both agree, so security relies on these two being independent and not colluding.
LayerZero Endpoints
Apps integrate via on-chain endpoints. A contract calls send on its source endpoint and implements lzReceive to handle incoming messages.
function lzReceive(
uint16 srcChain,
bytes srcAddress,
uint64 nonce,
bytes payload
) external {
// handle the cross-chain message
}Chainlink CCIP
CCIP (Cross-Chain Interoperability Protocol) from Chainlink uses its decentralized oracle network to relay messages and tokens.
It adds a separate Risk Management Network that independently monitors for anomalies and can pause transfers.
CCIP Messages
CCIP messages can carry data, tokens, or both. Developers send an EVM2AnyMessage and pay fees in LINK or the native gas token.
Client.EVM2AnyMessage message =
Client.EVM2AnyMessage({
receiver: abi.encode(dest),
data: payload,
tokenAmounts: tokens,
feeToken: linkAddress
});Security Through Independence
Both LayerZero and CCIP aim to remove single points of failure by separating roles (oracle vs relayer, or DON vs risk network).
The security argument is that compromising the system requires colluding across independent components.
Idempotency and Replay Protection
Receiving contracts must guard against duplicate delivery. Messages carry a nonce so handlers can ensure each is processed exactly once.
This is the same replay-protection principle bridges need.
require(!seen[srcChain][nonce], "dup");
seen[srcChain][nonce] = true;Use Cases
Generic messaging enables powerful patterns:
- Cross-chain governance — vote on one chain, execute on another
- Omnichain tokens — one token usable everywhere
- Cross-chain DeFi — borrow on A, use on B
Putting It Together
Messaging protocols like LayerZero and CCIP deliver arbitrary cross-chain messages, enabling omnichain applications. They reduce trust by separating independent roles and require replay protection in receiving contracts.
This completes your cross-chain journey.
Quick Check
Test your messaging protocol knowledge.
Recap: Messaging Protocols
You learned that:
- Messaging protocols deliver arbitrary cross-chain data, not just tokens
- LayerZero uses independent oracle + relayer; apps implement
lzReceive - Chainlink CCIP uses a DON plus a risk-management network
- Receivers need nonce-based replay protection
- They enable omnichain governance, tokens, and DeFi
Course complete!
常见问题解答
「消息协议」课时是免费的吗?
是的 — 「消息协议」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Web3 & DApp Development Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Web3 & DApp Development Fundamentals 课程共包含 4 节课。
「消息协议」这节课中我会学到什么?
LayerZero、CCIP 你通过在浏览器中直接运行的动手代码来练习 Web3 & DApp Development Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Web3 & DApp Development Fundamentals 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Web3 & DApp Development Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「消息协议」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Web3 & DApp Development Fundamentals 课中编写并运行代码吗?
能。每节 Web3 & DApp Development Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。