Skip to content

Commit

Permalink
fix: update Amplifier GMP example (#1188)
Browse files Browse the repository at this point in the history
Co-authored-by: Laith <[email protected]>
Co-authored-by: benjamin852 <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent a670b52 commit fa06def
Showing 1 changed file with 63 additions and 47 deletions.
110 changes: 63 additions & 47 deletions src/content/docs/dev/amplifier/gmp-example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,141 +6,157 @@ This example shows the execution of a GMP call from the Ethereum Sepolia to the

You will need:

- An [`axelard` node](/dev/amplifier/chain-integration/introduction/) that is [connected to the devnet](/validator/amplifier/verifier-onboarding/)
- A [funded wallet](https://docs.axelar.dev/dev/amplifier/chain-integration/integrate-a-chain/#make-sure-you-have-a-funded-wallet) on `devnet-amplifier`
- A [Solidity contract](https://github.com/cjcobb23/axelar-examples/blob/main/examples/evm/call-contract/CallContract.sol) deployed to the Ethereum Sepolia and Avalanche Fuji testnets
- We use a [sample contract](https://github.com/axelarnetwork/axelar-examples/blob/main/examples/evm/call-contract/CallContract.sol) throughout this demo

## Helpful references

- [Amplifier devnet contract addresses](https://github.com/axelarnetwork/axelar-contract-deployments/pull/187/files)
- [Amplifier devnet contract addresses](https://github.com/axelarnetwork/axelar-contract-deployments/blob/main/axelar-chains-config/info/devnet-amplifier.json)
- [`axelar-amplifier` GitHub repository](https://github.com/axelarnetwork/axelar-amplifier)

## 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](https://testnet.axelarscan.io/), which should look something like [this](https://sepolia.etherscan.io/tx/0xeafbc1283699c49ba4f79ec43d8749fd82ca4ee14c236787dd25a2f7d4932daa). Note the transaction hash and log index.
Use `callContract()` to execute the contract call on Ethereum Sepolia, then locate the `ContractCall` event in the transaction details on [Axelarscan](https://devnet-amplifier.axelarscan.io/), which should look something like [this](https://devnet-amplifier.axelarscan.io/gmp/0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1). 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`:
Once the transaction is finalized on the source chain, call `verify_messages` at the source chain’s `AxelarGateway`:

```bash
axelard tx wasm execute axelar18csycs4vm6varkp00apuqlsm7v4twg8jsljk8wfdd7cghr7g4rtsltrlkp \
axelard tx wasm execute axelar18zrymnzgdmutdjhqlfsslzy4yvzw8uylysjwqlq4uk4muq3qx30qde39qz \
'{
"verify_messages":
[
{
"cc_id":
{
"source_chain":"ethereum-sepolia",
"message_id":"0xeafbc1283699c49ba4f79ec43d8749fd82ca4ee14c236787dd25a2f7d4932daa-60"
"source_chain":"eth-sepolia",
"message_id":"0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1"
},
"destination_chain":"avalanche",
"destination_address":"0xCa85f85C72df5f8428a440887CA7c449D94e0D0c",
"source_address":"0x6F4f1eb0546872c4BE7bCe4EaD35f24119A5DA77",
"payload_hash":"64b8427717b2ce8573a0c37e03e30ec683c2fe57dcee4d426d22cf43c7692675"
"destination_chain":"avalanche-fuji",
"destination_address":"0x9F101c23CAcFC7773aAcaE0034d2b34B888dDC91",
"source_address":"0x857d737C37A83d6294bA801DD6874dcD6BdbC707",
"payload_hash":"d9f29a4e347ad89dc70490124ee6975fbc0693c7e72d6bc383673bfd0e8841f2"
}
]
}' \
--from validator \
--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
```

Wait for verification, which usually takes 1-3 blocks. Then call `route_messages()`:
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`:

```bash
axelard tx wasm execute axelar18csycs4vm6varkp00apuqlsm7v4twg8jsljk8wfdd7cghr7g4rtsltrlkp \
axelard tx wasm execute axelar18zrymnzgdmutdjhqlfsslzy4yvzw8uylysjwqlq4uk4muq3qx30qde39qz \
'{
"route_messages":
[
{
"cc_id":
{
"source_chain":"ethereum-sepolia",
"message_id":"0xeafbc1283699c49ba4f79ec43d8749fd82ca4ee14c236787dd25a2f7d4932daa-60"
"source_chain":"eth-sepolia",
"message_id":"0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1"
},
"destination_chain":"avalanche",
"destination_address":"0xCa85f85C72df5f8428a440887CA7c449D94e0D0c",
"source_address":"0x6F4f1eb0546872c4BE7bCe4EaD35f24119A5DA77",
"payload_hash":"64b8427717b2ce8573a0c37e03e30ec683c2fe57dcee4d426d22cf43c7692675"
"destination_chain":"avalanche-fuji",
"destination_address":"0x9F101c23CAcFC7773aAcaE0034d2b34B888dDC91",
"source_address":"0x857d737C37A83d6294bA801DD6874dcD6BdbC707",
"payload_hash":"d9f29a4e347ad89dc70490124ee6975fbc0693c7e72d6bc383673bfd0e8841f2"
}
]
}' \
--from validator \
--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:
Call `construct_proof` at the multisig-prover corresponding to the destination chain:

```bash
axelard tx wasm execute axelar1qum2tr7hh4y7ruzew68c64myjec0dq2s2njf6waja5t0w879lutqv062tl \
axelard tx wasm execute axelar1p22kz5jr7a9ruu8ypg40smual0uagl64dwvz5xt042vu8fa7l7dsl3wx8q \
'{
"construct_proof":
{
"message_ids":
[
{
"source_chain":"ethereum-sepolia",
"message_id":"0xeafbc1283699c49ba4f79ec43d8749fd82a4ee14c236787dd25a2f7d4932daa-60"
"source_chain":"eth-sepolia",
"message_id":"0x7bf03d8fc010f28de8689a24f12a515b7968ea1dc139ed4e7520acfc22f4a0e4-1"
}
]
}
}' \
--from validator \
--gas auto --gas-adjustment 1.5
--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:

```bash
{\"key\":\"multisig_session_id\",\"value\":\"1\"}
{\"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()`:
Wait for signing to complete, which usually takes 1-3 blocks. Then call `get_proof`:

```bash
axelard q wasm contract-state smart axelar1qum2tr7hh4y7ruzew68c64myjec0dq2s2njf6waja5t0w879lutqv062tl \
axelard q wasm contract-state smart axelar1p22kz5jr7a9ruu8ypg40smual0uagl64dwvz5xt042vu8fa7l7dsl3wx8q \
'{
"proof":
{
"multisig_session_id":"1"
"multisig_session_id":"881"
}
}'
}' --node http://devnet-amplifier.axelar.dev:26657
```

The output should look something like this:


```bash
data:
data:
commands:
- id: c767e0ff9bcfcfa11d5346095b2c969fedb1c4a87bbf9fd0cb82578eda6fecc2
params: 00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000079a35fd62dbaa820d3025b3400ebce17cdd6c58764b8427717b2ce8573a0c37e03e30ec683c2fe57dcee4d426d22cf43c769267500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010657468657265756d2d7365706f6c696100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a30784134663130663736423836453031423938646146363641336430326136356531346164623037363700000000000000000000000000000000000000000000
ty: approve_contract_call
destination_chain_id: "43113"
message_ids:
- chain: ethereum-sepolia
id: 0xeafbc1283699c49ba4f79ec43d8749fd82ca4ee14c236787dd25a2f7d4932daa-60
multisig_session_id: "1"
- 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: 09c5eabe000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006e00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000002e0000000000000000000000000000000000000000000000000000000000000a869000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000001c767e0ff9bcfcfa11d5346095b2c969fedb1c4a87bbf9fd0cb82578eda6fecc2000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000013617070726f7665436f6e747261637443616c6c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000079a35fd62dbaa820d3025b3400ebce17cdd6c58764b8427717b2ce8573a0c37e03e30ec683c2fe57dcee4d426d22cf43c769267500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010657468657265756d2d7365706f6c696100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a307841346631306637364238364530314239386461463636413364303261363565313461646230373637000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000380000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000030000000000000000000000008054f16ad10c3bf57e178f7f9bc45ea89f84301a00000000000000000000000089a73afebb411c865074251e036d4c12eb99b7ba000000000000000000000000f330a7f2a738eefd5cf1a33211cd131a7e92fdd400000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000415b0df0a1859262dbe806ba916432a688dddf8b31e82138d94d7a4d29ffd04a6f136d6286f02d337ca5632f0c739a4fea909b68c7fee60143bde385cb7c0623f61c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041f5fb2289f995a4ec662cf4b83396ae3beaf004af77e9c60083637cd9596b28b30bf17949473dc6f2bb063bcba9e09ae9b267bb543b852fe43fa5fae6c01f81811b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004123d2d5f8f86b7f568f2503cb156e184c3a96d48c0b3ab8f096f83d31a4a03b057e7ef8b0ac0e36eef8354e0b0acab8475ac6f1801571e82c45ff8eeeaf1a0f9c1c00000000000000000000000000000000000000000000000000000000000000
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`:

```js
> await wallet.sendTransaction({to: gatewayAddress, data: "0x"+executeData, gasLimit:ethers.BigNumber.from(5e+06)}).then((tx) => tx.wait())
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:

```js
> await contract.execute(ethers.utils.arrayify(command_id),source_chain, source_address, ethers.utils.arrayify(payload)).then((tx) => tx.wait())
await contract.execute(ethers.utils.arrayify(command_id),source_chain, source_address, ethers.utils.arrayify(payload)).then((tx) => tx.wait())
```

0 comments on commit fa06def

Please sign in to comment.