Developer Experience Guide
Essential information for developing with and contributing to the Astral SDK.
Development Setup
Prerequisites
• Node.js 18+ and pnpm
• A Web3 wallet (MetaMask or similar)
• Access to a blockchain RPC endpoint
Environment Configuration
Create a .env
file in your project root:
# Required for onchain operations
ETHEREUM_RPC_URL=https://sepolia.infura.io/v3/YOUR_KEY
PRIVATE_KEY=your_test_wallet_private_key
# Required for API operations
ASTRAL_API_URL=https://api.astral.global
# Optional
DEBUG=astral:*
※ Security Note: Never commit .env
files or expose private keys in code.
Module Workflow
Creating a New Extension
- Create the extension file:
// src/extensions/location/builtins/MyFormat.ts
import { LocationFormatExtension } from '../../types';
export class MyFormatExtension implements LocationFormatExtension {
name = 'my-format';
validate(location: unknown): boolean {
// Validation logic
}
encode(location: unknown): string {
// Encoding logic
}
decode(encoded: string): unknown {
// Decoding logic
}
}
- Register the extension:
// src/extensions/location/index.ts
import { MyFormatExtension } from './builtins/MyFormat';
export const locationExtensions = [
// ... existing extensions
new MyFormatExtension()
];
- Add tests:
// test/extensions/location/MyFormat.test.ts
import { MyFormatExtension } from '@/extensions/location/builtins/MyFormat';
describe('MyFormatExtension', () => {
const extension = new MyFormatExtension();
it('validates correct format', () => {
expect(extension.validate(validData)).toBe(true);
});
});
JavaScript vs TypeScript
Why the SDK Publishes JavaScript
The published NPM package contains:
• Transpiled JavaScript (ES2020) for broad compatibility
• TypeScript declaration files (.d.ts
) for type safety
• Source maps for debugging
Development is TypeScript
All source code is written in TypeScript: • Full type safety during development • Better IDE support and autocomplete • Compile-time error checking
Build Process
# TypeScript source → JavaScript output
pnpm run build
# Output structure:
dist/
├── index.js # Transpiled JavaScript
├── index.d.ts # Type declarations
└── index.js.map # Source maps
Testing Patterns
Unit Test Setup
import { vi } from 'vitest';
import { AstralSDK } from '@/core/AstralSDK';
// Mock provider
const mockProvider = {
request: vi.fn(),
getSigner: vi.fn()
};
// Test instance
const sdk = new AstralSDK({
provider: mockProvider
});