A SportX subgraph for The Graph. SportX provides a platform for sports betting on Ethereum.
A Graph Node can run multiple subgraphs, and in this case it can have a subgraph for Ropsten, Mainnet and Kovan. The subgraph ingests event data by calling to Infura through http. It can also connect to any geth node or parity node that accepts RPC calls. Fast synced geth nodes work. To use parity, the --no-warp
flag must be used. Setting up a local Ethereum node is more reliable and faster, but Infura is the easiest way to get started.
This subgraph has three types of files which tell the Graph Node to ingest events from specific contracts. They are:
- The subgraph manifest (subgraph.yaml)
- A GraphQL schema (schema.graphql)
- Mapping scripts (ExchangeV1.ts, ExchangeV2.ts)
This repository has these files created and ready to compile, so a user can start this subgraph on their own. The only thing that needs to be edited is the contract addresses in the subgraph.yaml
file to change between Kovan, Ropsten or Mainnet.
We have provided a quick guide on how to start up the SportX-Subgraph graph node. If these steps aren't descriptive enough, the getting started guide has in depth details on running a subgraph.
- Install IPFS and run
ipfs init
followed byipfs daemon
- Install PostgreSQL and run
initdb -D .postgres
followed bypg_ctl -D .postgres start
andcreatedb graph-node-mainnet
(note this db name is used in the commands below for the mainnet examples) - If using Ubuntu, you may need to install additional packages:
sudo apt-get install -y clang libpq-dev libssl-dev pkg-config
- Clone this repository, and run the following:
yarn
yarn codegen
- Clone https://github.com/graphprotocol/graph-node from master and
cargo build
(this might take a while) - a) Now that all the dependencies are running, you can run the following command to connect to Infura Mainnet (it may take a few minutes for Rust to compile). Password might be optional, it depends on your postrgres setup:
cargo run -p graph-node --release -- \
--postgres-url postgresql://USERNAME:[PASSWORD]@localhost:5432/graph-node-mainnet \
--ipfs 127.0.0.1:5001 \
--ethereum-rpc mainnet-infura:https://mainnet.infura.io --debug
- b) Or Mainnet with a Local Ethereum node. This is very common if you are working with brand new contracts, and you have deployed them to a testnet environment like ganache (note that ganache commonly uses port 9545 rather than 8545):
cargo run -p graph-node --release -- \
--postgres-url postgresql://USERNAME:[PASSWORD]@localhost:5432/graph-node-mainnet \
--ipfs 127.0.0.1:5001 \
--ethereum-rpc mainnet-local:http://127.0.0.1:8545
- c) Or Infura Kovan (NOTE: Infura Kovan is not reliable right now, we get inconsistent results returned. If Kovan data is needed, it is suggested to run your own Kovan node)
cargo run -p graph-node --release -- \
--postgres-url postgresql://USERNAME:[PASSWORD]@localhost:5432/graph-node-testnet \
--ipfs 127.0.0.1:5001
--ethereum-rpc kovan-infura:https://kovan.infura.io
- d) Or a Kovan local node which was started with
parity --chain=kovan --no-warp --jsonrpc-apis="all"
:
cargo run -p graph-node --release -- \
--postgres-url postgresql://USERNAME:[PASSWORD]@localhost:5432/graph-node-testnet \
--ipfs 127.0.0.1:5001 \
--ethereum-rpc kovan-local:http://127.0.0.1:8545
-
e) You can also connect to ropsten, just follow the syntax that was used with the kovan example.
-
Now create the subgraph locally on The Graph Node with
yarn create-local
. On The Graph Hosted service, creating the subgraph is done in the web broswer. -
Now deploy the SportX subgraph to The Graph Node with
yarn deploy --debug
. You should see a lot of blocks being skipped in thegraph-node
terminal, and then it will start ingesting events from the moment the contracts were uploaded to the network.
Now that you have subgraph is running you may open a Graphiql browser at 127.0.0.1:8000
and get started with querying.
This subgraph is not yet on The Graph Explorer. To understand how deploying to the hosted service works, check out the Deploying Instructions in the official documentation. The most important part of deploying to the hosted service is ensuring that the npm script for deploy
is updated to the correct name that you want to deploy with.
Below are a few ways to show how to query the SportX-Subgraph for data.
The query below shows all the information that is possible to query, but is limited to the first 5 instances. There are many other filtering options that can be used, just check out the querying api.
{
orders(first: 5){
id
maker
market {
id
baseToken
title
outcomeOne
outcomeTwo
outcomeVoid
referenceUrl
registered
}
taker
newFilledAmount
totalBetSize
percentageOdds
expiry
oracleFee
relayerMakerFee
relayerTakerFee
salt
relayer
isMakerBettingOutcomeOne
takerAmount
takerEscrow
potSize
makerOracleFee
takerOracleFee
}
}
The command above can be copy pasted into the Graphiql interface in your browser at 127.0.0.1:8000
or in the query playground on the hosted-service.