diff --git a/.gitignore b/.gitignore index 74c82d3..112ab68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ node_modules generated -build \ No newline at end of file +build +.git +.gitignore +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 221c1e8..2d53eef 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ ## Slides [![Top Slide](./slide1.png)](https://docs.google.com/presentation/d/1-jZd4Sp83YW6r2KhXYeU4sOlKdcmp0LVi3WF1VAkxzk/edit?usp=sharing) +[![Top Slide](./slide1how3marcus.png)](https://docs.google.com/presentation/d/1MMgXx_GrufU_o0JdFhEmqpxRKAFyMAxSdYyGO-9kfnU/edit?usp=sharing) ## Cheatsheet @@ -10,35 +11,37 @@ ## Good subgraphs: -- [Messari Subgraphs](https://subgraphs.messari.io) -- [EIP-721 (NFTS on The Graph Network)](https://thegraph.com/explorer/subgraph?id=AVZ1dGwmRGKsbDAbwvxNmXzeEkD48voB3LfGqj5w7FUS&view=Overview) -- [Lens Protocol](https://thegraph.com/hosted-service/subgraph/anudit/lens-protocol) -- [Unlock Protocol on The Graph Network](https://thegraph.com/explorer/subgraph?id=8u7KcVRxjtTDRgEJup3UuPJk6YoRDTHNpSMk5BEpdw42&view=Overview) -- [Open Sea Subgraph](https://thegraph.com/hosted-service/subgraph/protofire/opensea-wyvern-exchange-subgraph) -- [LiNEAR](https://thegraph.com/hosted-service/subgraph/linear-protocol/linear) -- [Aave Gotchi](https://thegraph.com/hosted-service/subgraph/aavegotchi/aavegotchi-core-matic) -- [Tellor](https://thegraph.com/hosted-service/subgraph/tellor-io/tellorxoraclemainhgraph) -- [Live Peer](https://thegraph.com/hosted-service/subgraph/livepeer/arbitrum-one) -- [ENS](https://thegraph.com/hosted-service/subgraph/ensdomains/ens) -- [UMA on The Graph Network](https://thegraph.com/explorer/subgraph?id=41LCrgtCNBQyDiVVyZEuPxbvkBH9BxxLU3nEZst77V8o&view=Overview) +- [Messari Subgraphs](https://subgraphs.messari.io) +- [EIP-721 (NFTS on The Graph Network)](https://thegraph.com/explorer/subgraph?id=AVZ1dGwmRGKsbDAbwvxNmXzeEkD48voB3LfGqj5w7FUS&view=Overview) +- [Lens Protocol](https://thegraph.com/hosted-service/subgraph/anudit/lens-protocol) +- [Unlock Protocol on The Graph Network](https://thegraph.com/explorer/subgraph?id=8u7KcVRxjtTDRgEJup3UuPJk6YoRDTHNpSMk5BEpdw42&view=Overview) +- [Open Sea Subgraph](https://thegraph.com/hosted-service/subgraph/protofire/opensea-wyvern-exchange-subgraph) +- [LiNEAR](https://thegraph.com/hosted-service/subgraph/linear-protocol/linear) +- [Aave Gotchi](https://thegraph.com/hosted-service/subgraph/aavegotchi/aavegotchi-core-matic) +- [Tellor](https://thegraph.com/hosted-service/subgraph/tellor-io/tellorxoraclemainhgraph) +- [Live Peer](https://thegraph.com/hosted-service/subgraph/livepeer/arbitrum-one) +- [ENS](https://thegraph.com/hosted-service/subgraph/ensdomains/ens) +- [UMA on The Graph Network](https://thegraph.com/explorer/subgraph?id=41LCrgtCNBQyDiVVyZEuPxbvkBH9BxxLU3nEZst77V8o&view=Overview) ## Info -- [Contract to index](https://etherscan.io/address/0xc2c747e0f7004f9e8817db2ca4997657a7746928) -- [Google Slides for NFT Subgraph Development Workshop](https://docs.google.com/presentation/d/1-jZd4Sp83YW6r2KhXYeU4sOlKdcmp0LVi3WF1VAkxzk/edit?usp=sharing) -- Questions: **[twitter.com/schmid_si](https://twitter.com/schmid_si)** +- [Contract to index](https://etherscan.io/address/0xc2c747e0f7004f9e8817db2ca4997657a7746928) +- [Google Slides for NFT Subgraph Development Workshop](https://docs.google.com/presentation/d/1-jZd4Sp83YW6r2KhXYeU4sOlKdcmp0LVi3WF1VAkxzk/edit?usp=sharing) +- Questions: + - **[twitter.com/schmid_si](https://twitter.com/schmid_si)** + - **[twitter.com/Marcus_Rein\_](https://twitter.com/Marcus_Rein_)** ## Prerequisites -- Install graph-cli: `yarn global add @graphprotocol/graph-cli` +- Install graph-cli: `yarn global add @graphprotocol/graph-cli` ## First Steps -- [Find the contract on Etherscan](https://etherscan.io/address/0xc2c747e0f7004f9e8817db2ca4997657a7746928) -- [Find the contract creation transaction for startBlock](https://etherscan.io/tx/0xe9e60dc12e1a7bc545aa497bc494f5f54ce81da06de4f6fef50459816218e66b) -- Download the ABI +- [Find the contract on Etherscan](https://etherscan.io/address/0xc2c747e0f7004f9e8817db2ca4997657a7746928) +- [Find the contract creation transaction for startBlock](https://etherscan.io/tx/0xe9e60dc12e1a7bc545aa497bc494f5f54ce81da06de4f6fef50459816218e66b) +- Download the ABI -- Run this command to initialise the subgraph with events: +- Run this command to initialise the subgraph with events: ```bash graph init \ @@ -51,8 +54,8 @@ graph init \ hashmasks hashmasks-subgraph ``` -- Inspect the source -- Change startblock: +- Inspect the source +- Change startblock: ``` source: @@ -63,18 +66,18 @@ source: – Create new subgraph on [Subgraph Studio](https://thegraph.com/studio/) named "Hashmasks" -- `graph auth --studio ...` -- `yarn deploy` +- `graph auth --studio ...` +- `yarn deploy` ## Remove unused Entities and Events ```graphql # schema.graphql type Transfer @entity { - id: ID! - from: Bytes! # address - to: Bytes! # address - tokenId: BigInt! # uint256 + id: ID! + from: Bytes! # address + to: Bytes! # address + tokenId: BigInt! # uint256 } ``` @@ -84,12 +87,12 @@ Make them immutable for performance improvements ```graphql type Transfer @entity(immutable: true) { - id: ID! - from: Bytes! # address - to: Bytes! # address - tokenId: BigInt! # uint256 - timestamp: BigInt! - blockNumber: BigInt! + id: ID! + from: Bytes! # address + to: Bytes! # address + tokenId: BigInt! # uint256 + timestamp: BigInt! + blockNumber: BigInt! } ``` @@ -97,65 +100,65 @@ Use `event.transaction.hash.toHex() + "-" + event.logIndex.toString()` as the id ```typescript export function handleTransfer(event: TransferEvent): void { - let entity = new Transfer( - event.transaction.hash.toHex() + "-" + event.logIndex.toString() - ); - entity.blockNumber = event.block.number; - entity.timestamp = event.block.timestamp; - entity.from = event.params.from; - entity.to = event.params.to; - entity.tokenId = event.params.tokenId; - entity.save(); + let entity = new Transfer( + event.transaction.hash.toHex() + "-" + event.logIndex.toString() + ); + entity.blockNumber = event.block.number; + entity.timestamp = event.block.timestamp; + entity.from = event.params.from; + entity.to = event.params.to; + entity.tokenId = event.params.tokenId; + entity.save(); } ``` ### Store logical entities -- Identify the important entities: Token, Owner, Contract -- Link them +- Identify the important entities: Token, Owner, Contract +- Link them ```graphql type Transfer @entity(immutable: true) { - id: ID! - from: Owner! - to: Owner! - token: Token! - timestamp: BigInt! - blockNumber: BigInt! + id: ID! + from: Owner! + to: Owner! + token: Token! + timestamp: BigInt! + blockNumber: BigInt! } type Token @entity { - id: ID! - owner: Owner - uri: String - transfers: [Transfer!]! @derivedFrom(field: "token") - contract: Contract + id: ID! + owner: Owner + uri: String + transfers: [Transfer!]! @derivedFrom(field: "token") + contract: Contract } type Owner @entity { - id: Bytes! # Use bytes as ID - ownedTokens: [Token!]! @derivedFrom(field: "owner") - balance: BigInt + id: Bytes! # Use bytes as ID + ownedTokens: [Token!]! @derivedFrom(field: "owner") + balance: BigInt } type Contract @entity { - id: ID! - name: String - symbol: String - totalSupply: BigInt - mintedTokens: [Token!]! @derivedFrom(field: "contract") + id: ID! + name: String + symbol: String + totalSupply: BigInt + mintedTokens: [Token!]! @derivedFrom(field: "contract") } ``` ## Other resources -- https://github.com/schmidsi/hackathon-starterkit -- https://github.com/scaffold-eth/scaffold-eth#-scaffold-eth -- https://soulbound.xyz -- https://github.com/Developer-DAO/resources -- https://dev.to/dabit3/the-complete-guide-to-full-stack-ethereum-development-3j13 -- https://github.com/itsjerryokolo/CryptoPunks -- https://github.com/dabit3/building-a-subgraph-workshop -- https://thegraph.com/docs/developer/quick-start -- https://thegraph.com/discord -- https://protean-labs.github.io/subgrounds/ +- https://github.com/schmidsi/hackathon-starterkit +- https://github.com/scaffold-eth/scaffold-eth#-scaffold-eth +- https://soulbound.xyz +- https://github.com/Developer-DAO/resources +- https://dev.to/dabit3/the-complete-guide-to-full-stack-ethereum-development-3j13 +- https://github.com/itsjerryokolo/CryptoPunks +- https://github.com/dabit3/building-a-subgraph-workshop +- https://thegraph.com/docs/developer/quick-start +- https://thegraph.com/discord +- https://protean-labs.github.io/subgrounds/ diff --git a/slide1how3marcus.png b/slide1how3marcus.png new file mode 100644 index 0000000..b250146 Binary files /dev/null and b/slide1how3marcus.png differ