Links
📨

EVM General Message Passing

Learn how to use Axelar General Message Passing in order to send messages between EVM chains and Secret Network
In this tutorial, you will learn how to use Axelar GMP to send a string between Polygon and Secret testnets. To learn more about the flow architecture, see the Axelar documentation here.

Prerequisites

  • For GMP to work, both chain A and chain B must be EVM or Cosmos with a deployed Axelar Gateway contract. For this tutorial we will be using the Polygon testnet Axelar Gateway contracts. We will go into this in more detail momentarily.
  • Have Metamask installed, Polygon Mumbai Network added to your wallet, and your wallet funded with Polygon tokens.
Add Polygon Mumbai Network to your Metamask wallet by navigating to the Polygon testnet explorer and clicking "Add Mumbai Network" in the bottom righthand corner of the homepage.

Upload a contract to Polygon

In order to execute a smart contract on Secret network, you must first upload and instantiate a smart contract on Polygon that can execute messages using Axelar GMP. Axelar has a github repository of example contracts that can be used for GMP. We will be uploading the SendReceive.sol contract to Polygon for this demo.
The Cosmwasm smart contracts in this Axelar repository are not compatible with Secret Network out of the box due to dependency issues. However, we will modify the SendReceive contract to be compatible with Secret Network.
To upload the contract, we will use Remix Online IDE, which is a powerful toolset for developing, deploying, debugging, and testing Ethereum and EVM-compatible smart contracts.
First, navigate to Remix and create a new blank workspace:
Remix workspace
Next, create a new file called SendReceive.sol and paste the Axelar GMP solidity code. This will autofill your workspace with the necessary dependencies for your SendReceive.sol contract 🤯
Now all that's left is to compile and upload the contract. Navigate to the Solidity compiler using the sidebar and click "Compile SendReceive.sol". Then, navigate to "Deploy and run transactions." Toggle the Environment from "Remix VM (Shanghai)" to "Injected Provider - MetaMask" and make sure that in your MetaMask wallet you have currently selected Mumbai network.
The constructor of SendReceive.sol contains 3 variables that you must now input in order to instantiate the contract and link it to Axelar's Polygon gateway contract and gas receiver contract, as well as the Polygon Mumbai chain name:
GATEWAY CONTRACT: "0xBF62ef1486468a6bd26Dd669C06db43dEd5B849B"
GASRECEIVER CONTRACT: "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6"
CHAINNAME: "Polygon"
Input these strings like so and then click "Transact":
SendReceive constructor
Upon successful instantiation, the contract address will be returned in the Remix terminal, which you can then view on Polygonscan. And the deployed contract can now be interacted with in the "Deployed Contracts" window:
Congrats, you've just deployed an Axelar GMP-compatible contract to Polygon testnet that can send and receive messages to and from a Secret Network smart contract 🎉

Upload a contract to Secret Network

Now that you've uploaded a GMP-compatible contract to Polygon, let's do the same on Secret Network so that the contracts can communicate with each other across the Cosmos!
First, clone this Secret Network examples repository:
git clone https://github.com/scrtlabs/examples
Then, cd into the examples/secret-ethereum-gmp folder
cd examples/secret-ethereum-gmp
and compile the contract by running make build-mainnet in your terminal.
make build-mainnet
If this is your first time working with a Secret contract, visit the Getting Started docs to properly configure your developer environment.
Now, open a new terminal window and cd into examples/secret-ethereum-gmp/node
cd examples/secret-ethereum-gmp/node
and then run npm install to install the package.json dependencies.
npm install
Create a .env file in examples/secret-ethereum-gmp/node and add your wallet mnemonic in order to upload the contract:
.env config
You can then upload and instantiate the contract by running node index.js.
node index.js
Upon successful instantiation, a Secret contract address is returned that you can then use to send messages to and from Polygon:
Secret contract address upon successful instantation
Now let's send a string from Polygon to Secret! 🚀

Send a string from Polygon to Secret

Now that you have a GMP-compatible contract instantiated on Secret Network, you have all of the variables needed in order to send a cross-chain message using the SendReceive.sol contract.
In order to send messages using Axelar GMP, the user prepays the relayer gas fee on the source chain to Axelar’s Gas Services contract.
You can do this in Remix by navigating to the "Deploy and run transactions" tab in the sidebar and adding gas to prepay the gas fee.
To make sure you have enough gas, add .40 Matic, (roughly .20 USD or 400000000000000000 Wei), to the transaction:
Axelar Gas fee
Now all that's left is to execute the transaction! From the "Deployed contracts" section of Remix, open the dropdown for the send function, which should have three inputs: destinationChain, destinationAddress, and message. Input the following:
destinationChain: "secret"
destinationAddress: "Your Secret Contract Address"
destinationMessage: "Your message that you want to send!"
Once you have inputed these strings and your contract address, select "transact." Congratulations! You've just sent a string from Polygon to Secret Network! 🎉

Query the string on Secret

Now that you've successfully executed a cross-chain message from Polygon to Secret using Axelar GMP, let's query the message on Secret Network to see if the message was actually received by the Secret contract.
First, confirm that the transaction has been successfully relayed by Axelar.
The Axelarscan status diagram indicates the following 5 steps were executed successfully:
Axelarscan Transaction Status
Once the transaction has been executed successfully, you can use Secret.js to query the message:
let get_stored_message = async () => {
let query = await secretjs.query.compute.queryContract({
contract_address: contractAddress,
query: {
get_stored_message: {},
},
code_hash: contractCodeHash,
});
console.log(query);
};
get_stored_message();
To execute this query, navigate to the query.js file in examples/secret-ethereum-gmp/node and replace the contractAdress and contractCodeHash with your contract address and code hash, respectively.
Then run node query.
node query
If the message was executed successfully, the query will return the Ethereum wallet address that sent the transaction as well as the message that the wallet included:
{
sender: `0x49e01eb08bBF0696Ed0df8cD894906f7Da635929`,
message: `one small step for Secret!`
}
Great work! Now let's send a string from Secret to Polygon!

Send a string from Secret to Polygon

To execute the SendMessageEvm transaction, navigate to the execute.js file in examples/secret-ethereum-gmp/node and replace the contractAdress and contractCodeHash with your contract address and code hash.
Then, update destinationAddress to your Polygon contract address, and myMessage to the message that you want to send:
execute.js variables

Gas Token

Next, in order to send a GMP message from Secret to Polygon, you need to acquire some AXL tokens and include the correct IBC denom representing those tokens to your transaction to pay for gas, so that the message can be executed over IBC
Learn more about IBC denoms here.
The correct IBC denom is already included in the secret.js transaction, but in order for it to execute successfully, you need to have this IBC denom funded in your wallet. To add this token to your wallet, you can send Axelar tokens to your Secret wallet address over IBC.
If this is your first time sending Axelar testnet tokens over IBC, see an Axelar Gas Token video tutorial here, which guides you through the following steps:
  1. 1.
    Add Axelar testnet to your Keplr wallet by visiting Axelar Satellite (upon visiting the website, a Keplr notification will pop up that says, "https://testnet.satellite.money would like to add blockchain axelar-testnet-lisbon-3 to Keplr")
  2. 2.
    Procure AXL testnet tokens from the Axelar faucet.
  3. 3.
    Send AXL testnet tokens to your Secret testnet wallet address over IBC using Axelar Satellite.
Upon successful transfer, you should now see the new AXL IBC token in your Keplr Wallet:
AXL IBC token
Once you have properly configured your execute.js file and procured the IBC denom needed to execute the transaction, all that's left is to run node execute.
node execute
The transaction should return a transactionHash as well as data about the IBC routing:
send_message_evm() transaction
And for good measure, view the transaction on Polygonscan to see that the message was received!
To actually see the message that you sent, click on "Click to see more":
Polygonscan transaction
And then at "Input Data", view the input as UTF-8 to reveal the decoded message! 👀
Decoded String sent from Secret to Ethereum
Congratulations! You now have all of the tools to send a message from Secret Network to Polygon using Axelar GMP! 🎉

Summary

In conclusion, Axelar's General Message Passing (GMP) offers a powerful solution for achieving secure interchain communication and token transfers across diverse blockchain ecosystems, including Cosmos and Ethereum. With GMP, developers can seamlessly execute smart contracts on one blockchain from another, fostering complete composability within the Web3 landscape. This documentation has guided you through the process of deploying GMP-compatible contracts on both Polygon and Secret Network, illustrating how to send messages across these networks. By following these steps, you have unlocked the potential for seamless interoperability and enhanced functionality in your blockchain applications. Axelar GMP paves the way for a more interconnected and efficient blockchain ecosystem. Congratulations on your successful journey with Axelar GMP!
If you run into any errors or questions, ping the #dev-issues channel on Secret Network's Discord and somebody will get back to you shortly 😊
Last modified 20d ago