Charged Particles
  • What is Charged Particles
  • GETTING STARTED
    • Quick Start
  • CHARGED PARTICLES PROTOCOL
    • Protocol Overview
      • How It Works
      • Current Status
      • Protocol Revenue
      • Protocol Features
    • Why Use Charged Particles?
      • NFT Platforms And How They Differ
      • Charged Particles NFTs - What Are They?
    • How to Use Charged Particles
      • Minting an NFT
      • Energizing an NFT
      • Manage an NFT
      • Using A Test Network
      • Migrating Particles from V1 to V2
    • Developer Docs
      • System Overview
      • Quickstart
        • Read and Write to Contracts
        • Read from the Subgraph
        • Get Kovan ETH + ERC20s
        • VSCode Node.js Typescript Debugging
      • Smart Contracts
        • V2
          • Charged Particles Contract (V2)
          • Charged Settings Contract (V2)
          • Charged State Contract (V2)
          • ProtonB Contract
        • V1
          • Charged Particles Contract
          • Charged Settings Contract
          • Charged State Contract
          • Proton Contract
        • Error Codes
      • Protocol Subgraph
    • IONX
      • IONX Token Addresses
      • IONX Rewards
    • Web3 Packs
    • Liquidity Mining
      • Base Reward Program
      • Leptons
    • Protocol Governance
      • Governance Process
      • Creating a Proposal
      • Voting
      • Delegating Votes
    • Projects + Use Cases
    • Allowlist Application
    • Team
    • Guilds
    • Roadmap
    • Hackathons
      • Hackathon Ideas
      • Previous Hackathons
    • Dune Analytics
  • SDK
    • Charged Particles SDK Overview
    • Quick Start
    • API
    • Advanced Use
    • Types
    • Common Issues / FAQ
    • Common Terminology
  • RESOURCES
    • Hiring!
      • Full-stack/Back-end Web3 Engineer
      • Create Your Own Position
    • Glossary of Terms
    • FAQs
      • Protocol and app.charged.fi
      • Governance
      • Other
      • How to report a bug
    • External Contracts Allowlisted
    • Audits
    • Legal
      • Beta End User License Agreement (EULA)
      • Privacy Policy
      • Policies & Terms of Service
    • Media Kit
  • Additional Resources
    • Discord
    • Telegram
    • Twitter
    • Medium
    • Github
    • LinkedIn
    • Instagram
    • TikTok
Powered by GitBook
On this page
  • Read Only: The subgraph
  • Sample Interaction using Node.js

Was this helpful?

  1. CHARGED PARTICLES PROTOCOL
  2. Developer Docs
  3. Quickstart

Read from the Subgraph

Read most data from the blockchain, as well as some additional higher-level fields without querying contracts themselves

PreviousRead and Write to ContractsNextGet Kovan ETH + ERC20s

Last updated 3 years ago

Was this helpful?

Read Only: The subgraph

Most of the data from the blockchain, and additional higher level fields are readable from the ().

Kovan:

We recommend digging into the Schema yourselves to figure out what is available to query.

Please also pay attention to some example queries we provide on the top left

Sample Interaction using Node.js

The sample is in Typescript using ts-node but you can use CommonJs require as well.

npm install -D ts-node graphql-request graphql

You might also need a tsconfig.json at the root of your project with

{ "compilerOptions": { "moduleResolution": "node" } }
getFirst20Protons.ts
import { request, gql } from 'graphql-request';

const query = gql`
{
   universes {
     protonToken {
       tokens(first:20) {
         name,
         tokenId,
         id
         creator,
         owner,
         salePrice,
         lastSalePrice,
       }
     }
   }
 }`
 
 const doGraphRequest = (endpoint, query, variables={}) => new Promise((resolve, reject) => {
  request(endpoint, query, variables)
    .then((data) => resolve(data))
    .catch(err => reject(err));
});

async function run() {
  const endpoint = 'https://api.thegraph.com/subgraphs/name/charged-particles/kovan-universe';
  const res: any = await doGraphRequest(endpoint, query);
  const { protonToken } = res.universes[0];
  console.log(protonToken);
}

run();
# Run it
./node_modules/.bin/ts-node getFirst20Protons.ts

/* Outputs:


{
  tokens: [
    {
      creator: '0xb14d1a16f30db670097da86d4008640c6ccc2b76',
      id: '0xd4f7389297d9cea850777ea6ccbd7db5817a12b2-1',
      lastSalePrice: null,
      name: 'ETH on Mars',
      owner: '0xb14d1a16f30db670097da86d4008640c6ccc2b76',
      salePrice: '69000000000000000000',
      tokenId: '1'
    },
    {
      creator: '0x11113c2fba9ae08d7d16c817f03de51f29117db2',
      id: '0xd4f7389297d9cea850777ea6ccbd7db5817a12b2-10',
      lastSalePrice: null,
      name: 'ha',
      owner: '0x11113c2fba9ae08d7d16c817f03de51f29117db2',
      salePrice: '0',
      tokenId: '10'
    },
    ...
*/

Almost all the information available from the contracts is available somewhere on the subgraph, besides the current accrued interest (ie: how much my DAI at 12% APY in my ProtonNFT made me) which is currently available only by currentParticleCharge(address,uint256,string,address)(uint256)

graphql-request is the most minimal and simplest to use GraphQL client. It's perfect for small scripts or simple apps. But it doesn't allow you to listen for changes for this, please use something like .

until is resolved.

If you want access to and be able to set breakpoints check Debugging so you can use debugger; statement.

contract querying
apollo-client
https://github.com/prisma-labs/graphql-request/issues/214
subgraph
quick video
https://thegraph.com/explorer/subgraph/charged-particles/kovan-universe?query=Protons%20NFTs
VSCode debugger