---
# System prepended metadata

title: ICA demo

---

# ICA demo


This is the script that needs to be run on both servers, except the chain id needs to be changed on the second server

## Introduction

- Alice is on chain test-1 and  has 100 tokens
- bob is on chain test-2 does not have any token.
- alice knows an faucet user on chain test-2, so she can sometimes ask faucet user to send her some tokens.

1. now, alice wants to send some native token of chain test-2 to bob.

2. alice want to transfer some of her asset on chain test-2 to chain test-1.

3. alice want to delegate the rest of her tokens on chain test-2 to a validator on test-2.

setup: 
- run the [scrip](https://hackmd.io/Sl0Xb2-WTVmnUwpSBvbu3w) to build two chains on digital ocean.
- set up two homes for chain test-1 and test-2, called .gaia, and .gaia2. 
- I also have created a channel `channel-1` for ibc transfer.





Now you can locally compile the binary and run commands from your computer that point to the two ip addresses of the two nodes:

```bash
# gaia home for chain test-1
gaiad config chain-id test-1
gaiad config node http://165.22.23.73:26657
gaiad config keyring-backend test

# gaia home for chain test-2
gaiad config chain-id test-2 --home ~/.gaia2
gaiad config node http://164.90.226.126:26657 --home ~/.gaia2
gaiad config keyring-backend test --home ~/.gaia2

hermes query connections test-1
hermes query channels test-1
```

# Prepare faucet account, and user keys, and ica addr

- Billy has one faucet acct on chain test-1 and one on test-2
  Now add the same faucet account from the server to your local machine so you have an faucet account with some tokens in it for both chains

```bash
echo "history early rice thank umbrella barely pulse issue primary obvious situate wild help fish okay door floor strong comfort rib gesture donate flock until" | gaiad keys add faucet --recover
```

```bash
echo "history early rice thank umbrella barely pulse issue primary obvious situate wild help fish okay door floor strong comfort rib gesture donate flock until" | gaiad keys add faucet --recover --home ~/.gaia2
```


- alice key's mnemonic: (alice on test-1)
```
future inherit oval mosquito beach imitate material volume angry soul blue hungry outdoor census mention mimic curtain acoustic promote mushroom infant obey mask only
```


- bob key's mnemonic (bob on test-2)
```
cable eight shed online tobacco barrel barely garment bracket dial guard holiday jelly soda gallery empty chimney room pizza bird ribbon shaft tiny swallow
```


- export keys as env var
```bash
export FAUCET=$(gaiad keys show faucet -a)
export ALICE=$(gaiad keys show alice -a)
export BOB=$(gaiad keys show bob -a --home .gaia2)
```

- transfer some token of chain test-1 to alice 
```bash
gaiad tx bank send $FAUCET $ALICE 100stake --from faucet
```


----
### From here start demo:

show the setup
```bash
gaiad config 
gaiad config --home .gaia2
gaiad q bank balances $ALICE
gaiad q bank balances $BOB --home .gaia2
```

### task prepare: get ica ready: register and send some token to ica

- get alice ica addr
```bash
gaiad tx icamsgauth register --from alice --connection-id connection-0 --counterparty-connection-id connection-0 --gas 150000 
```

query ica acct
```bash
gaiad q icamsgauth interchainaccounts $ALICE connection-0 connection-0 

```

export ica acct
```bash
export ICA=$(gaiad query icamsgauth interchainaccounts $(gaiad keys show alice -a) connection-0 connection-0 -o json | jq -r '.interchain_account_address')
```
query the connection:
```bash
hermes query connections test-1
```

query the channel: you can see one channel for alice ica
```bash
hermes query channels test-1
```
ica `register` cmd sends a new `MsgChannelOpenInit` internally in the interchain accounts code here and emits the events which hermes listens to and detects, and then hermes finishes the channel handshake by sending the ChannelOpenTry to the counterparty chain (test-2).

faucet send some token to ica

```bash
gaiad tx bank send $FAUCET $ICA 100stake --from faucet --home .gaia2
```
---------

### task 0(skip): ica sends some token to bob through ica
bob now does not have any tokens
Step 1: generate the transaction json
```bash
gaiad tx bank send $ICA $BOB 50stake --chain-id test-2 --generate-only | jq '.body.messages[0]' > ./send-raw.json

cat send-raw.json
```
step 2: send the generated tx json:
```bash
gaiad tx icamsgauth submit-tx ./send-raw.json --connection-id connection-0 --counterparty-connection-id connection-0 --from alice --chain-id test-1 --gas 150000
```

### task1: ica send some tokens to alice through ibc transfer and ica
step1: create ibc channel (maybe ahead before demo)
```bash
hermes create channel  -c connection-0 --port-a transfer --port-b transfer test-1
```

step2:
```bash
gaiad tx ibc-transfer transfer transfer channel-1 $ALICE 10stake --from $ICA --home .gaia2 --generate-only | jq '.body.messages[0]' > send-raw.json


cat send-raw.json
{
  "@type": "/ibc.applications.transfer.v1.MsgTransfer",
  "source_port": "transfer",
  "source_channel": "channel-2",
  "token": {
    "denom": "stake",
    "amount": "10"
  },
  "sender": "cosmos1gzc3junl60s5t7vl9sdlvrc7npt2rm3erkyqdlxq7gcan0m094fqskrtfk",
  "receiver": "cosmos174zg2evx453gn8ztym9xsaa7rjqj7j5v80tgwn",
  "timeout_height": {
    "revision_number": "1",
    "revision_height": "7509"
  },
  "timeout_timestamp": "1642698787145236000"
}
```

step3: ibc tx by ica

```bash
gaiad tx icamsgauth submit-tx send-raw.json --connection-id connection-0 --counterparty-connection-id connection-0 --from alice --gas 150000

```


### task2: ica delegate to val on chain test-2
query validator
```bash
gaiad q staking validators --home .gaia2 -o json | jq
```
val has `7000000000stake`
val oper addr `cosmosvaloper1hckrjqvuhdqncuuy73eu0engkgxn9gjds2jl5m`

```bash
 gaiad tx staking delegate cosmosvaloper1hckrjqvuhdqncuuy73eu0engkgxn9gjds2jl5m 20stake --from $ICA --generate-only | jq '.body.messages[0]' > ./send-raw.json
```

```bash
cat send-raw.json
{
  "@type": "/cosmos.staking.v1beta1.MsgDelegate",
  "delegator_address": "cosmos1gzc3junl60s5t7vl9sdlvrc7npt2rm3erkyqdlxq7gcan0m094fqskrtfk",
  "validator_address": "cosmosvaloper1hckrjqvuhdqncuuy73eu0engkgxn9gjds2jl5m",
  "amount": {
    "denom": "stake",
    "amount": "20"
  }
}
```

query ica delegation
```bash
gaiad q staking delegations $ICA --home .gaia2 -o json | jq
```


### propose upgrade by ica

```bash
gaiad tx gov submit-proposal software-upgrade theta \
--title theta \
--deposit 2stake \
--upgrade-height 73000 \
--upgrade-info "upgrade to theta" \
--description "upgrade to theta" \
--gas 400000 \
--from $ICA \
--home .gaia2 \
--yes \
--generate-only | jq '.body.messages[0]' > send-raw.json
```
```bash

gaiad tx icamsgauth submit-tx send-raw.json --connection-id connection-0 --counterparty-connection-id connection-0 --from alice --gas 150000
```

```bash
gaiad q gov proposals --home .gaia2
```


```
gaiad tx gov vote 1 yes \
> --from $ICA \
> --home .gaia2 \
> --yes --generate-only | jq '.body.messages[0]' > send-raw.json
```


## Note

when creating a new channel, when do tc by this new channel, hermes log: account sequence mismatch problem (this err only appear in hermes v0.9)

the fix was solved in v0.10, but v0.10 currently doesn't work with ICA

----------
notes from Billy


```
# account on `test-1` (aka a)
```bash
gaiad keys show demo | jq
```
```json
{
  "name": "demo",
  "type": "local",
  "address": "cosmos16u7wauye3f6er5kf98k776c3syrrsgwsecm4yq",
  "pubkey": "{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\",\"key\":\"Aie4oCBueIqSwmi+PiiM6QSN4Ih6cmAokSSX2x5RicJ+\"}"
}
```
# Show balance of the account
```bash
gaiad q bank balances $(gaiad keys show demo -a) | jq
```
```json
{
  "balances": [
    {
      "denom": "stake",
      "amount": "100000000000"
    }
  ],
  "pagination": {
    "next_key": null,
    "total": "0"
  }
}
```
# Create ICA account on `test-2` via `test-1`

```bash
gaiad tx icamsgauth register --from demo --connection-id connection-0 --counterparty-connection-id connection-0 --gas 150000
```




# Show the account on `test-2` (AKA a')
```bash
gaiad q icamsgauth interchainaccounts $(gaiad keys show demo -a) connection-0 connection-0 | jq
```
```json
{
  "interchain_account_address": "cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6"
}
```

# Send tokens to the interchain account on `test-2`

```bash=
gaiad tx bank send $(gaiad keys show demo -a --home ~/.gaia2) cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6  99stake --from demo --home ~/.gaia2 -y | jq
```

# show the balance of the interchain account
```bash
gaiad q bank balances cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 --home ~/.gaia2| jq
```
```json
{
  "balances": [
    {
      "denom": "stake",
      "amount": "99"
    }
  ],
  "pagination": {
    "next_key": null,
    "total": "0"
  }
}
```

# Send tokens back to the original account via interchain accounts

