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

Setup Scalar Network API #4

Open
0xdavid7 opened this issue Feb 17, 2025 · 0 comments
Open

Setup Scalar Network API #4

0xdavid7 opened this issue Feb 17, 2025 · 0 comments

Comments

@0xdavid7
Copy link

  • The Scalar Network API is the gateway to interact with the Scalar network
  • It provides the openapi.yaml file

Prerequisites:

pakage.json

{
   "scripts": {
         "generate-api": "rimraf ./src/types/schema.ts && openapi-typescript ./assets/openapi.yaml -o ./src/types/schema.ts"
     }
}

Refs: https://github.com/scalarorg/simple-staking/blob/scalar/src/types/schema.ts

  • Setup OpenAPI and ScalarAPI client:
import createFetchClient from "openapi-fetch";
import createClient, { OpenapiQueryClient } from "openapi-react-query";

import { ProjectENV } from "@/env";
import { paths } from "@/types/schema";

const scalarFetchClient = createFetchClient<paths>({
  baseUrl: ProjectENV.NEXT_PUBLIC_SCALAR_API_URL,
});

const ScalarAPI: OpenapiQueryClient<paths> = createClient(scalarFetchClient);

export default ScalarAPI;
  • Usage:
import ScalarAPI from "@/apis/scalar";

export const useScalarnetParams = () => {
  return ScalarAPI.useQuery("get", "/scalar/scalarnet/v1beta1/params", {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant