General Message Passing with Amplifier Example
This example shows the execution of a GMP call from the Ethereum Sepolia to the Avalanche Fuji testnets.
Prerequisites
You will need:
- A funded wallet on
devnet-amplifier
- A Solidity contract deployed to the Ethereum Sepolia and Avalanche Fuji testnets
- We use a sample contract throughout this demo
Helpful references
Send a GMP call between two chains
Execute the contract call on the source chain
Use callContract()
to execute the contract call on Ethereum Sepolia, then locate the ContractCall
event in the transaction details on Axelarscan, which should look something like this. Note the transaction hash and log index.
Verify messages at the source chain gateway
Once the transaction is finalized on the source chain, call verify_messages
at the source chain’s AxelarGateway
:
axelard tx wasm execute axelar18zrymnzgdmutdjhqlfsslzy4yvzw8uylysjwqlq4uk4muq3qx30qde39qz \ '{ "verify_messages": [ { "cc_id": { "source_chain":"eth-sepolia", "message_id":"0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1" }, "destination_chain":"avalanche-fuji", "destination_address":"0x9F101c23CAcFC7773aAcaE0034d2b34B888dDC91", "source_address":"0x857d737C37A83d6294bA801DD6874dcD6BdbC707", "payload_hash":"d9f29a4e347ad89dc70490124ee6975fbc0693c7e72d6bc383673bfd0e8841f2" } ] }' \ --from wallet \ --keyring-backend test \ --node http://devnet-amplifier.axelar.dev:26657 \ --chain-id devnet-amplifier \ --gas-prices 0.00005uamplifier \ --gas auto --gas-adjustment 1.5
Note: message_id
corresponds to the transaction hash of the transaction on the source chain.
Once this has been sent, you can wait for the transaction to be verified, this will usually takes 1-3 blocks. Then call route_messages
:
axelard tx wasm execute axelar18zrymnzgdmutdjhqlfsslzy4yvzw8uylysjwqlq4uk4muq3qx30qde39qz \ '{ "route_messages": [ { "cc_id": { "source_chain":"eth-sepolia", "message_id":"0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1" }, "destination_chain":"avalanche-fuji", "destination_address":"0x9F101c23CAcFC7773aAcaE0034d2b34B888dDC91", "source_address":"0x857d737C37A83d6294bA801DD6874dcD6BdbC707", "payload_hash":"d9f29a4e347ad89dc70490124ee6975fbc0693c7e72d6bc383673bfd0e8841f2" } ] }' \ --from wallet \ --keyring-backend test \ --node http://devnet-amplifier.axelar.dev:26657 \ --chain-id devnet-amplifier \ --gas-prices 0.00005uamplifier \ --gas auto --gas-adjustment 1.5
Call construct_proof
at the multisig-prover corresponding to the destination chain:
axelard tx wasm execute axelar1p22kz5jr7a9ruu8ypg40smual0uagl64dwvz5xt042vu8fa7l7dsl3wx8q \ '{ "construct_proof": [ { "source_chain":"eth-sepolia", "message_id":"0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1" } ] }' \ --from wallet \ --keyring-backend test \ --node http://devnet-amplifier.axelar.dev:26657 \ --chain-id devnet-amplifier \ --gas-prices 0.00005uamplifier \ --gas auto --gas-adjustment 1.5
Note the multisig_session_id
in the output:
{\"key\":\"multisig_session_id\",\"value\":\"881\"}
Retrieve the signed batch of messages
Wait for signing to complete, which usually takes 1-3 blocks. Then call get_proof
:
axelard q wasm contract-state smart axelar1p22kz5jr7a9ruu8ypg40smual0uagl64dwvz5xt042vu8fa7l7dsl3wx8q \ '{ "proof": { "multisig_session_id":"881" } }' --node http://devnet-amplifier.axelar.dev:26657
The output should look something like this:
data: message_ids: - message_id: 0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1 source_chain: eth-sepolia multisig_session_id: "881" payload: messages: - cc_id: message_id: 0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1 source_chain: eth-sepolia destination_address: 0x9F101c23CAcFC7773aAcaE0034d2b34B888dDC91 destination_chain: avalanche-fuji payload_hash: d9f29a4e347ad89dc70490124ee6975fbc0693c7e72d6bc383673bfd0e8841f2 source_address: 0x857d737C37A83d6294bA801DD6874dcD6BdbC707 status: completed: execute_data: 64f1d85a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001600000000000000000000000009f101c23cacfc7773aacae0034d2b34b888ddc91d9f29a4e347ad89dc70490124ee6975fbc0693c7e72d6bc383673bfd0e8841f2000000000000000000000000000000000000000000000000000000000000000b6574682d7365706f6c696100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000443078376266303364386663303130663238646538363839613234663132613531356237393638656131646331333965643465373532306163666332326634613065342d3100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30783835376437333743333741383364363239346241383031444436383734646344364264624337303700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000002b5c75000000000000000000000000000000000000000000000000000000000000000300000000000000000000000051380cbf0777990e197a3e498ffafd26143e35f8000000000000000000000000000000000000000000000000000000000000000100000000000000000000000061373485594010371dfbf3a8f8bd1736bfda7c090000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c70aa87b38e6ab3c0df6e56338f96a5c00e6530800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004152119e65c7c80829542bfb7766dfd6a7d628a59533a3040db6ee3f35ab7b8c8d38b8e023a3a1c821e2512cfdcfcee73dd54a0d2ad858900cefbc959f7d80610e1c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000417d0c127646384b5ab7145dce5b9adabdf9faca911f119419bd68802e4b3850d85d0b34bd86b90c56daf6ef2ba2821573e87653c462da031793e9dc67e7ef455e1b00000000000000000000000000000000000000000000000000000000000000
Relay the execute data to the destination chain gateway
The execute data can be relayed to the destination chain’s AxelarGateway
in a number of ways. Here’s how to do it with node.js
using ethers
:
await wallet.sendTransaction({to: gatewayAddress, data: "0x"+executeData, gasLimit:ethers.BigNumber.from(5e+06)}).then((tx) => tx.wait())
Execute the contract
Fill in the appropriate values and execute the contract. The command_id
can be found in the response to the get_proof
query:
await contract.execute(ethers.utils.arrayify(command_id),source_chain, source_address, ethers.utils.arrayify(payload)).then((tx) => tx.wait())