Giter Site home page Giter Site logo

parketh / arbitrum-proposal-alerts-tally Goto Github PK

View Code? Open in Web Editor NEW

This project forked from withtally/tally-api-quickstart

0.0 0.0 0.0 175 KB

A cloneable repository for getting started with the new Tally API.

JavaScript 19.93% TypeScript 76.86% CSS 2.80% HTML 0.42%

arbitrum-proposal-alerts-tally's Introduction

tally-api-quickstart

A cloneable repository for getting started with the new Tally API.

To clone the repository:

git clone https://github.com/withtally/tally-api-quickstart.git

To set env variables:

copy the .env.template file into a .env file at the root of your directory

create a Tally account at https://tally.xyz and when signed in, generate your API Key at https://www.tally.xyz/user/settings

add your API KEY as VITE_TALLY_API_KEY={ your_tally_api_key }

To run the application:

npm install

npm run dev

Querying the Tally API:

the quickstart application renders three example tables: governors, proposals and polygon proposals

the first table queries the API using auto-generated hooks that you will find in src/hooks.js

to edit or add new queries, edit or add your .graphql files in the src directory and run:

npm run gen

this will result in a new hook in the hook.js file, which you can import and use in your application

if you would prefer to make raw graphql queries without the use of codegen tooling, take a look at the second query in the Proposals component

simply pass your graphql document string and variable arguments to the fetcher helper function to query the API

finally, the third table uses a helpful hook that we've created for you: useQuery. This hook uses React Query to supply states like isLoading, error, etc

Making your first GraphQL query

for those of you who aren't familiar with using GraphQL, have no fear!

making a GraphQL query with our fetcher method is as simple as defining your GraphQL query "document", and passing arguments.

as you can see in src/Proposals.jsx, the GraphQL document is simply a string that defines which API query you are calling and which fields you'd like to fetch

for more information on GraphQL querying checkout https://graphql.org/learn/queries/

when you've defined your document string pass it to the fetcher like so:

fetcher({ query: queryDocument })

when passing arguments, reference the Tally API playground or docs see which arguments are required for your query

you can then pass them to the fetcher as variables:

fetcher({
      query: proposalQueryDocument,
      variables: {
        id: proposalId,
       })

once you've passed your query and variables, fetcher will return your data as a promise

here's an example of handling the response in a .then() and setting it to some local state

fetcher({ ... }).then((data) => {
      const { proposals } = data ?? [];
      setProposals(proposals);
    });
API reference:

For our API Docs, visit https://docs.tally.xyz/tally-api/welcome

For our graphQL API Playground, visit https://api.withtally.com/playground

remember to pass your API Key in the headers

{ "api-key": "your_tally_api_key" }

and to only use the Governors and Proposals queries, all other queries and mutations are subject to changes or deprecation.

happy hacking!

arbitrum-proposal-alerts-tally's People

Contributors

dmrusyniak avatar parketh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.