This subgraph template enables developers to track balances and approvals for ERC20 tokens.
Example Subgraph is hosted at: https://thegraph.com/explorer/subgraph/andreujuanc/erc20-allowances. You can also try below queries in the playground.
# copy env and adjust its content
# you can get an access token from https://thegraph.com/explorer/dashboard
cp .env.test .env
# edit config/mainnet.json file and add your desired ERC20 contract & corresponding start block for indexing
yarn
# creates a subgraph.yml file with desired contract and start block information specified in config file
yarn prepare:mainnet
yarn codegen
yarn build
yarn deploy
Here are a few examples of types of queries that can be run:
{
assets(first: 1) {
id
name
symbol
decimals
}
}
{
user(id: "0x574300348823910c6f82a6a3d859791b9cd0310e") {
balance
}
}
{
user(
id: "0x574300348823910c6f82a6a3d859791b9cd0310e",
block: {number: 12459565}
) {
balance
}
}
{
user(id: "0x0000000000007f150bd6f54c40a34d7c3d5e9f56") {
id
balance
approvals(where: {owner: "0x0000000000007f150bd6f54c40a34d7c3d5e9f56"}) {
id
count
value
}
}
}