Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@definedfi/sdk

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@definedfi/sdk

The Defined.fi SDK for JavaScript/Typescript. It provides generated types and convenient ways to access the graphql api.

  • 0.5.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
616
decreased by-12.5%
Maintainers
1
Weekly downloads
 
Created
Source

Defined SDK

This package exists to help you develop on top of the Defined API (https://docs.defined.fi).

It provides the public schema SDL for you to use. You can use graphql-codegen to generate types and queries for example.

Installation

packagercommand
npmnpm add @definedfi/sdk
yarnyarn add @definedfi/sdk
bunbun add @definedfi/sdk

Usage

Follow one of the examples in the examples directory, or simply run.

Fetch a token.

import { Defined } from "@definedfi/sdk";

const sdk = new Defined(MY_API_KEY);

sdk.queries
  .token({
    input: {
      address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c",
      networkId: 56,
    },
  })
  .then(console.log);

Use your own GraphQL selections

import { Network } from "../../src/resources/graphql";
import { Defined } from "@definedfi/sdk/dist/sdk";

const sdk = new Defined(process.env.DEFINED_API_KEY || "");

sdk
  .send<{ getNetworks: Network[] }>(
    `
  query GetNetworks {
    getNetworks { id name }
  }
`,
    {}
  )
  .then((res) => {
    console.log("Networks: ", res.getNetworks);
  });

Running the examples

You'll need to have curl installed in order to build this locally, as it fetches the schema from the Defined API.

You need to provide an API key in order for the examples to work. We have bun in use for development here.

After installing bun, from the project root.

  • bun i
  • bun run build

Simple

This performs a simple inline graphql request, and uses a user-provided query and selection set.

  • cd examples/simple
  • bun i
  • DEFINED_API_KEY=xyz bun run index.ts

You can define your own GraphQL queries and use those with codegen (see next section). The pre-defined queries we provide in the examples do not include all of the fields for every query.

Codegen

This shows how to use graphql-codegen to generate query types and get a fully typed end-to-end experience.

  • cd examples/codegen
  • bun i
  • bun run codegen
  • DEFINED_API_KEY=xyz bun run src/index.ts

Next

This shows how you could use it in a NextJS project.

  • cd examples/next
  • bun i
  • NEXT_PUBLIC_DEFINED_API_KEY=xyz bun run dev

Contributing

Prs open!

Keywords

FAQs

Package last updated on 24 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc