This web application shows several informations about Cartesi Proof of Stake:
- node public address
- node balance
- current node owner
- action to claim a node through metamask
- action to release a node from the current owner
This is a Next.js application which uses smart contracts deployed by the pos-dlib and staking-pool projects. In order to run the application locally you need to:
- Run a localhost hardhat node with all contracts deployed
- Run a local graph node reading from the local hardhat node and deploy the subgraph
- Run the application
- Open application in browser and switch to a local network in MetaMask
This can be done from the staking-pool project by running:
$ cd staking-pool
$ yarn start --export ../explorer/src/services/contracts/localhost.json
This will run a local hardhat node running at http://127.0.0.1:8545/ and deploy all smart contracts. Among the contracts are:
- CartesiToken: the CTSI token contract. Minter is the first account, and holds 1B tokens initially.
- StakingImpl: the staking contract.
- WorkerManagerAuthManagerImpl: used to hire worker nodes.
- PoS: proof of stake smart contract, holds the chains. Starts with no chain created.
- StakingPoolFactoryImpl: factory of new staking pools.
The application uses a subgraph powered by thegraph to consolidate blockchain information and serve using a GraphQL endpoint.
- Clone the graph node from GitHub.
- Copy the file
docker/docker-compose.yml
todocker/docker-compose-localhost.yml
- Modify line 20 to
ethereum: 'localhost:http://host.docker.internal:8545/'
- Modify line 27 to
./data_localhost/ipfs:/data/ipfs
- Modify line 38 to
./data_localhost/postgres:/var/lib/postgresql/data
Then run:
$ cd docker
$ docker-compose -f docker-compose-localhost.yml up
Every time you reset your local hardhat node you will need to delete the data_localhost
folder that is created by the docker-compose
command before running it again.
The next step is the deploy the subgraph to the local graph node.
Checkout the subgraph project from GitHub.
Then yarn link the project to the local staking-pool
project by running yarn link
at the staking-pool
project and than yarn link @cartesi/staking-pool
at the subgraph
project.
Then run the following commands:
$ yarn prepare:localhost
$ yarn create:localhost
$ yarn deploy:localhost
There are two files in the explorer project the.env.development
and .env.production
. They set default values e.g. config for Unleash that is our feature-flag provider. You can create a file called .env.development.local
that is gitignored so you can add your secrets there.
The next step is to create an account on Infura. Create a project so you can have access to a PROJECT ID.
On your .env.development.local
set the following var:
- NEXT_PUBLIC_PROJECT_ID=your_project_id_goes_here
You can read more about nextJS env vars here
Simply run:
$ yarn dev
Open the application in your browser at http://localhost:3000 Open MetaMask and switch to a network configured to the url http://localhost:8545 and Chain ID 31337.