Cosmos SDK - Neutron Terra
Publish on chain using CosmWasm
Pre-requisite
At this stage, we assume that you followed the steps at ReactJs.
We will be using
-
Keplr as a wallet to interact with the frontend interface. Make sure that you have it installed and funded via Neutron-Testnet Faucet Channel.
-
Wamskit for compiling and deploying the cosmwasm contracts. It is automatically installed when installing npm modules.
-
Hermes for IBC relayer. For the installation, please refer to this installation guide.
You can access the code of this walkthrough on Gitlab:
Contract deployment
Clone the client contract repo.
The Neutron-Client contract interacts with Terra-host contract for sending verification requsts. The Terra-host contract receives the request, relays it to the Core Verification contract deployed on the same network and records the result in itself.
Add your wallet information.
- Neutron-Client
Add your wallet credentials to your wasmkit.config.js
as specified in wasmkit.config.js.example
.
- Terra-Host
Make an .env
file in the scripts
folder and add your wallet MNEMONIC there.
Deploy and verify a proof.
- Neutron-Client
Take a look at wasmkit.config.js
, make sure that you have the correct RPCs and contract addresses.
By running the following commands, you can compile, upload the contract and instantiate it.
Run the script and take a note of your contract address, we will be using them later.
To verify a Reclaim proof on it, run wasmkit run scripts/verifyProof.ts
.
Here is an example of how your output should look like:
- Terra-host
Run the following commands to upload the contract and instantiate it.
Take a note of the deployed contract address. We're going to need it.
IBC Relayer Configuration
Adding a private key
Prepare two wallets(Neutron and Terra) with enough funds in them. They will be used for executing IBC messages on both chains.
Run the following commands for setting up accounts.
Warning: If you look at the keyterra.json
file in the $HOME/.hermes/keys/phoenix-1/keyring-test
,
you may see a different account address from your wallet address.
That is because Terra's address generation algorithm is different from other cosmos chains and hermes as well.
You should send funds to the account adddress in the json file, as that is the actual address that executes the messages.
Configuration file
The command hermes config auto
provides a way to automatically generate a configuration file for the chains:
If the command runs successfully, it should output something like:
(Make sure that each chain uses the correct corresponding key.)
And generate the following configuration:
Take special care to the highlighted lines. Your setup transaction may fail if the gas settings are not properly configured. Refer them and make your own adjustion.
Creating a channel
Run the following command for creating a channel between the two contracts you have already deployed. Replace the contract addresses with your own.
The channel version should be identical to the one set in your contract.
Now your two contracts can interact with each other.
Perform a health-check
to verify that your setup is correct with:
Save the channel id
in the result and pass them as a parameter in the verifyProof
query.
React client development
Bootstrap project and install packages.
Add the following to project dependency(packages.json) and install modules.
Setup your React codebase.
We will continue building on the reclaim react client, new lines are highlighted below.
Create a new folder (utilities).
Structure the folder as per the following, these are configs to call Reclaim on Neutron.
Copy this to NeutronContext.js.
By default, the values below are for NeutronContext's testnet, uncomment for mainnet.
Copy this to NeutronFunctions.js.
Replace with your contract address. You can leave values as are if you did not do the deployment step, make sure to uncomment values for mainnet.
Wrap the App with the specified Neutron context (index.js).
Create a VerifyProof component.
Include the VerifyProof() function.
Create a ConnectButton component.
Add a button and placeholder for connecting.
Bringing it all together (App.js).
We will submit the proof on chain once we get the success
callback. New lines are highlighted.
Submitting the proof
After requesting a proof from Reclaim and performing the verification on your end, a verify proof button will appear on the screen. Make sure your Keplr is connected, click the button, a wallet pop-up will show prompting you to submit.
Now your proof will get approved on-chain, here is the sample transaction from the screenshot above.