Quickstart

Install the SDK, create a passkey and an account, and make a first trade.

1. Install

npm install @dattex/sdk viem

The SDK ships ESM and CommonJS builds with types. viem is required because the SDK builds and encodes transactions with it.

2. Create the client

import { DattEx } from '@dattex/sdk'
import { base } from 'viem/chains'
import { http } from 'viem'

const sdk = new DattEx({
  apiKey: process.env.GALACTIC_API_KEY!,
  chain: { id: base.id },
  viem: { chain: base, transport: http() },
  namespace: 'main', // optional, defaults to 'main'
})
Option Required What it does
apiKey yes Your integrator key. Sent as the bearer on every request.
chain.id yes The chain the SDK operates on (Base is 8453).
viem.chain, viem.transport yes The viem chain and transport used for reads and encoding.
baseURL no API base URL. Defaults to production.
webauthnAdapter no How passkeys are created and used. Defaults to WebAuthnP256Adapter.
namespace no Multi-tenant slug. Defaults to main.

3. Create a passkey and an account

// Shows the browser's passkey prompt, registers the signer, and creates the account.
const account = await sdk.accounts.create({ inviteCode: 'FRIEND-123' })

console.log(account.id)      // account id
console.log(account.address) // smart account address on the configured chain

accounts.create makes a signer first if you do not pass one. See Passkeys and sign-in to bring your own signer or to sign in again later.

4. Deposit, then trade

// Fund the account from the owner's wallet (see Deposits).
const deposit = await account.prepareDeposit({
  token: { address: USDC_ADDRESS },
  amount: 25_000_000n, // 25 USDC, 6 decimals
})
await deposit.submit({ walletClient }) // a viem WalletClient the owner controls

// Quote, look at the numbers, then execute.
const quote = await account.prepareTradeQuote({
  inputAsset: { name: 'credits', amount: { unit: 'human', value: '10' } },
  outputAsset: { name: 'TSLA' },
  slippageTolerance: 0.5,
})

console.log(quote.outputAsset.amount.units.human) // what you would receive
const result = await quote.execute()              // prompts for the passkey signature
console.log(result.transactionHash)

Quotes are not orders. prepareTradeQuote creates a pending order on the server. Nothing moves until you call execute(). Show the user outputAsset, priceImpact and the route before you do.

Next