-
Couldn't load subscription status.
- Fork 3.8k
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
PingPongPacketstruct to represent the ping pong packet data and a libraryPingPongPacketLibfor encoding and decoding packets. -
Contract Definition: The
PingPongcontract inherits fromIBCAppBaseand 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
initiatefunction 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
initiatefunction. - Upon receiving a packet, the
onRecvPacketfunction is triggered, emitting aRingevent 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.