-
Notifications
You must be signed in to change notification settings - Fork 40
PingPong
The PingPong
contract implements a simple ping pong protocol that alternates between sending "ping" and "pong" messages between two contracts deployed on two different blockchains connected via IBC.
The contract consists of the following components:
-
Data Structures and Library: Defines a
PingPongPacket
struct to represent the ping pong packet data and a libraryPingPongPacketLib
for encoding and decoding packets. -
Contract Definition: The
PingPong
contract inherits fromIBCAppBase
and implements the IBC callbacks. -
Constructor: Initializes the contract with the IBC handler, revision number, and the number of blocks before pong timeout.
-
IBCAppBase Overrides: Overrides functions required by the IBC protocol, including
ibcAddress
,onRecvPacket
, and channel open/close callbacks. -
Initiation: The
initiate
function sends a ping or pong packet to the counterparty chain.
- The contract is deployed with the IBC handler, revision number, and timeout information.
- One side of the channel initiates the ping pong protocol by calling the
initiate
function. - Upon receiving a packet, the
onRecvPacket
function is triggered, emitting aRing
event and sending a response packet to the counterparty chain. - The protocol continues to alternate between ping and pong messages as each side of the channel processes incoming packets.
The PingPong
contract showcases a basic example of cross-chain communication over IBC using Solidity. It demonstrates how developers can implement a simple ping pong protocol, exchanging packets and alternating between ping and pong messages. This example serves as a starting point for building more complex cross-chain applications using IBC and Solidity.