A simple subgraph for tracking a single erc721 smart contract.
Link to see what this is like live: Here
Make sure you have the latest versions of the following installed:
- Rust Link to install
- Graph-cli Link to install
- substreams-cli Link to install
pub const ADDRESS: &str = "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D";
const START_BLOCK: u64 = 13090020;
- name: map_transfers
kind: map
initialBlock: 13090020
inputs:
- source: sf.ethereum.type.v2.Block
output:
type: proto:schema.Transfers
We now need to recompile our WASM binary with the new changes we made to the rust files.
We need to bundle the protobuf definitions and the WASM binary into a single file. This is what we will deploy the subgraph.
This endpoint will change if you are deploying to the hosted service or decentralized network. But replace this with the command that is appropriate for your setup.
type Collection @entity {
id: ID! #address of the contract
tokens: [Token!]! @derivedFrom(field: "collection") #tokens that belong to the contractA
}
type Transfer @entity {
id: ID! #tx hash of the transfer
from: Account! #account that sent the transfer
to: Account! #account that received the transfer
tokenId: Token! #token that was transferred
}
type Approval @entity {
id: ID! #tx hash of the approval
owner: Account!
approved: Account!
tokenId: Token!
}
type Token @entity {
id: ID! #token id
collection: Collection! #contract that the token belongs to
owner: Account! #account that owns the token
transfers: [Transfer!]! @derivedFrom(field: "tokenId") #transfers that the token has been involved in
approvals: [Approval!]! @derivedFrom(field: "tokenId")
}
type Account @entity {
id: ID! #Address of the account
tokens: [Token!]! @derivedFrom(field: "owner") #tokens that the account owns
}