✨Works out of the box guarantee. If you face any issue at all, hit us up on Telegram and we will write the integration for you.
logoReclaim Protocol Docs

Cosmos - XION

Publish on chain using XION and CosmWasm Stargate

Pre-requisite

Before trying the steps below, make sure you have XION Daemon and Docker installed.

You can access the code of this walkthrough on Github:

Contract deployment

Step 1: Clone the Repository

git clone https://github.com/reclaimprotocol/xion-sdk-onchain-integration.git
cd xion-sdk-onchain-integration

Step 2: Compile and Optimize the Wasm Bytecode

docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/optimizer:0.16.0

Step 3: Upload the Bytecode to the Blockchain

Set your signing key name:

WALLET=

Run the upload command:

RES=$(xiond tx wasm store ./artifacts/reclaim_xion.wasm \
      --chain-id xion-testnet-2 \
      --gas-adjustment 1.3 \
      --gas-prices 0.001uxion \
      --gas auto \
      -y --output json \
      --node https://rpc.xion-testnet-2.burnt.com:443 \
      --from $WALLET)

Extract the transaction hash by running:

echo $RES

And set the value:

TXHASH=

Step 4: Retrieve the Code ID

Then, retrieve the code id:

CODE_ID=$(xiond query tx $TXHASH \
  --node https://rpc.xion-testnet-1.burnt.com:443 \
  --output json | jq -r '.events[-1].attributes[1].value')bash copy

And view it:

echo $CODE_ID

Step 5: Instantiate the Contract

Set the contract's initialization message (replace with your own):

MSG='{"owner":"xion138lsa3mczwzl9j7flytg0f5r6pldaa8htddq0j"}'

Instantiate the contract with the Code ID from the previous step:

xiond tx wasm instantiate $CODE_ID "$MSG" \
  --from $WALLET \
  --label "reclaim_xion" \
  --gas-prices 0.025uxion \
  --gas auto \
  --gas-adjustment 1.3 \
  -y --no-admin \
  --chain-id xion-testnet-1 \
  --node https://rpc.xion-testnet-1.burnt.com:443

Example output:

gas estimate: 217976
code: 0
txhash: 09D48FE11BE8D8BD4FCE11D236D80D180E7ED7707186B1659F5BADC4EC116F30

Copy the new transaction hash for the next step.


Step 6: Retrieve the Contract Address

Set the new transaction hash:

TXHASH="your-txhash-here"

Query the blockchain to get the contract address:

CONTRACT=$(xiond query tx $TXHASH \
  --node https://rpc.xion-testnet-1.burnt.com:443 \
  --output json | jq -r '.events[] | select(.type == "instantiate") | .attributes[] | select(.key == "_contract_address") | .value')

Display the contract address:

echo $CONTRACT

Example output:

xion1zcphm9wllvmtlhclvwh8qrlcx46p5mwe4yfdve0c95xfh6arsejspq5nvd

Interact with the Contract

Step 1: Setup

Change directory to the /node directory and install packages:

cd node
 
npm install

Then add your credentials to your .env:

XION_MNEMONIC="your wallet mnemonic phrase here"
XION_RPC_URL=https://rpc.xion-testnet-2.burnt.com
XION_CHAIN_ID=xion-testnet-2
CONTRACT_ADDRESS=xion1zcphm9wllvmtlhclvwh8qrlcx46p5mwe4yfdve0c95xfh6arsejspq5nvd

Step 2: Add an Epoch

While in /node, run the command:

node add-epoch.js

This will add an Epoch, here is an example tx.

You can fetch an added Epoch with:

node get-epoch.js

Step 3: Verify a Proof

While in the same directory, run the command:

node verify_proof.js 

This will add an Epoch, here is an example tx.