Before you begin
The commands on this page need: Follow the tutorial to set up a deployment with a GMP app, a client, and a running relayer. Once you have a live connection and a running relayer, you’ll need the following values from each chain. Run the commands in this guide from theibc/cli directory:
1. Deploy a contract to call
A GMP call arrives on the destination as a contract call, carrying the packet’s payload as its call data. Every GMP call executes through an account contract that belongs to the sender, so the target reads that account’s address asmsg.sender.
Create a Foundry project in the ibc/cli directory:
- Write a receiver that stores a value it is passed and the caller. Save it in the project as
gmp-guide/src/Remote.sol:
- Deploy the contract on the destination chain:
- Keep the address it printed:
2. Send the call
Sending is a single call tosendCall on the source chain’s GMP contract:
set(42), addressed to the Remote contract you deployed on chain B.
- Encode the call to be made as the payload:
- Read the source chain’s clock and pick a timeout an hour out:
- Dry-run the send:
- Send the source transaction, keeping the hash so you can relay it:
3. Relay the packet
The relayer will pick up the packet automatically and relay it to the destination chain. The command below reads the tutorial’s relayer; add--config <file> if yours runs from a different one, as it does after Run a standalone relayer.
You can watch the transaction settle on the destination. This takes about a minute:
Verify the call landed
Now verify the state changed on the destination contract:Contract acknowledgement callbacks
When sending from a contract, the sender can receive the acknowledgement by implementing two callback functions:GMPAcknowledgement when success is true, and carry a fixed error constant when it is not.
- GMP only calls back if your contract advertises that it can receive callbacks. You can do that by inheriting
IBCCallbackReceiver. - Each
sendCallreturns a sequence number. Save it if you need to match an acknowledgement to the call that caused it.