a. Overview
#To get started developing with FRAGMENT:
- Design your Schema
- Generate an SDK
- Deploy your Ledger
- Integrate the API
Get started by using the MCP or following the guide.
b. Use the MCP
#Open the dashboard and create a new MCP Connection. Paste the following prompt into your preferred AI tool:
Use the Fragment MCP to read the quickstart-mcp guide, then follow it end to end.
After this is done you'll have a script that demonstrates the integration against a FRAGMENT Ledger.
- Design a Schema to fit your use-case
- Go to production by embedding FRAGMENT into your CI
- Migrate your existing ledger to FRAGMENT
c. Follow the guide
#A Schema customizes a FRAGMENT Ledger for a specific use-case. Download this toy Schema to begin the quickstart:
{
"key": "quickstart-schema",
"chartOfAccounts": {
"defaultConsistencyConfig": {
"totalBalanceUpdates": "strong"
},
"defaultCurrencyMode": "multi",
"accounts": [
{
"key": "assets",
"type": "asset"
},
{
"key": "liabilities",
"type": "liability"
},
{
"key": "income",
"type": "income"
},
{
"key": "expense",
"type": "expense"
}
]
},
"ledgerEntries": {
"types": [
{
"type": "simple-entry",
"lines": [
{
"key": "line-WPZ6bsw08YyW",
"account": {
"path": "assets"
},
"currency": {
"code": "USD"
},
"amount": "{{gross_amount}}"
},
{
"key": "line-m4spJaQWFqnw",
"account": {
"path": "liabilities"
},
"currency": {
"code": "USD"
},
"amount": "{{gross_amount}}-{{fee_revenue}}"
},
{
"key": "line-bvZiWSE69k4m",
"account": {
"path": "income"
},
"currency": {
"code": "USD"
},
"amount": "{{fee_revenue}}"
}
]
}
]
},
"scenes": [
{
"name": "Simple Scenario",
"events": [
{
"eventType": "entry",
"entry": {
"type": "simple-entry",
"typeVersion": 1,
"parameters": {
"fee_revenue": "250",
"gross_amount": "10000"
}
}
}
]
}
]
}Generate a strongly-typed SDK specific to your Schema using the FRAGMENT CLI.
-
Install the CLI via NPM or Homebrew:
npmnpm install -g @fragment-dev/clihomebrewbrew tap fragment-dev/tap &&\ brew install fragment-dev/tap/fragment-cli -
Authenticate the CLI against your FRAGMENT workspace:
fragment login -
Generate an SDK for your language:
fragment gen-graphql \ --path=quickstart-schema.jsonc \ --output=queries.graphql &&\ npm install --save @fragment-dev/node-client &&\ npx fragment-node-client-codegen \ --input=queries.graphql \ --outputFilename=fragment-client.ts -
Create an API client in the dashboard.
-
Initialize your FRAGMENT client using the generated SDK and API client credentials:
import { createFragmentClient } from '@fragment-dev/node-client'; import { getSdk } from './fragment-client'; const fragment = createFragmentClient({ params: { clientId: "<Client ID>", clientSecret: "<Client Secret>", apiUrl: "<API URL>", authUrl: "<OAuth URL>", scope: "<OAuth Scope>", }, getSdk, });
To deploy your Ledger:
- Store the Schema
- Create a Ledger from the Schema
import { readFileSync } from 'node:fs';
// Load the Schema you downloaded with `fragment get-schema`.
const schema = JSON.parse(
readFileSync('quickstart-schema.jsonc', 'utf8')
);
const { storeSchema } = await fragment.storeSchema({
schema,
})
const { createLedger } = await fragment.createLedger({
ik: `test-ledger`,
ledger: {
name: `quickstart ledger`,
},
schemaKey: schema.key,
})Begin integrating the API into your product by:
- Posting a Ledger Entry
- Reading a Ledger Account's balance
import { ReadBalanceConsistencyMode } from '@fragment-dev/node-client/types';
// Post the `simple-entry` Ledger Entry type
// with the required parameters
const { addLedgerEntry } = await fragment.PostSimpleEntry({
ik: `quickstart-entry`,
// The Ledger the Ledger Entry should post to.
ledgerIk: `test-ledger`,
gross_amount: '10000', // $100.00
fee_revenue: '250', // $2.50
})
const { ledgerAccount } = await fragment.getLedgerAccountBalance({
ledgerIk: `test-ledger`,
path: `income`,
balanceConsistencyMode: ReadBalanceConsistencyMode.Strong,
})
console.log(ledgerAccount.balance);- Design a Schema to fit your use-case
- Go to production by embedding FRAGMENT into your CI
- Migrate your existing ledger to FRAGMENT