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.
Contract Definition: The
PingPongcontract inherits from
IBCAppBaseand implements the callbacks from
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
onRecvPacket, and channel open/close callbacks.
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
- Upon receiving a packet, the
onRecvPacketfunction is triggered, emitting a
Ringevent 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.
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.
The interface used by the implementation is the one described in the Solidity integration section.