# How to Build a Subgraph in 5 Minutes 1. Make sure you have the Graph CLI installed globally in your system: `npm i -g @graphprotocol/graph-cli` 2. Run `graph` to verify it is installed 3. Run `graph init` to initialize ``` npx graph init # With this config: # ✔ Protocol · ethereum # ✔ Product for which to initialize · hosted-service # ✔ Subgraph name · alchemy/my-subgraph # ✔ Directory to create the subgraph in · my-subgraph # ✔ Ethereum network · mainnet # ✔ Contract address · 0x2E645469f354BB4F5c8a05B3b30A929361cf77eC # ✔ Fetching ABI from Etherscan # ✔ Fetching Start Block # ✔ Start Block · 6175244 # ✔ Contract Name · GravatarRegistry # ✔ Index contract events as entities (Y/n) · true ``` ## After CLI wizard 1. Now we need to fill in three main files before everything works properly: - the `schema.graphql` - the `subgraph.yaml` (aka: manifest file) - the `.ts` file inside `/src` that was auto-generated by the wizard process > Notice: the wizard process creates a `/abis` folder and automatically populates the contract abi, which you'll need (`BAYC.json` file) File breakdown: - `subgraph.graphql`: You can see things like the name of the contract, the contract address, start block, entities defined in the schema (?) and the event handlers (?) - out of the wizard process, this doesn't fit our need - we need - `schema.graphql`: GraphQL syntax file that contains entities (DEFINE ENTITIES) ## After 2 files are good 1. Now that we have both of these files defined, let's define the event handler itself. That will take place in the `/src.bayc.ts` file: ## After all files good 1. run `graph codegen` so that all of the info we inputted in the 3 files are used to build all requirements for subgraph You will then see your terminal output: `Types generated successfully` (EXPLAIN?) ![see](https://hackmd.io/_uploads/HyfgSHFMT.png) 2. Run `graph build` Your terminal will output: ![success](https://hackmd.io/_uploads/ry4EdKtGa.png) ## Final step and connectiont to Alchemy Subgraphs (Satsuma) 1. Run: ```bash graph deploy pudgy-penguins-transfers \ --version-label v0.0.1-new-version \ --node https://subgraphs.alchemy.com/api/subgraphs/deploy \ --deploy-key vxndDhH8s5CSD \ --ipfs https://ipfs.satsuma.xyz ``` Questions: 1. Is `deploy-key` always the same? 2. Do I need a special Alchemy API key for this? 3. Anything else I should know about this command?