Skip to main content

async nano library for easy account management

Project description

Nano Wallet Library (nanowallet)

PyPI version License: MIT

A modern, asynchronous Python library for interacting with the Nano cryptocurrency network. nanowallet supports read-only monitoring and authenticated operations via private key or seed+index, providing full transaction capabilities including sending, receiving, and sweeping funds.

Designed with type safety and robust error handling in mind.

Key Features

  • Asynchronous: Built with asyncio for efficient network communication.
  • Typed: Fully type-hinted for better developer experience and static analysis.
  • Wallet Types:
    • NanoWalletReadOnly: Monitor accounts without exposing keys.
    • NanoWalletAuthenticated: Operate a wallet using a private key (via create_wallet_from_private_key) or seed+index (via create_wallet_from_seed).
  • Comprehensive Operations: Send, receive (specific blocks or all pending), sweep funds, check history, get account info.
  • Safe Error Handling: Uses a NanoResult[T] wrapper to prevent unexpected crashes, promoting explicit error checks.
  • Automatic State Management: Handles Nano's sequential block requirements automatically after operations.
  • Configurable: Set default representatives, control work generation sources.
  • Automatic Retry: Includes methods like send_with_retry for handling transient network/RPC issues.

Installation

pip install nanowallet

Requires Python 3.8+

Quick Start

import asyncio
from nanowallet import create_wallet_from_seed, NanoWalletRpc, WalletConfig
from nanowallet.utils import sum_received_amount

async def main():
    # Connect to a Nano node
    rpc = NanoWalletRpc(url="http://localhost:7076")
    wallet_config = WalletConfig(use_work_peers=False)  # Optional configuration
    
    # Create wallet from seed and index
    # ------------------------------------------------------------
    wallet = create_wallet_from_seed(
        rpc=rpc,
        seed="0000000000000000000000000000000000000000000000000000000000000000",
        index=0,
        config=wallet_config,
    )
    
    # Check balance
    # ------------------------------------------------------------
    response = await wallet.balance_info()
    balance_info = response.unwrap()  # Option 1 - .unwrap() to handle the response
    print(f"Balance: {balance_info.balance} NANO")
    print(f"Receivable Balance: {balance_info.receivable} NANO")
    
    # Receive all pending transactions
    # ------------------------------------------------------------
    result = await wallet.receive_all()
    if result.success:  # Option 2 - check success
        received_amount = sum_received_amount(result.value)
        print(f"Received {len(result.value)} blocks!")
        print(f"Received amount: {received_amount.amount} NANO")
    else:
        print(f"Error receiving blocks: {result.error}")
    
    # Send entire balance to another account
    # ------------------------------------------------------------
    destination = "nano_3msc38fyn67pgio16dj586pdrceahtn75qgnx7fy19wscixrc8dbb3abhbw6"
    send_result = await wallet.sweep(
        destination, sweep_pending=True
    )  # Sweeps pending/receivable balance + confirmed balance
    
    try:
        send_hash = send_result.unwrap()
        print(f"Sent! Block hash: {send_hash}")
    except Exception as e:
        print(f"Error sending: {e}")

asyncio.run(main())

That's it! The library handles all the complexity of work generation, block signing, and state management for you.

Documentation

For full details on wallet types, methods, error handling, and configuration, see the Full Documentation.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanowallet-0.1.8.tar.gz (57.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nanowallet-0.1.8-py3-none-any.whl (40.8 kB view details)

Uploaded Python 3

File details

Details for the file nanowallet-0.1.8.tar.gz.

File metadata

  • Download URL: nanowallet-0.1.8.tar.gz
  • Upload date:
  • Size: 57.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for nanowallet-0.1.8.tar.gz
Algorithm Hash digest
SHA256 3156afdb10b4dfd9495371b19974e34f6c6f42a9bf5b56dcde8e167d1879baa1
MD5 fee817238e4434cf636022580bfb5d15
BLAKE2b-256 16bbc12f4c79564207642061cd270a01268625baa170d64a6ad16209f8c15356

See more details on using hashes here.

File details

Details for the file nanowallet-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: nanowallet-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 40.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for nanowallet-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d3ce3a71f3891ba36d004c8bb423a2c4dc0ffe3f9ebabb8dda9fee333f18691e
MD5 7a9625b0db17538a3fd8a6450b902548
BLAKE2b-256 3dae93eb84fa306b871d31bfc992c3c4a1cfdb7a7879b12975304b84ac299a1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page