mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
* fix android CI * fix: duplicate outgoing tx for jup swaps and stuck pending state * fix solana security risk by handling duplicate token symbols in wallet transactions * feat: implement additional cost handling for pending transactions in Solana wallet. * fix: Items on security audit list for solana wallet * refactor: streamline fee payer index handling and improve error logging * fix: verifySignature for solana and handle wrong mint on default token * fix: token decimals defaulting to zero and breaking amount parsing in solana * fix: use token mask in tx history * refactor: apply lint to modified code * fix: merge conflicts * fix: use Money and mint decimals when parsing sol swaps * test: add unit tests for SPL token amount handling and parsing * test: add more tests * fix: update decimal handling for fetched token and remove unused fields
cw_solana
Solana wallet module for Cake Wallet. Provides native SOL and SPL token support built on on_chain/solana with high-throughput RPC usage and safe transaction parsing.
Features
- Connect to Solana RPC (Ankr/Chainstack/custom) via
SolanaRPCover HTTP. - Fetch SOL balances and aggregate SPL token balances across accounts.
- Parse and stream native and SPL token transactions (filters ATA-only and spam-like micro txs).
- Estimate fees per compiled message and enforce rent-exemption checks.
- Create/sign/broadcast SOL and SPL transfers; auto-create recipient ATA when necessary.
- Manage SPL tokens; fetch on-chain metadata (symbol/name) for unknown mints.
- Sign and verify messages.
- Node health checks for SOL and a known SPL token (USDC).
Getting started
If you use hosted RPC providers, add a secrets file for keys (optional unless using those hosts):
// cw_solana/lib/.secrets.g.dart (DO NOT COMMIT)
const String ankrApiKey = 'YOUR_ANKR_KEY';
const String chainStackApiKey = 'YOUR_CHAINSTACK_KEY';
Connect and sync:
final service = SolanaWalletService(walletInfoBox, true);
final wallet = await service.create(SolanaNewWalletCredentials(name: 'My SOL', password: 'secret'));
await wallet.connectToNode(node: Node(uriRaw: 'api.mainnet-beta.solana.com', isSSL: true));
await wallet.startSync();
final sol = wallet.balance[CryptoCurrency.sol]?.balance;
Usage
Send SOL:
final pending = await wallet.createTransaction(
SolanaTransactionCredentials.single(
address: 'SoL...',
cryptoAmount: '0.05',
currency: CryptoCurrency.sol,
),
);
final sig = await pending.commit();
Add an SPL token by mint:
final token = await wallet.getSPLToken('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'); // USDC
if (token != null) {
await wallet.addSPLToken(token);
}
Additional information
- When using
rpc.ankr.comorsolana-mainnet.core.chainstack.com, the client reads API keys from.secrets.g.dart. - See
lib/for APIs:SolanaWalletClient,SolanaWallet,SolanaWalletService, and credential types.