0.19.20 • Published 5 months ago

@abstract-money/abstract.js v0.19.20

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

abstract.js

This repository holds the type declarations and interfaces for our smart contracts in CosmWasm. Autogenerated contracts lie in generated and those that are "fixed" are placed in src/contracts.

Scripts

  • pnpm build: Generate the types
  • pnpm fix: Temporary fixes for the autogenerated contracts (TODO)
  • pnpm format: Run prettier
  • pnpm lint: Run linter
  • pnpm lint:fix: Attempt linter fixes

Getting Started

  1. Install Abstract.js
pnpm install @abstract-money/abstract.js
  1. Initialize the AbstractQueryClient for the chain on which you're using Abstract.
import { AbstractQueryClient } from "@abstract-money/abstract.js";

const CHAIN_NAME = "juno";
const getAbstract = async () => {
  const abstractQueryClient = await AbtsractQueryClient.connectToChain(
    CHAIN_NAME
  );
};

Abstract API

  1. Install dependencies
pnpm install graphql-request@5

Typescript

To allow for strongly-typing the schemas, we recommend setting up code generation.

See https://www.apollographql.com/docs/ios/code-generation/codegen-configuration/ for alternative options.

The following uses the-guild's graphql codegen as a typescript preset. See https://the-guild.dev/graphql/codegen/plugins/presets/preset-client for client options.

  1. Install dependencies
pnpm install -D graphql @graphql-codegen/cli @graphql-codegen/client-preset @graphql-typed-document-node/core
  1. Setup codegen.yml. This allows for auto type generation.
schema: "<API_URL>/graphql" # This can be the API URL or the schema document

documents: ["./src/**/*.{tsx,ts}", "!src/__generated__/gql/**/*"]
generates:
  ./src/__generated__/gql/:
    preset: client
    presetConfig:
      gqlTagName: gql
      immutableTypes: true
    config:
      immutableTypes: true
      useTypeImports: true
      scalars:
        # Temporarily map to any, see DAT-16
        JSON: any
        Semver: string
        Bech32Address: string
  1. Add codegen command to package.json
{
  "scripts": {
    "codegen": "graphql-codegen --config codegen.yml",
    "codegen:watch": "graphql-codegen --config codegen.yml --watch"
  }
}

NOTE: The first time you generate the types you will not import gql from the generated folder, rather just including the string in the file!

Usage

The following example shows how to query the Abstract API for the value of a given account:

import { AbstractAccountId, abstractApiRequest } from '@abstract-money/abstract.js'

import { gql } from '__generated__/gql'
import { type AccountValueQuery } from '__generated__/gql/graphql'

const accountValueQuery = gql(/* GraphQL */`
  query AccountsByIds($ids: [AccountIdWithChain!]!) {
    accountsByIds(ids: $ids) {
      vault {
        value
        baseAsset
      }
    }
  }
`)

const getAccountValue = async (accountId: AbstractAccountId) => {
  // This type is auto-generated and inferred by graphql-codegen, we are typing it for exemplary purposes
  const result: AccountValueQuery = await abstractApiRequest(
    accountValueQuery,
    // query variables are also strongly-typed!
    { ids: [accountId.toApi()] },
  )

  return result.accountsByIds[0].vault
}

getAccountValue(AbstractAccountId.fromStringId("kujiratestnet-13"))
  .then(({ value, baseAsset }) => console.log(
    `Total account value is ${value} ${baseAsset}`
  )
)

IDEs

We recommend installing the graphql plugins for the ides, where you can also include a link to the Abstract API URL for auto recognition of the schemas.

0.19.20

5 months ago

0.19.11

6 months ago

0.19.15

6 months ago

0.19.16

6 months ago

0.19.17

5 months ago

0.19.18

5 months ago

0.19.19

5 months ago

0.19.10

6 months ago

0.19.9

7 months ago

0.19.0

7 months ago

0.17.2

10 months ago

0.19.1

7 months ago

0.17.3

10 months ago

0.17.4

10 months ago

0.19.3

7 months ago

0.17.5

10 months ago

0.19.4

7 months ago

0.17.6

10 months ago

0.19.5

7 months ago

0.17.7

9 months ago

0.19.6

7 months ago

0.17.8

9 months ago

0.19.7

7 months ago

0.17.9

9 months ago

0.17.0

10 months ago

0.17.1

10 months ago

0.15.4

11 months ago

0.15.5

11 months ago

0.15.6

11 months ago

0.15.2

12 months ago

0.15.1

12 months ago

0.15.0

12 months ago

0.14.2

1 year ago

0.14.1

1 year ago