Skip to main content

A Python-based lightweight crypto wallet for Ethereum, Binance Smart Chain, and Polygon.

Project description

Nocturn Crypto Wallet

Introduction

Nocturn is a lightweight Python-based cryptocurrency wallet supporting Ethereum (ETH), Binance Smart Chain (BSC), and Polygon (POL). It enables users to manage their wallets, check balances, send transactions, and retrieve transaction history using public blockchain RPC nodes.

The wallet supports both mainnet and testnet environments and can be accessed using either a mnemonic phrase or a private key.


Features

  • Multi-chain Support: Works with Ethereum, Binance Smart Chain, and Polygon.
  • Wallet Management: Generate wallets from a mnemonic phrase or private key.
  • Transaction Management:
    • Check account balance.
    • Fetch transaction history.
    • Send crypto to any address.
    • Preview transactions before sending.
  • Custom RPC Support: Use default or custom RPC endpoints.
  • Conversion Utilities: Convert between ETH, Wei, USD, and other fiat currencies.

Wallet Class

The Wallet class is the primary interface for managing a wallet. It supports mnemonic phrase-based wallets and private key-based wallets.

Initialization

wallet = Wallet(ETHERSCAN_API_KEY="your_api_key", mnemonic_phrase="your mnemonic phrase")

or

wallet = Wallet(ETHERSCAN_API_KEY="your_api_key", private_key="your private key")

Constructor Parameters

Parameter Type Description
ETHERSCAN_API_KEY str API key for fetching transaction history.
mnemonic_phrase str (optional) Mnemonic phrase to generate a wallet.
private_key str (optional) Private key to restore an existing wallet.
rpc_endpoints dict (optional) Custom RPC endpoints for different chains.

Available Methods

1. fetch_balance(chain, testnet=False)

Fetches the balance of the wallet in Wei.

balance = wallet.fetch_balance("eth")
print(balance)  # Returns balance in Wei
Parameter Type Description
chain str Blockchain to fetch balance from (eth, bsc, pol).
testnet bool (optional) Fetch from testnet if True, default is False.

Returns: int (balance in Wei).


2. get_transaction_history(chain, page=1, testnet=False, offset=0)

Fetches transaction history from Etherscan-compatible APIs.

transactions = wallet.get_transaction_history("eth", page=1)
Parameter Type Description
chain str Blockchain (eth, bsc, pol).
page int (optional) Page number for pagination. Default is 1.
testnet bool (optional) Fetch from testnet if True.
offset int (optional) Number of transactions to skip. Default is 0.

Returns: list of transaction objects.


3. send_crypto(to_address, amount, chain, testnet=False, gas_price=None)

Sends cryptocurrency to a recipient.

tx = wallet.send_crypto("0xRecipientAddress", Web3.to_wei(0.01, "ether"), "eth")
print(tx)  # Returns transaction details
Parameter Type Description
to_address str Recipient’s wallet address.
amount int Amount to send (in Wei).
chain str Blockchain (eth, bsc, pol).
testnet bool (optional) Send on testnet if True.
gas_price int (optional) Custom gas price in Wei. If None, fetches from the network.

Returns: dict containing transaction details including:

  • Transaction hash (tx_hash)
  • Sender and recipient addresses
  • Gas limit, gas price, and total gas fee
  • Amount sent and remaining balance

4. preview_transaction(to_address, amount, chain, testnet=False, gas_price=None)

Simulates a transaction before sending.

preview = wallet.preview_transaction("0xRecipientAddress", Web3.to_wei(0.01, "ether"), "eth")
print(preview)
Parameter Type Description
to_address str Recipient’s wallet address.
amount int Amount to send (in Wei).
chain str Blockchain (eth, bsc, pol).
testnet bool (optional) Send on testnet if True.
gas_price int (optional) Custom gas price in Wei.

Returns: dict with transaction details including:

  • Estimated gas fee
  • Total cost (amount + gas fee)
  • Whether the wallet has enough balance (can_proceed)

Nocturn Class

The Nocturn class provides utility functions for working with crypto assets.

1. to_wei(amount)

Converts ETH to Wei.

wei_value = Nocturn.to_wei(0.01)  

Returns: int (Wei equivalent).


2. from_wei(amount)

Converts Wei to ETH.

eth_value = Nocturn.from_wei(10000000000000000)  

Returns: float (ETH equivalent).


3. to_currency(amount, currency="usd")

Converts ETH to another currency using Coingecko API.

usd_value = Nocturn.to_currency(1, "usd")  

Returns: float (value in the requested currency).


4. from_currency(amount, currency="usd")

Converts a currency (e.g., USD) to ETH.

eth_amount = Nocturn.from_currency(2000, "usd")  

Returns: float (ETH equivalent).


5. fetch_balance(address, rpc_endpoint)

Fetches balance for a given wallet address.

balance = Nocturn.fetch_balance("0xYourWalletAddress", "https://eth.meowrpc.com")

Returns: int (balance in Wei).


6. get_transaction_history(address, chain, API_KEY, page, testnet=False, offset=0)

Fetches transaction history for any address.

transactions = Nocturn.get_transaction_history("0xYourWalletAddress", "eth", "your_api_key", 1)

Returns: list of transaction objects.


7. send_crypto(private_key, to_address, amount, rpc_endpoint, gas_price=None)

Sends cryptocurrency from a private key.

tx = Nocturn.send_crypto("your-private-key", "0xRecipientAddress", Web3.to_wei(0.01, "ether"), "https://eth.meowrpc.com")

Returns: dict containing transaction details.


Conclusion

Nocturn is a powerful, lightweight crypto wallet for managing ETH, BSC, and POL transactions. It provides robust tools for sending, receiving, and monitoring transactions while ensuring flexibility with custom RPC nodes and conversion utilities.

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

nocturn-0.1.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

nocturn-0.1.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file nocturn-0.1.2.tar.gz.

File metadata

  • Download URL: nocturn-0.1.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for nocturn-0.1.2.tar.gz
Algorithm Hash digest
SHA256 548453d2cc585b754ed7008c7af23d87c23f6d94cf4b52b0830a862cfb1935eb
MD5 87a3cbb2f9cd8ca35077f3a5c1f1ece7
BLAKE2b-256 68f7f0e2a91db1e8ca716f42417672835db604ef0abeb2fc75a73bf4038c768e

See more details on using hashes here.

File details

Details for the file nocturn-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nocturn-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.3

File hashes

Hashes for nocturn-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23d670b9e1344ed412cf3bf5db9471e83658ea4b9bbe40448c5562f47f760c84
MD5 4298ded75730452c64dda0ff61cd4a54
BLAKE2b-256 88103e1d3564fe5aeb3b5664ccc85641748f3558c12a0b8a8de84fa5f1c4277e

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