npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

nvc-sdk-wallet-sol

v1.0.0

Published

Solana Wallet SDK for React Native - TrustWallet/Phantom style

Readme

Solana Wallet SDK

SDK Solana Wallet cho React Native với style tương tự TrustWallet/Phantom. Hỗ trợ đầy đủ các chức năng quản lý ví, giao dịch, swap và tích hợp Solscan.

Tính năng

  • ✅ Tạo ví Solana mới với mnemonic 12 từ
  • ✅ Tạo nhiều ví con từ mnemonic gốc
  • ✅ Import ví từ private key hoặc mnemonic
  • ✅ Gửi và nhận SOL và SPL tokens
  • ✅ Swap onchain các token trên Solana (tích hợp Jupiter)
  • ✅ Xem lịch sử giao dịch từ Solscan
  • ✅ Config mainnet/devnet
  • ✅ Encrypt private key với AES + password
  • ✅ Token balance cache
  • ✅ Adapter riêng cho React Native với AsyncStorage
  • ✅ TypeScript support đầy đủ

Cài đặt

npm install nvc-sdk-wallet-sol
# hoặc
yarn add nvc-sdk-wallet-sol

Peer Dependencies

SDK này yêu cầu các peer dependencies sau:

npm install react-native @react-native-async-storage/async-storage

Sử dụng

Khởi tạo SDK

import { ReactNativeAdapter, Network } from 'nvc-sdk-wallet-sol';

// Khởi tạo với React Native Adapter
const adapter = new ReactNativeAdapter({
  network: Network.MAINNET, // hoặc Network.DEVNET
  rpcUrl: 'https://api.mainnet-beta.solana.com', // optional, custom RPC
  solscanApiKey: 'your-api-key', // optional, để sử dụng Solscan API
});

// Initialize adapter (load data từ storage)
await adapter.initialize();

Tạo ví mới

// Tạo ví mới
const { account, mnemonic } = await adapter.createWallet({
  name: 'My Wallet',
  password: 'your-secure-password',
});

// Lưu mnemonic an toàn! Bạn sẽ cần nó để khôi phục ví
console.log('Mnemonic:', mnemonic);
console.log('Public Key:', account.publicKey);

Tạo ví con

// Tạo ví con từ mnemonic gốc
const childWallet = await adapter.createChildWallet(
  mnemonic,
  'your-password',
  0, // index
  'Child Wallet 1'
);

Import ví

// Import từ private key
const importedWallet = await adapter.importFromPrivateKey({
  name: 'Imported Wallet',
  password: 'your-password',
  privateKey: 'your-private-key-base58',
});

// Import từ mnemonic
const importedWallet2 = await adapter.importFromMnemonic({
  name: 'Imported Wallet 2',
  password: 'your-password',
  mnemonic: 'word1 word2 ... word12',
  derivationPath: "m/44'/501'/0'/0'", // optional
});

Gửi SOL

const sdk = adapter.getSDK();
const currentAccount = sdk.getCurrentAccount();

if (currentAccount) {
  const signature = await sdk.sendSOL(
    currentAccount.id,
    'your-password',
    'recipient-address',
    0.1 // amount in SOL
  );
  
  console.log('Transaction signature:', signature);
}

Gửi Token

const signature = await sdk.sendToken(
  currentAccount.id,
  'your-password',
  'recipient-address',
  'token-mint-address',
  100, // amount
  9 // decimals (optional)
);

Lấy số dư

// SOL balance (có cache)
const solBalance = await sdk.getSOLBalance(currentAccount.id);
console.log('SOL Balance:', solBalance);

// Token balance (có cache)
const tokenBalance = await sdk.getTokenBalance(
  currentAccount.id,
  'token-mint-address'
);
if (tokenBalance) {
  console.log('Token Balance:', tokenBalance.uiAmount);
}

Swap Token

// Get swap quote
const quote = await sdk.getSwapQuote({
  fromToken: 'So11111111111111111111111111111111111111112', // SOL
  toToken: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
  amount: '1000000000', // amount in smallest unit
  slippage: 0.5, // 0.5% slippage
});

console.log('Output amount:', quote.outputAmount);
console.log('Price impact:', quote.priceImpact);

// Execute swap
const swapSignature = await sdk.swap(
  currentAccount.id,
  'your-password',
  {
    fromToken: 'So11111111111111111111111111111111111111112',
    toToken: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
    amount: '1000000000',
    slippage: 0.5,
  }
);

Lịch sử giao dịch

// Lấy lịch sử giao dịch từ Solscan
const transactions = await sdk.getTransactionHistory(
  currentAccount.id,
  50 // limit
);

transactions.forEach(tx => {
  console.log('Type:', tx.type);
  console.log('Amount:', tx.amount);
  console.log('Status:', tx.status);
  console.log('Signature:', tx.signature);
});

Quản lý nhiều ví

// Lấy tất cả ví
const allAccounts = sdk.getAllAccounts();

// Chuyển đổi ví hiện tại
await adapter.setCurrentAccount(accountId);

// Xóa ví
await adapter.removeAccount(accountId);

// Đổi tên ví
await adapter.updateAccountName(accountId, 'New Name');

Thay đổi network

// Chuyển sang devnet
sdk.setNetwork(Network.DEVNET);

// Hoặc custom RPC
sdk.setNetwork(Network.MAINNET, 'https://custom-rpc-url.com');

Sử dụng trực tiếp SDK (không dùng adapter)

import { SolanaWalletSDK, Network } from 'nvc-sdk-wallet-sol';

const sdk = new SolanaWalletSDK({
  network: Network.MAINNET,
  rpcUrl: 'https://api.mainnet-beta.solana.com',
  solscanApiKey: 'your-api-key',
});

// Sử dụng tương tự như trên
// Lưu ý: Bạn cần tự quản lý storage cho accounts

Cấu trúc

src/
├── core/              # Core classes
│   ├── Wallet.ts      # Quản lý ví
│   ├── TransactionManager.ts  # Gửi/nhận token
│   ├── SwapManager.ts # Swap tokens
│   ├── SolscanManager.ts # Solscan integration
│   └── CacheManager.ts # Cache manager
├── config/            # Configuration
│   └── network.ts     # Network config
├── utils/             # Utilities
│   ├── encryption.ts  # AES encryption
│   └── keyDerivation.ts # Key derivation
├── adapters/          # Platform adapters
│   └── ReactNativeAdapter.ts # React Native adapter
├── types/             # TypeScript types
│   └── index.ts
└── index.ts           # Main export

Bảo mật

  • Private keys được encrypt bằng AES với password
  • Mnemonic phrases được generate theo BIP39 standard
  • Key derivation theo BIP44 với path m/44'/501'/index'/0'
  • Không lưu plaintext private keys

Lưu ý

  1. Password: Luôn sử dụng password mạnh và an toàn
  2. Mnemonic: Lưu mnemonic ở nơi an toàn, mất mnemonic = mất ví
  3. Network: Kiểm tra network (mainnet/devnet) trước khi giao dịch
  4. RPC: Có thể cần custom RPC để tránh rate limit
  5. Solscan API: Cần API key để sử dụng đầy đủ tính năng Solscan

Publish lên NPM

# Build
npm run build

# Publish
npm publish --access public

License

MIT