@abstract-money/core
v3.4.1
Published
Typings for Abstract smart contracts
Downloads
1,136
Readme
abstractjs
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 typespnpm fix
: Temporary fixes for the autogenerated contracts (TODO)pnpm format
: Run prettierpnpm lint
: Run linterpnpm lint:fix
: Attempt linter fixes
Getting Started
- Install core
pnpm install @abstract-money/core
- Initialize the
AbstractQueryClient
for the chain on which you're using Abstract.
import { AbstractQueryClient } from '@abstract-money/core'
const CHAIN_NAME = "juno"
const getAbstract = async () => {
const abstractQueryClient = await AbtsractQueryClient.connectToChain(CHAIN_NAME)
}
Abstract API
- 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.
- Install dependencies
pnpm install -D @graphql-codegen/cli @graphql-codegen/client-preset @graphql-typed-document-node/core
- Setup
codegen.yml
. This allows for auto type generation. See
schema: "<API_URL>" # 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
SafeInt: number
- Add
codegen
command topackage.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 { gql } from '__generated__/gql'
import { type AccountValueQuery } from '__generated__/gql/graphql'
import { AbstractAccountId, abstractApiRequest } from '@abstract-money/core'
const accountValueQuery = gql(/* GraphQL */ `
query AccountValue($accountId: AccountIdInput!, $chain: ID!) {
account(chain: $chain, accountId: $accountId) {
vault {
baseAsset
value
}
}
}
`)
const CHAIN_NAME = "juno"
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!
{
chain: CHAIN_NAME,
accountId: accountId.toApi(),
}
)
return result.account.value
}
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.