Package for flow wallet network layer with backend server api
npm install @onflow/frw-apiNetwork API services and client interfaces for Flow Reference Wallet.
This package provides HTTP client interfaces and service definitions for interacting with Flow Reference Wallet backend APIs. It includes auto-generated TypeScript clients from OpenAPI/Swagger specifications.
- Auto-generated Clients: TypeScript clients generated from OpenAPI specs
- Type Safety: Full TypeScript support with auto-generated types
- Axios Integration: Built on Axios for reliable HTTP communication
- Multiple Service Endpoints: Support for various backend services
- Error Handling: Consistent error handling across all API calls
The package includes auto-generated services from two main API specifications:
#### JavaScript/TypeScript Services (service.ts)
- Auto-generated from js_swagger.json
- Modern TypeScript interfaces and client methods
- Promise-based async/await support
#### Go Services (goService.ts)
- Auto-generated from go_swagger.json
- Compatible with existing Go backend services
- Includes legacy endpoint support
- NftService: NFT collection and asset management
- FlowEvmNftService: EVM-based NFT services
- UserFtTokensService: Fungible token management
- AddressbookService: Contact and address book management
- AccountService: Account management operations
- CryptoService: Cryptographic operations
- CoinService: Coin and token operations
- UserService: User profile and settings
- ProfileService: User profile management
- DeviceService: Device registration and management
``typescript
import { NftService, UserFtTokensService, AddressbookService } from '@onflow/frw-api';
// Get NFT collections for an address
const nftResponse = await NftService.id({ address: '0x1234...' });
console.log(nftResponse.data);
// Get fungible tokens
const tokenResponse = await UserFtTokensService.ft({
address: '0x1234...',
network: 'mainnet',
currency: 'USD',
});
console.log(tokenResponse.data);
// Get address book contacts
const contacts = await AddressbookService.contact();
console.log(contacts.data);
`
`typescript
import { FlowEvmNftService } from '@onflow/frw-api';
// Get EVM NFT collections
const evmNfts = await FlowEvmNftService.id({ address: '0x1234...' });
console.log(evmNfts.data);
// Get NFTs from a specific collection
const collectionNfts = await FlowEvmNftService.collectionList({
address: '0x1234...',
collectionIdentifier: 'SomeCollection',
offset: 0,
limit: 50,
});
console.log(collectionNfts.data);
`
`typescript
import './codgen/axios'; // Import axios configuration
// The axios configuration is automatically applied
// All services use the configured axios instance
`
This package uses automated code generation from OpenAPI specifications:
- pnpm codegen: Generate TypeScript clients from both swagger filescodegen.cjs
- : Generates JavaScript/TypeScript servicescodegen-go.cjs
- : Generates Go-compatible services
- js_swagger.json: JavaScript/TypeScript API specificationgo_swagger.json
- : Go backend API specification
- src/codgen/service.ts: Modern TypeScript servicessrc/codgen/goService.ts
- : Go-compatible servicessrc/codgen/axios.ts
- : Axios configuration and interceptorssrc/codgen/utils.ts
- : Utility functions and types
`bashInstall dependencies
pnpm install
API Specifications
$3
1. Update the appropriate swagger JSON file (
js_swagger.json or go_swagger.json)
2. Run code generation: pnpm codegen
3. Review generated changes
4. Update version and rebuild$3
1. Add endpoints to the appropriate swagger specification
2. Regenerate clients:
pnpm codegen
3. Export new services in src/index.ts
4. Update types if neededError Handling
All API services return responses in a consistent format:
`typescript
interface ApiResponse {
data?: T;
status?: number;
message?: string;
success?: boolean;
}
`Handle errors appropriately:
`typescript
try {
const response = await NftService.id({ address });
if (response.data) {
// Handle success
console.log(response.data);
}
} catch (error) {
// Handle API errors
console.error('API Error:', error);
}
`Dependencies
-
axios: HTTP client library
- swagger-axios-codegen`: Code generation toolLGPL-3.0-or-later