# Billy's Cosmos Hub Hack Solution
## Task 1
```
# configure gaiad so that there is relevant chain info in two different directories:
gaiad config chain-id test-1
gaiad config node http://165.22.23.73:26657
gaiad config keyring-backend test
gaiad config chain-id test-2 --home ~/.gaiad2
gaiad config node http://164.90.226.126:26657 --home ~/.gaiad2
gaiad config keyring-backend test --home ~/.gaiad2
# Create account on `test-1` (aka a)
> gaiad keys add demo
# Show account on `test-1` (aka a)
> gaiad keys show demo | jq
{
"name": "demo",
"type": "local",
"address": "cosmos1xpgnzjhz650pljhk7f8szu5rjzfj6e2rw8jl3m",
"pubkey": "{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\",\"key\":\"AxEVQMM3ZbWgnTRYcY/i0RmQ99+RTfx7JmjFHr659wF1\"}"
}
# Show balance of the account that was populated by Billy with `demowallet`
> gaiad q bank balances $(gaiad keys show demo -a) | jq
{
"balances": [
{
"denom": "stake",
"amount": "1000"
}
],
"pagination": {
"next_key": null,
"total": "0"
}
}
# Create ICA account on `test-2` via `test-1`
> 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')
> gaiad q icamsgauth interchainaccounts $(gaiad keys show demo -a) connection-0 connection-0 | jq
{
"interchain_account_address": "cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6"
}
# Show the balance of `a'` on `test-2` that was populated by Billy with `demowallet`
> gaiad q bank balances cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 --home ~/.gaiad2 | jq
{
"balances": [
{
"denom": "stake",
"amount": "1000"
}
],
"pagination": {
"next_key": null,
"total": "0"
}
}
# Create empty account on `test-2`
> gaiad keys add demo --home ~/.gaiad2 --keyring-backend test
> gaiad keys show demo --home ~/.gaiad2 | jq
{
"name": "demo",
"type": "local",
"address": "cosmos1734fsdjhy7unndu2dlks4zfgvzh0x629thq8kt",
"pubkey": "{\"@type\":\"/cosmos.crypto.secp256k1.PubKey\",\"key\":\"A3gopqMAvispe6h/j26+W3vQ7OgbTlxroVHiYvKCcLeN\"}"
}
# Show the empty account on `test-2` is empty
> gaiad q bank balances $(gaiad keys show demo -a --home ~/.gaiad2) --home ~/.gaiad2 | jq
{
"balances": [],
"pagination": {
"next_key": null,
"total": "0"
}
}
# Create the raw send msg for `test-2` to be passed to the ica account on `test-1`
> gaiad tx bank send cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 cosmos1734fsdjhy7unndu2dlks4zfgvzh0x629thq8kt 500stake --from cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 --home ~/.gaiad2 --generate-only | jq '.body.messages[0]' > send-raw.json
# Show the message
> cat send-raw.json
{
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": "cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6",
"to_address": "cosmos1734fsdjhy7unndu2dlks4zfgvzh0x629thq8kt",
"amount": [
{
"denom": "stake",
"amount": "500"
}
]
}
> gaiad tx icamsgauth submit-tx send-raw.json --connection-id connection-0 --counterparty-connection-id connection-0 --from demo -y | jq
{
"height": "0",
"txhash": "5640F02D1D3003AE8878C2EC8C4DAB220551909C613C9615D4F932F4E2485AC3",
"codespace": "",
"code": 0,
"data": "",
"raw_log": "[]",
"logs": [],
"info": "",
"gas_wanted": "0",
"gas_used": "0",
"tx": null,
"timestamp": "",
"events": []
}
# Show that the token was moved between the account:
> gaiad q bank balances $(gaiad keys show demo -a --home ~/.gaiad2) --home ~/.gaiad2 | jq
{
"balances": [
{
"denom": "stake",
"amount": "500"
}
],
"pagination": {
"next_key": null,
"total": "0"
}
}
# TASK ONE IS COMPLETE
```
## Task 2
```
# Send the tokens back to the interchain account
> gaiad tx bank send $(gaiad keys show demo -a --home ~/.gaiad2) cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 500stake --from demo --home ~/.gaiad2 -y | jq
{
"height": "0",
"txhash": "3710C5A023490329A90468CAF60A7F2A30F36E86576658EB22F6179A937D776A",
"codespace": "",
"code": 0,
"data": "",
"raw_log": "[]",
"logs": [],
"info": "",
"gas_wanted": "0",
"gas_used": "0",
"tx": null,
"timestamp": "",
"events": []
}
# Query the balance of the interchain account to show the stake went back
> gaiad q bank balances cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 --home ~/.gaiad2 | jq
{
"balances": [
{
"denom": "stake",
"amount": "1000"
}
],
"pagination": {
"next_key": null,
"total": "0"
}
}
# TASK TWO IS COMPLETE
```
## Task 3
```
# A new channel needs to be opened between the chains to start using ibc-transfer. This is done with the relayer as follows:
hermes --config ./gaia-config.toml create channel --port-a transfer --port-b transfer test-1 test-2 -v ics20-1
# NOTE: I was unable to use --connection-a connection-0 and re-use the initial connection. Is that expected behaviour? Instead a new connection was created with port_id `transfer` and `channel_id` `channel-5` (same on both sides)
# Account on `test-1` to send `stake` to PK controlled account on `test-2`
> gaiad tx ibc-transfer transfer transfer channel-5 $(gaiad keys show demo -a --home ~/.gaiad2) 100stake --from demo -y | jq
{
"height": "0",
"txhash": "BDECF458321A5163E5C7A2F2EBE1548A982A525B1C49159E2CAEF2DB789BBC9E",
"codespace": "",
"code": 0,
"data": "",
"raw_log": "[]",
"logs": [],
"info": "",
"gas_wanted": "0",
"gas_used": "0",
"tx": null,
"timestamp": "",
"events": []
}
# Apparently this failed. Hermes had an error about account number mismatch. I restarted the relayer and the tokens were returned, my guess is because the timeout occured. After the restart I tried again and this time it worked.
> gaiad tx ibc-transfer transfer transfer channel-5 $(gaiad keys show demo -a --home ~/.gaiad2) 100stake --from demo -y | jq
{
"height": "0",
"txhash": "79B2A1B916793ECD7BD39147A32E72ED6B35040C40D3098852A1CBE5A167C9C9",
"codespace": "",
"code": 0,
"data": "",
"raw_log": "[]",
"logs": [],
"info": "",
"gas_wanted": "0",
"gas_used": "0",
"tx": null,
"timestamp": "",
"events": []
}
> gaiad q bank balances $(gaiad keys show demo -a --home ~/.gaiad2) --home ~/.gaiad2 | jq
{
"balances": [
{
"denom": "ibc/E37052AA15C33306A29C10EC2EF99E6681FF485550D8BFCBA059F82A809B2623",
"amount": "100"
}
],
"pagination": {
"next_key": null,
"total": "0"
}
}
# TASK 3 IS COMPLETE
```
## Task 4
```
# Send the IBC token from the `A` account to `a'`
> gaiad tx bank send $(gaiad keys show demo -a --home ~/.gaiad2) cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 100ibc/E37052AA15C33306A29C10EC2EF99E6681FF485550D8BFCBA059F82A809B2623 --from demo --home ~/.gaiad2 -y | jq
{
"height": "0",
"txhash": "4D41351A2AEED8F2B37306D79AB34663D0B26BE2DD667F06251EBD115B302C72",
"codespace": "",
"code": 0,
"data": "",
"raw_log": "[]",
"logs": [],
"info": "",
"gas_wanted": "0",
"gas_used": "0",
"tx": null,
"timestamp": "",
"events": []
}
# Query the balance of the interchain account
> gaiad q bank balances cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 --home ~/.gaiad2 | jq
{
"balances": [
{
"denom": "ibc/E37052AA15C33306A29C10EC2EF99E6681FF485550D8BFCBA059F82A809B2623",
"amount": "100"
},
{
"denom": "stake",
"amount": "1000"
}
],
"pagination": {
"next_key": null,
"total": "0"
}
}
# TASK 4 IS COMPLETE
```
## Task 5
```
# Create the outgoing IBC transaction that sends the IBC token back to the origin chain from the interchain account.
F99E6681FF485550D8BFCBA059F82A809B2623 --from cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6 --generate-only | jq '.body.messages[0]' > ibc-raw.json
> cat ibc-raw.json
{
"@type": "/ibc.applications.transfer.v1.MsgTransfer",
"source_port": "transfer",
"source_channel": "channel-5",
"token": {
"denom": "ibc/E37052AA15C33306A29C10EC2EF99E6681FF485550D8BFCBA059F82A809B2623",
"amount": "100"
},
"sender": "cosmos1zg52ngxx95tznc4mqn6spvue25q2msgpatzw2925d0ar9vgk6u3s6qszr6",
"receiver": "cosmos1xpgnzjhz650pljhk7f8szu5rjzfj6e2rw8jl3m",
"timeout_height": {
"revision_number": "2",
"revision_height": "13371"
},
"timeout_timestamp": "1640193459068597000"
}
# Create the ICA transaction including the evenual IBC trasfer message
> gaiad tx icamsgauth submit-tx ibc-raw.json --connection-id connection-0 --counterparty-connection-id connection
-0 --from demo -y | jq
{
"height": "0",
"txhash": "0230BD16B8F803C77EE2B773EE987443838DD247CB58601AAE1FE0DDE5EDB8D3",
"codespace": "",
"code": 0,
"data": "",
"raw_log": "[]",
"logs": [],
"info": "",
"gas_wanted": "0",
"gas_used": "0",
"tx": null,
"timestamp": "",
"events": []
}
# HOWEVER, this will fail becauas ibc-transfer messages WERE NOT WHITELISTED in our host chain ica-module genesis as a parameter. Only the delegate and send messages were whitelisted at this point. OOPS!!!
```