A simple subgraph for tracking a single ERC1155 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 = "0x73DA73EF3a6982109c4d5BDb0dB9dd3E3783f313";
const START_BLOCK: u64 = 12129118;
- name: map_transfers
kind: map
initialBlock: 12129118
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
}
enum TransferType {
SINGLE,
BATCH
}
type Transfer @entity {
id: ID! # {tx-hash}-{log-index}
from: Account! #account that sent the transfer
to: Account! #account that received the transfer
operator: Account! #account that sent the transfer (msg.sender)
tokenIds: [Token!]! #token ids that were transferred
transferType: TransferType! #single or batch transfer
}
type ApprovalForAll @entity {
id: ID! #tx hash of the approval
owner: Account!
operator: Account!
approved: Boolean!
}
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: "tokenIds") #transfers that the token has been involved in
uri: String #uri of the token
}
type Account @entity {
id: ID! #Address of the account
tokens: [Token!]! @derivedFrom(field: "owner") #tokens that the account owns
}