Skip to main content

The simplest way to use Web3 features

Project description

Web3Account

Web3Account - this module is a Python client library as the simplest way to use Web3 features

Installation

Install the current version with PyPI:

pip install web3-account

Usage

You can make trasfers like this

from web3_account import *

account = Web3Account(
    "", # your secret key
    "avalanche",
    after_tx_sleeping=False  # after_tx_sleeping - sleep random timing after submitted tx
)

tx_status = account.send_money("0x54C32309b67e72bD44899e46EC630d14Eb96125f", 0.001)

logs.info(f'Tx status: {tx_status}. If it is True - tx complited, else: failed')

On Lib already includes web3 nodes for all popular chains (using Ankr), so, you can change it if it needed

links = {
    "polygon" : ['http://my_custom_node.com']
}

account = Web3Account(
    "", # your secret key
    "polygon", # set up work net_name
    after_tx_sleeping=False,  # after_tx_sleeping - sleep random timing after submitted tx
    nodes=links # our custom links
)

Example of swaps

Lib also include swap* function from 1inch api url

from web3_account import *


account = Web3Account(
    "", # your secret key
    "polygon",
    after_tx_sleeping=False  # after_tx_sleeping - sleep random timing after submitted tx
)

matic_balance = account.get_native_balance()
human_readable_balance = Web3.from_wei(matic_balance, 'ether')

logs.info(f'Balance: {human_readable_balance}')            # print without file logging
account.logger.info(f'Balance: {human_readable_balance}')  # print with file logging

token_out = "0x2297aEbD383787A160DD0d9F71508148769342E3" # btc address


swap_response = account.swap(
    "eth",
    token_out,
    round(matic_balance * 0.1),
    increase_gas_price=3 # increase_gas_price coef of increasing gwei price (for polygon recomended)
) # will buy btc with $matic for 10% of total balance


btcb_balance, human_readable_btb_balance = account.get_balance(token_out)
account.logger.info(f'Have: {human_readable_btb_balance} $btc')

swap_response = account.swap(
    token_out,
    "eth",
    btcb_balance,
    increase_gas_price=3 # increase_gas_price coef of increasing gwei price (for polygon recomended)
) # will sell btc to matic on ALL balance of btc

account.logger.info(f'Swap response: {swap_response}')

Contributing

Bug reports and/or pull requests are welcome

License

The module is available as open source under the terms of the Apache License, Version 2.0

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

web3_account-1.0.1.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file web3_account-1.0.1.tar.gz.

File metadata

  • Download URL: web3_account-1.0.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for web3_account-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7415c53bf3b76683c001a17228bbe40a377c5eecdfc4d53f671e1e485ba82668
MD5 9ef805d96d1ef7de0cacff475ab600af
BLAKE2b-256 d3730bc213a831dbe309a5e423f238968f5346665dc21fde0c3ea0ca0529eb57

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