# Starport Consumer
**Versions**
- go 1.16
- Starport v0.16.2
**Note:** This version is communicating with BandChain Laozi Testnet 2
- This chain takes an oracle input as a list of symbols and a price multiplier and an output as a list of prices for the given symbols, but some oracle scripts have different formats of inputs and outputs. Thus this is not expected to work with all oracle scripts.
- This tutorial is using BandChain's go-relayer (forked from the official go-relayer) because we have implemented a feature to query packets from EndBlock events.
## Setup the Consumer chain
1. Clone the repository
```bash
cd ~
git clone https://github.com/bandprotocol/starport-consumer.git
cd starport-consumer
```
2. Start the chain
```bash
starport serve
```
3. Add `user` key with its mnemonic from `config.yml`
```bash
consumerd keys add user --recover
```
## Connect to BandChain via Relayer
- The relayer config for this tutorial has gas price equal to 0, and the account for the mnemonic on step(3) of this section is already created on BandChain Laozi testnet 2. Hence, you do not have to worry about creating a relayer account on Band side.
- But if you wish to create an account and fund it, you can do so as follows.
```bash
export FAUCET_URL=https://laozi-testnet2.bandchain.org/faucet/request
export BAND_ADDR={BAND_ADDR_GENERATED_FROM_RELAYER}
curl --location --request POST "${FAUCET_URL}" \
--header 'Content-Type: application/json' \
--data-raw "{
\"address\": \"$BAND_ADDR\"
}"
```
---
1. Initialize the relayer's configuration.
```bash
cd ~
git clone https://github.com/bandprotocol/relayer.git
cd relayer
git checkout starport-consumer
rly config init
```
2. Add chain configs
```bash
rly chains add -f configs/band/chains/bandchain.json
rly chains add -f configs/band/chains/consumer.json
```
3. Import created keys for the relayer to use when signing and relaying transaction
```bash
export MNEMONIC="dose scale monkey unique flag print problem abstract gold hole quiz oxygen train misery easily sail divert impose fatigue desert length act liar firm"
rly keys restore band-laozi-testnet2 bandkey "$MNEMONIC" --coin-type 494
rly keys restore starportconsumer conskey "$MNEMONIC"
```
4. Ensure both relayer accounts are funded by querying each.
```bash
rly q balance band-laozi-testnet2
rly q balance starportconsumer
```
5. Now we are ready to initiaze the light clients on each network.
```bash
rly light init band-laozi-testnet2 -f
rly light init starportconsumer -f
```
6. Next, we add a config path to the relayer and name it `demo`.
```bash
rly paths add band-laozi-testnet2 starportconsumer demo --file configs/band/paths/demo.json
```
7. Now we are ready to create a connection and a channel between two chains. This command will return you the names of the channel of oracle module in BandChain and the channel of a module in your chain that you wish to communicate with the oracle module.
```bash
rly tx link demo -o 3s
```
After running the command, the last line of outputs will be as follows
```bash
★ Channel created: [band-laozi-testnet2]chan{bandchain_channel-id}port{oracle} -> [starportconsumer]chan{your_channel-id}port{your_port}
```
**NOTE:** You will need `{your_channel-id}` which is a channel ID on your chain side in order to create a new oracle request message and `{bandchain_channel-id}` which is a channel ID on BandChain side to check your pool address.
8. Finally, we can start the relayer with the connection and channel created in step (12). The relayer will periodically update the clients and listen for IBC messages to relay.
```bash
rly start demo
```
## Send Message
- Currently there is no data source fee when requesting data on Laozi testnet 2, so request-key can be any arbitrary string. Also currently there is no easy way to fund a pool account according to the request key without running Band node, so we are opting out a step to fund this pool account for now.
- For the purpose of this tutorial, we are using oracle script [#37](https://laozi-testnet2.cosmoscan.io/oracle-script/37#bridge) .
---
1. We can send a request to BandChain Laozi testnet 2 using the following CLI command.
```bash
starport-consumerd tx consuming RequestData 37 4 3 --channel channel-0 --symbols "BTC,ETH" --multiplier 1000000 --fee-limit 30uband --request-key "random_string" --prepare-gas 200000 --execute-gas 200000 --from user
```
2. Once you receive an acknowledgement back from BandChain you can query your request ID as follows.
```bash
starport-consumerd query consuming latest-request
```
Then you will see something like
```bash
request_id: "{REQUEST_ID}"
```
3. Once BandChain relays the result for this request, you use a query command to find the prices/rates for BTC and ETH multipled with the multiplier specified in the request command from step(1) of this section.
```bash
starport-consumerd query consuming result REQUEST_ID
```