-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
HardlyDifficult edited this page Apr 28, 2026
·
1 revision
Runnable TypeScript examples under examples/ in the canton-node-sdk repository.
- cn-quickstart running with OAuth2 enabled
- Clone:
https://github.com/digital-asset/cn-quickstart - Setup:
cd quickstart && make setup(choose "with OAuth2") - Start:
cd quickstart && make start
- Clone:
- SDK: from repo root,
npm install
Demonstrates the Canton class which provides a unified entry point for all API clients:
npx tsx examples/canton-quickstart.ts- Initializes all clients with shared configuration
- Shows how to use ledger, validator, and scan APIs
- Demonstrates dynamic party ID updates
npx tsx examples/localnet-with-oauth2.ts- Automatic token acquisition and refresh
- Bearer token injection in requests
- Keycloak/OAuth2 integration
npx tsx examples/create-party.ts [party-name] [amount]
npx tsx examples/create-party.ts alice 100- Creates user via Validator API
- Funds party via transfer offer
- Creates transfer preapproval contract
npx tsx examples/transfer-amulets.ts <receiver-party-id> [amount]
npx tsx examples/transfer-amulets.ts alice::12345... 10- Creates a transfer offer
- Accepts the offer as receiver
- Two-step transfer flow
npx tsx examples/external-signing.ts- Generates Ed25519 keypair
- Creates external party on ledger
- External signing flow
npx tsx examples/scan-traffic-status.tsimport { Canton } from '@fairmint/canton-node-sdk';
const canton = new Canton({ network: 'localnet' });
const version = await canton.ledger.getVersion();
const balance = await canton.validator.getWalletBalance();
const health = await canton.scan.getHealthStatus();import { Canton, createParty } from '@fairmint/canton-node-sdk';
const canton = new Canton({ network: 'localnet' });
const { partyId, preapprovalContractId } = await createParty({
ledgerClient: canton.ledger,
validatorClient: canton.validator,
partyName: 'alice',
amount: '100',
});import { Canton, createTransferOffer, acceptTransferOffer } from '@fairmint/canton-node-sdk';
const canton = new Canton({ network: 'localnet' });
const offerId = await createTransferOffer({
ledgerClient: canton.ledger,
receiverPartyId: 'bob::123...',
amount: '50',
description: 'Payment',
});
await acceptTransferOffer({
ledgerClient: canton.ledger,
transferOfferContractId: offerId,
acceptingPartyId: 'bob::123...',
});import { Keypair } from '@stellar/stellar-base';
import { Canton, createExternalParty } from '@fairmint/canton-node-sdk';
const canton = new Canton({ network: 'localnet' });
const keypair = Keypair.random();
const { partyId } = await createExternalParty({
ledgerClient: canton.ledger,
keypair,
partyName: 'external-alice',
synchronizerId: 'global-synchronizer::...',
});- External signing (hosted docs)
- Integration tests — more complex scenarios