Skip to content

AploCoin/AploNpm

Repository files navigation

AploNpm

TypeScript library for AploCoin blockchain interaction - mining, staking, and wallet operations.

CI npm version License: MIT

Installation

npm install @aplocoin/aplonpm
# or
pnpm add @aplocoin/aplonpm
# or
yarn add @aplocoin/aplonpm

Quick Start

Node.js Backend

import { createAploClient, DEFAULT_RPC_ENDPOINTS, fromWei } from '@aplocoin/aplonpm';

// Create client
const client = createAploClient({
  url: DEFAULT_RPC_ENDPOINTS.pub1,
  timeout: 30000,
});

// Get balance
const balance = await client.getBalance('0x...');
console.log('Balance:', fromWei(balance), 'APLO');

// Send transaction
const txHash = await client.sendTransaction(privateKey, {
  to: '0x...',
  value: toWei('1.5'), // Send 1.5 APLO
});

Browser with Wallet

import { detectInjectedProvider, createBrowserClient, sendAplo } from '@aplocoin/aplonpm';

// Detect MetaMask or compatible wallet
const provider = detectInjectedProvider();

// Request account access
await provider.request({ method: 'eth_requestAccounts' });

// Send transaction
const txHash = await sendAplo(provider, '0x...', '1.5');

Features

  • Core Operations: Balance, transactions, gas estimation
  • Staking: Stake/unstake APLO, check multipliers
  • Mining: Mine blocks with staking rewards
  • Browser Wallets: MetaMask, Rainbow, WalletConnect support
  • TypeScript: Full type definitions with strict mode
  • Dual Format: ESM and CommonJS support
  • Tree-shakeable: Optimized bundle size
  • Tested: 99 tests with comprehensive coverage

Development

Prerequisites

  • Node.js >= 18.0.0
  • pnpm (recommended) or npm

Setup

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Type checking
pnpm typecheck

# Build
pnpm build

# Lint
pnpm lint

Package Manager Notes

This project uses pnpm as the primary package manager. If dyno is available in your environment, you can use it as an alternative. Standard npm/yarn commands also work.

Project Structure

aplonpm/
├── src/
│   └── index.ts          # Main entry point
├── tests/
│   └── index.test.ts     # Test suite
├── dist/                 # Build output (ESM + CJS)
├── package.json
├── tsconfig.json
├── tsup.config.ts        # Build configuration
└── vitest.config.ts      # Test configuration

Examples

Comprehensive examples for both Node.js and browser environments:

Node.js Backend Examples

Browser Frontend Examples

See examples/README.md for detailed usage instructions.

Documentation

API Overview

Core Client

import { createAploClient, AploClient } from '@aplocoin/aplonpm';

const client = createAploClient({ url: 'https://pub1.aplocoin.com' });
await client.getBalance(address);
await client.sendTransaction(privateKey, { to, value });
await client.getTransactionReceipt(txHash);

Staking

import { createAploStaking, MIN_STAKE_WEI } from '@aplocoin/aplonpm';

const staking = createAploStaking({ url: 'https://pub1.aplocoin.com' });
await staking.getStake(address);
await staking.getMultiplier(address);
await staking.canMine(address);

Mining

import { createAploMining } from '@aplocoin/aplonpm';

const mining = createAploMining({ url: 'https://pub1.aplocoin.com' });
const result = await mining.mineOnce(privateKey, address);
await mining.mineLoop(privateKey, address, { onSuccess, onError });

Browser Wallets

import { detectInjectedProvider, sendAplo, stakeAplo } from '@aplocoin/aplonpm';

const provider = detectInjectedProvider();
await sendAplo(provider, toAddress, '1.5');
await stakeAplo(provider, '1000');

CI/CD

This project uses GitHub Actions for continuous integration and deployment:

  • CI Workflow (.github/workflows/ci.yml): Runs on every push and PR

    • Tests on Node.js 18.x, 20.x, 22.x
    • Type checking, linting, and testing
    • Build verification and package size check
  • Publish Workflow (.github/workflows/publish.yml): Publishes to NPM

    • Triggered by version tags (v1.0.0) or manual dispatch
    • Automatic dist-tag detection (latest, beta, alpha)
    • NPM provenance attestations
    • GitHub Release creation

See RELEASE.md for publishing instructions.

License

MIT

Contributing

Contributions are welcome! Please ensure:

  • All tests pass: pnpm test
  • Type checking passes: pnpm run typecheck
  • Code is linted: pnpm run lint
  • Examples are updated if API changes

Links

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors