Get started
Overview
abstract.js is a TypeScript interface for Abstract apps that provides low-level stateless primitives for interacting with Abstract. abstract.js is focused on developer experience, bundle size, and performance:
- Developer experience Automatic type safety and inference, comprehensive documentation, composable APIs.
- Bundle size Tree-shakable lightweight modules.
- Performance Optimized encoding/parsing, async tasks only when necessary. You can learn more about the rationale behind the project in the Why abstract.js section.
Installation
Using CosmosKit:
npm i @abstract-money/react @abstract-money/provider-cosmoskit
Using graz:
npm i @abstract-money/react @abstract-money/provider-graz
Quick Start
1. Set up your Config & Client Provider
Firstly, set up your config with a desired provider.
import { createConfig } from '@abstract-money/react'
import { grazProvider } from '@abstract-money/provider-graz'
const config = createConfig({
provider: grazProvider
})
2. Provide the Config to Abstract Provider
Wrap your app in the AbstractProvider
React Context Provider and pass the config
you created earlier to the config
property.
import { createConfig, AbstractProvider } from '@abstract-money/react'
import { grazProvider } from '@abstract-money/provider-graz'
const config = createConfig({
provider: grazProvider
})
export function App() {
return (
<AbstractProvider config={config}>
{/*...*/}
</AbstractProvider>
)
}
3. Setup Tanstack Query
Outside the AbstractProvider
, wrap your app in a TanStack Query React Context Provider,
e.g. QueryClientProvider, and pass a new QueryClient instance to the client property.
Check out the TanStack Query docs to learn about the library, APIs, and more.
Install @tanstack/react-query@^4
.
npm i @tanstack/react-query@^4
Now, wrap the AbstractProvider
with QueryClientProvider
.
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ChainProvider, defaultModalViews } from "@cosmos-kit/react";
import { wallets as keplrWallets } from "@cosmos-kit/keplr";
import { createConfig, AbstractProvider } from '@abstract-money/react'
import { cosmosKitProvider } from '@abstract-money/provider-cosmoskit'
const config = createConfig({
provider: cosmosKitProvider
})
const client = new QueryClient()
export function App() {
return (
<ChainProvider
chains={["cosmoshub"]}
wallets={[
...keplrWallets,
/*...*/
]}
>
<QueryClientProvider client={client}>
<AbstractProvider config={config}>
{/*...*/}
</AbstractProvider>
</QueryClientProvider>
</ChainProvider>
)
}
4. Use Abstract SDK
Now that everything is set up, every component inside the Abstract and TanStack Query Providers can use Abstract React Hooks.
import { accountIdToString } from '@abstract-money/core'
import { useAccounts } from '@abstract-money/react'
const owner = `...`
export default function Page() {
const accountsQuery = useAccounts({
args: {
chainName: 'osmosis',
owner,
}
})
if (accountsQuery.isLoading) return <>Loading</>
if (accountsQuery.isError) return <>Error =(</>
return accountsQuery.data.map(
(account, i) => <p key={i}>{accountIdToString(account)}</p>
)
}