@venturialstd/circle
v0.0.7
Published
Circle API Integration Module for Venturial
Keywords
Readme
@venturialstd/circle
A comprehensive NestJS module for integrating with Circle's User-Controlled Wallets and Developer-Controlled Wallets APIs.
Features
- Wallet Management: Create and manage wallets across multiple blockchains
- Wallet Sets: Organize wallets into sets for better management
- Transaction Management: Create and track transactions on various blockchains
- Token Balance Tracking: Monitor token balances for wallets
- NFT Balance Tracking: Track NFT balances for wallets
- Challenge Management: Handle user challenges for wallet operations
- API Operation Logging: Comprehensive logging of all Circle API operations
- Real-time Settings: Dynamic configuration via SettingsService
Installation
npm install @venturialstd/circleUsage
Import the Module
import { Module } from '@nestjs/common';
import { CircleModule } from '@venturialstd/circle';
@Module({
imports: [CircleModule],
})
export class AppModule {}Configure Settings
Before using the module, configure Circle API settings through the Settings module:
GLOBAL:CIRCLE:GENERAL:API_KEY- Your Circle API key (required)GLOBAL:CIRCLE:GENERAL:ENTITY_SECRET- Entity secret for developer-controlled wallets (optional)GLOBAL:CIRCLE:GENERAL:BASE_URL- Circle API base URL (optional, defaults tohttps://api.circle.com)
Use the Services
import { Injectable } from '@nestjs/common';
import {
CircleWalletService,
CircleTransactionService,
} from '@venturialstd/circle';
@Injectable()
export class WalletService {
constructor(
private readonly circleWalletService: CircleWalletService,
private readonly circleTransactionService: CircleTransactionService,
) {}
async createWallet(blockchains: string[], walletSetId: string) {
return this.circleWalletService.createWallets(blockchains, walletSetId);
}
async createTransaction(walletId: string, amounts: string[], destinationAddress: string) {
return this.circleTransactionService.createTransaction(
walletId,
amounts,
destinationAddress,
);
}
}Testing
The module includes a comprehensive test application that you can run locally.
Setup
- Copy the example environment file:
cd test
cp env.template .envUpdate the
.envfile with your database credentials.Create the database:
createdb circle_test- Run migrations:
npm run migration:run- Start the test server:
npm run test:devThe test server will start on http://localhost:3004 with all endpoints available for testing.
Available Scripts
npm run build- Build the modulenpm run test:dev- Start the test servernpm run test:watch- Start the test server with auto-reloadnpm run migration:generate --name=MigrationName- Generate a new migrationnpm run migration:run- Run pending migrationsnpm run migration:revert- Revert the last migration
Entities
CircleWallet
Represents a wallet created via Circle API.
CircleWalletSet
Represents a set of wallets for organization.
CircleTransaction
Represents a transaction on a blockchain.
CircleTokenBalance
Represents token balances for a wallet.
CircleNFTBalance
Represents NFT balances for a wallet.
CircleChallenge
Represents user challenges for wallet operations.
CircleApiOperation
Logs all Circle API operations for debugging and auditing.
Services
All services extend TypeOrmCrudService from @dataui/crud-typeorm for consistent CRUD operations.
CircleWalletService
createWallets()- Create wallets via Circle APIlistWallets()- List wallets from Circle APIgetWallet()- Get a wallet from Circle API
CircleTransactionService
createTransaction()- Create a transaction via Circle APIlistTransactions()- List transactions from Circle APIgetTransaction()- Get a transaction from Circle API
CircleTokenBalanceService
getWalletTokenBalance()- Get token balances for a wallet
CircleNFTBalanceService
getWalletNFTBalance()- Get NFT balances for a wallet
CircleChallengeService
listChallenges()- List challenges for a user
CircleApiService
makeApiCall()- Make API calls to Circle with automatic logginggetApiKey()- Get API key from settingsgetBaseUrl()- Get base URL from settings
License
MIT
Support
For issues and questions, please open an issue on the repository.
