Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Graph #63

Closed
Tracked by #13
manuelbarbas opened this issue Dec 26, 2023 · 0 comments
Closed
Tracked by #13

The Graph #63

manuelbarbas opened this issue Dec 26, 2023 · 0 comments

Comments

@manuelbarbas
Copy link
Collaborator

manuelbarbas commented Dec 26, 2023

The Graph

The Graph is a indexing protocol and be used to create subgraphs on SKALE Chain data. You can reach out to the Graph community to request a Graph node, or you may run your own Graph node. These instructions assume you are using a Testnet or Mainnet SKALE Chain and are running your own graph node.

For proper compatibility, you must point a Graph node to a SKALE Archive node.

  1. Install Prerequisites
  • docker
  • docker-compose
  • nodejs
  • npm
  • yarn
  • truffle
  1. Get a SKALE Endpoint
    Get the SKALE chain endpoint assigned to your project here OR use your your own dedicated chain as available.

  2. Configure a Graph Node

git clone https://github.com/graphprotocol/graph-node/
cd graph-node/docker

Then modify the docker-compose.yml file:

ethereum: 'skale:http://host.docker.internal:15000' <1>
...
extra_hosts:
      - "host.docker.internal:host-gateway" <2>

<1> Replace with your SKALE Chain endpoint if not using the SKALE-IMA-SDK.
<2> Add this if using host.docker.internal on a Linux machine.

  1. Start the Graph Node
docker-compose up -d 

To follow the container output, run docker logs docker_graph-node_1 --follow

  1. Prepare the Subgraph test
    In another terminal on the same machine, execute:
git clone https://github.com/skalenetwork/se-integrations/
cd se-integrations/graph-protocol/

Modify the .env file.

SKALE_CHAIN=https://YOURSKALECHAINIP:PORT
ACCOUNT=yourAccountFromMetamask
PRIVATE_KEY=<PRIVATE_KEY>
CONTRACT_ADDRESS=<CONTRACT_ADDRESS> <1>

<1> You will add the contract address in step 7.

  1. Deploy Test contract
npm install
truffle compile
truffle migrate
  1. Add deployed MyToken Contract address to subgraph.yaml
...
dataSources:
  - kind: ethereum/contract
    name: MyToken
    network: skale <1>
    source:
      address: 'CONTRACT_ADDRESS' <2>
      abi: MyToken
...

<1> Change from mainnet to skale to match docker-compose.yml in graph-node.
<2> Replace with deployed contract address.

  1. Add deployed MyToken contract address to .env file

  2. Execute yarn

yarn && yarn codegen
  1. Create local Subgraph
yarn create-local

Expected output:

Created subgraph: skaleToken
Done in 1.04s.

Expected output in Graph-node container:

Dec 17 23:18:38.892 INFO Received subgraph_create request, params: SubgraphCreateParams { name: SubgraphName("skaleToken") }, component: JsonRpcServer
  1. Deploy to Local
yarn deploy-local
  1. Verify graph-node terminal
    Expected output in graph-node container:
graph-node_1  | Apr 23 20:20:58.952 INFO Scanning blocks [0, 0], range_size: 1, subgraph_id: QmbWZiRDpGb95WkA1QH8UM3wsUMZeBmr6ZW2UJaMtGZADB, component: SubgraphInstanceManager > BlockStream
  1. Execute graph test
truffle test --network skale test/myToken.test.forgraph.js

Expected output:

MyToken
...
    ✓ In the test (237ms)


  1 passing (242ms)
  1. Execute token test
truffle test --network skale test/myToken.test.js

Output:

...
MyBalance
  ✓ enough account balance

MyToken
  ✓ deploys a contract
  ✓ has a default token value (1042ms)
  ✓ can update token value (1042ms)


4 passing (3s)
  1. Check your GraphQL:

http://localhost:8000/subgraphs/name/skaleToken/graphql

  1. Perform a test query:
{
  myTokens(orderBy: tokenValue, orderDirection: asc) {
    id
    owner
  }
}

Expected output:

{
  "data": {
    "myTokens": [
      {
        "id": "0x2",
        "owner": "..."
      }...
    ]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant