2022-12-22 06:03:39 +00:00
# ERC20 Watcher
2023-01-10 00:44:39 +00:00
Instructions to deploy a local ERC20 watcher stack (core + watcher) for demonstration and testing purposes using [stack orchestrator ](/README.md#install )
2022-12-22 06:03:39 +00:00
## Setup
2023-01-10 00:44:39 +00:00
Clone required repositories:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
laconic-so setup-repositories --include cerc-io/go-ethereum,cerc-io/ipld-eth-db,cerc-io/ipld-eth-server,cerc-io/watcher-ts
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Build the core and watcher container images:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
laconic-so build-containers --include cerc/go-ethereum,cerc/go-ethereum-foundry,cerc/ipld-eth-db,cerc/ipld-eth-server,cerc/watcher-erc20
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
This should create the required docker images in the local image registry.
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Deploy the stack:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
laconic-so deploy-system --include ipld-eth-db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 up
```
2022-12-22 06:03:39 +00:00
## Demo
2023-01-10 00:44:39 +00:00
Find the watcher container's id using `docker ps` and export it for later use:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
export CONTAINER_ID=< CONTAINER_ID >
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Deploy an ERC20 token:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
docker exec $CONTAINER_ID yarn token:deploy:docker
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Export the address of the deployed token to a shell variable for later use:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
export TOKEN_ADDRESS=< TOKEN_ADDRESS >
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Open `http://localhost:3002/graphql` (GraphQL Playground) in a browser window
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Connect MetaMask to `http://localhost:8545` (with chain ID `99` )
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Add the deployed token as an asset in MetaMask and check that the initial balance is zero
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Export your MetaMask account (second account) address to a shell variable for later use:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
export RECIPIENT_ADDRESS=< RECIPIENT_ADDRESS >
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
To get the primary account's address, run:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
docker exec $CONTAINER_ID yarn account:docker
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
To get the current block hash at any time, run:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
docker exec $CONTAINER_ID yarn block:latest:docker
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Fire a GQL query in the playground to get the name, symbol and total supply of the deployed token:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```graphql
query {
name(
blockHash: "LATEST_BLOCK_HASH"
token: "TOKEN_ADDRESS"
) {
value
proof {
data
2022-12-22 06:03:39 +00:00
}
2023-01-10 00:44:39 +00:00
}
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
symbol(
blockHash: "LATEST_BLOCK_HASH"
token: "TOKEN_ADDRESS"
) {
value
proof {
data
2022-12-22 06:03:39 +00:00
}
2023-01-10 00:44:39 +00:00
}
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
totalSupply(
blockHash: "LATEST_BLOCK_HASH"
token: "TOKEN_ADDRESS"
) {
value
proof {
data
}
}
}
```
Fire the following query to get balances for the primary and the recipient account at the latest block hash:
```graphql
query {
fromBalanceOf: balanceOf(
2022-12-22 06:03:39 +00:00
blockHash: "LATEST_BLOCK_HASH"
2023-01-10 00:44:39 +00:00
token: "TOKEN_ADDRESS",
# primary account having all the balance initially
owner: "PRIMARY_ADDRESS"
2022-12-22 06:03:39 +00:00
) {
2023-01-10 00:44:39 +00:00
value
proof {
data
2022-12-22 06:03:39 +00:00
}
}
2023-01-10 00:44:39 +00:00
toBalanceOf: balanceOf(
blockHash: "LATEST_BLOCK_HASH"
token: "TOKEN_ADDRESS",
owner: "RECIPIENT_ADDRESS"
) {
value
proof {
data
2022-12-22 06:03:39 +00:00
}
}
2023-01-10 00:44:39 +00:00
}
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
- The initial balance for the primary account should be `1000000000000000000000`
- The initial balance for the recipient should be `0`
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Transfer tokens to the recipient account:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
docker exec $CONTAINER_ID yarn token:transfer:docker --token $TOKEN_ADDRESS --to $RECIPIENT_ADDRESS --amount 100
```
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Fire the above GQL query again with the latest block hash to get updated balances for the primary (`from`) and the recipient (`to`) account:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
- The balance for the primary account should be reduced by the transfer amount (`100`)
- The balance for the recipient account should be equal to the transfer amount (`100`)
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
Transfer funds between different accounts using MetaMask and use the playground to query the balance before and after the transfer.
2022-12-22 06:03:39 +00:00
## Clean up
2023-01-10 00:44:39 +00:00
To stop all the services running in background run:
2022-12-22 06:03:39 +00:00
2023-01-10 00:44:39 +00:00
```bash
laconic-so deploy-system --include ipld-eth-db,go-ethereum-foundry,ipld-eth-server,watcher-erc20 down
```