# @abstract-money/abstract.js

> Typings for Abstract smart contracts

Latest version **0.19.20** (published 2023-12-17) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @abstract-money/abstract.js
pnpm add @abstract-money/abstract.js
yarn add @abstract-money/abstract.js
bun add @abstract-money/abstract.js
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.19.20 |
| Published | 2023-12-17 |
| First published | 2023-04-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 17 |
| Unpacked size | 5.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | adairrr |
| Maintainers | abstractos |

## Links

- npm: https://www.npmjs.com/package/@abstract-money/abstract.js
- Repository: https://github.com/Abstract-SDK/abstract.js
- Homepage: https://github.com/Abstract-SDK/abstract.js#readme
- Issues: https://github.com/Abstract-SDK/abstract.js/issues
- npm.io page: https://npm.io/package/@abstract-money/abstract.js

## Dependencies (17)

- [yup](https://npm.io/package/yup.md) 1.3.2
- [bech32](https://npm.io/package/bech32.md) ^2.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [semver](https://npm.io/package/semver.md) ^7.3.8
- [ts-mixer](https://npm.io/package/ts-mixer.md) ^6.0.2
- [type-fest](https://npm.io/package/type-fest.md) ^3.5.0
- [ts-pattern](https://npm.io/package/ts-pattern.md) ^4.0.6
- [cosmjs-types](https://npm.io/package/cosmjs-types.md) ^0.8.0
- [@cosmjs/amino](https://npm.io/package/@cosmjs/amino.md) ^0.31.0
- [chain-registry](https://npm.io/package/chain-registry.md) ^1.18.1
- [graphql-request](https://npm.io/package/graphql-request.md) 5
- [@cosmjs/encoding](https://npm.io/package/@cosmjs/encoding.md) ^0.31.0
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) ^0.13.1
- [@cosmjs/tendermint-rpc](https://npm.io/package/@cosmjs/tendermint-rpc.md) ^0.31.0
- [@abstract-money/cosmwasm](https://npm.io/package/@abstract-money/cosmwasm.md) 0.1.6
- [@cosmjs/cosmwasm-stargate](https://npm.io/package/@cosmjs/cosmwasm-stargate.md) ^0.31.0

## Recent versions

- 0.19.20 (latest) — 2023-12-17
- 0.19.19 — 2023-11-29
- 0.19.18 — 2023-11-28
- 0.19.17 — 2023-11-28
- 0.19.16 — 2023-11-22
- 0.19.15 — 2023-11-20
- 0.19.11 — 2023-11-20
- 0.19.10 — 2023-11-11
- 0.19.9 — 2023-10-19
- 0.19.7 — 2023-10-19
- 0.19.6 — 2023-10-17
- 0.19.5 — 2023-10-17
- 0.19.4 — 2023-10-17
- 0.19.3 — 2023-10-17
- 0.19.1 — 2023-10-06
- … 19 more at https://npm.io/package/@abstract-money/abstract.js/versions

## README

# abstract.js

This repository holds the type declarations and interfaces for our smart contracts in CosmWasm.
Autogenerated contracts lie in [generated](generated) and those that are "fixed" are placed in [src/contracts](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

```bash
pnpm install @abstract-money/abstract.js
```

2. Initialize the `AbstractQueryClient` for the chain on which you're using Abstract.

```ts
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

```bash
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

```bash
pnpm install -D graphql @graphql-codegen/cli @graphql-codegen/client-preset @graphql-typed-document-node/core
```

2. Setup `codegen.yml`. This allows for auto type generation.

```yml
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
```

3. Add `codegen` command to `package.json`

```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:

```ts
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.

---
_Source: https://npm.io/package/@abstract-money/abstract.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
