A Node.js library for working with the Cardano blockchain.
- Node.js >= 20.0.0
- npm >= 10.0.0
- Wallet management with seed phrase and address support
- UTXO handling and querying
- Token operations (finding, listing, history)
- Transaction metadata support
- Network-agnostic design (supports mainnet, testnet, preprod, and preview networks)
- Blockfrost provider integration for blockchain data access
npm install cardano-tsimport { Wallet, Blockfrost } from 'cardano-ts';
// Create a provider
const provider = new Blockfrost('YOUR_PROJECT_ID', 'preview');
// Create a wallet
const wallet = new Wallet(provider, 'YOUR_ADDRESS');
// Get wallet balance
const balance = await wallet.getBalance();
console.log(`Wallet balance: ${balance} lovelace`);
// Get wallet assets
const assets = await wallet.getAssets();
console.log('Wallet assets:', assets);
// Check if wallet has enough balance
const hasEnough = await wallet.hasBalance(1000000n); // 1 ADA
console.log('Has enough balance:', hasEnough);
// Get asset balance
const assetId = 'YOUR_ASSET_ID';
const assetBalance = await wallet.getAssetBalance(assetId);
console.log(`Asset balance: ${assetBalance}`);
// Get asset history
const history = await wallet.getAssetHistory(assetId, 10);
console.log('Asset history:', history);- Clone the repository:
git clone https://github.com/MynthAI/cardano-ts.git
cd cardano-ts- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env
# Edit .env with your Blockfrost API keys- Run tests:
npm test- Build the library:
npm run buildThe library uses Vitest for testing. Tests are located in the src/tests directory.
To run tests:
npm testTo run tests in watch mode:
npm run test:watch- Added support for preview network
- Improved network validation and error handling
- Updated tests to use preview network addresses
- Added comprehensive Blockfrost provider implementation
- Support for UTXO queries with pagination
- Token operations (find, list, history)
- Transaction metadata handling
- Stake address support
- Added proper TypeScript types for all entities (Address, StakeAddress, UTxO)
- Improved network type to support all Cardano networks
- Added type-safe interfaces for provider methods
- Moved types to a dedicated types.ts file
- Improved error handling with network validation
- Added JSDoc comments for better documentation
- Updated tests to use new type system
- Added network validation tests
- Improved test organization and readability
- Added comprehensive Blockfrost provider tests
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.