Skip to main content

Easily send transactions on the Ethereum blockchain and fine tune gas parameters

Project description

eth_transfer

Easily send transactions on the Ethereum blockchain and fine tune gas parameters.

Motivation

The Web3.py python library, Alchemy API, and a slew of other projects provide easy ways to send transactions (exchange of value between addresses). However, there is often a lot of guess work that goes into selecting the values affecting the total gas fee, such as the max priority fee per gas, the max fee per gas, and the maximum amount of gas the user is willing to be consumed for the transaction to succeed. The Etherum network can become very busy at certain times (i.e. days following the FTX bankruptcy) and thus gas fees become very large. User controls on gas on applications such as MetaMask are basic, and give vaugue time estimates when trying to save on gas fees.

This package intends to provide an easy to use and customizable object oriented way to send transactions that minimize gas fees according to your needs.

How to use

The use of this package requires you are able to connect to the Etherum blockchain using web3.py and also have an Etherscan account from which you can create an API key. Access to PRO Etherscan endpoints is not neeeded.

Installing web3

If you do not have the web3 package installed in your environment or virtual environment, follow the quickstart here.

If you do not have an Etherscan account, create one as well as an API key by following the Getting Started steps here.

Quickstart

You can install the eth_transfer package via pip

pip3 install eth_transfer

Sending a Transaction

After you have installed the package, create a Web3 instance using either a local or remote provider. Below, we use the Remote provider Infura.io as an example.

w3 = Web3(Web3.HTTPProvider("https://mainnet.infura.io/v3/YOUR_PROJECT_ID"))

Instantiate an instance of the Tx class

address_1 = SENDING_ADDRESS
address_2 = RECEIVING_ADDRESS

transaction = Tx(w3, address_1, address_2, '0.100 ether', '55 gwei', '1 gwei')

Now, send the transaction

transaction.send_transaction()

Tracking Gas Prices

Instantiate an instance of the GasTracker class. This can be done one of two ways. Both ways are shown below

  • From variable with string of your API key
    etherscan_key = YOUR_ETHERSCAN_KEY
    gastracker = GasTracker.from_key(etherscan_key)
    
  • From env with your API Key
    fpath = FILEPATH_TO_ENV_WITH_API_KEY # e.g. '/Users/DeadBeef/Desktop/etherscan.env'
    key_name = ENV_API_KEY_NAME # e.g. 'API_KEY'
    gastracker = GasTracker.from_env(fpath, key_name)
    
  • Confirmation Times vs. Fee Per Gas

    gas_limit = 50000 # Note: minimum is 21,000 
    gastracker.plot_gas_price_confirmation_time(gas_limit)
    

    Sending a slow transaction

    Sometimes, you can wait for a transaction to be confirmed! If so, you might as well save ETH on it being confirmed. Note, the maximum fee per gas you are willing to pay must exceed the current base fee. This is taken care of for you.

    gastracker.get_safe_gas_price()
    

    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

    eth_transfer-0.0.3.tar.gz (9.0 kB view details)

    Uploaded Source

    Built Distribution

    eth_transfer-0.0.3-py3-none-any.whl (9.1 kB view details)

    Uploaded Python 3

    File details

    Details for the file eth_transfer-0.0.3.tar.gz.

    File metadata

    • Download URL: eth_transfer-0.0.3.tar.gz
    • Upload date:
    • Size: 9.0 kB
    • Tags: Source
    • Uploaded using Trusted Publishing? No
    • Uploaded via: twine/4.0.1 CPython/3.10.6

    File hashes

    Hashes for eth_transfer-0.0.3.tar.gz
    Algorithm Hash digest
    SHA256 5e5dfbeaa70b0a1aa537de061080e6aaa85b2dd707adb82c02a521682c40b25e
    MD5 9235dfbbfa7a0236d8aa6ca9b2718a42
    BLAKE2b-256 0e1b4c24574b7dbd147041e09751283aef1adcc2942c3ef7337fa32bc8e54327

    See more details on using hashes here.

    File details

    Details for the file eth_transfer-0.0.3-py3-none-any.whl.

    File metadata

    File hashes

    Hashes for eth_transfer-0.0.3-py3-none-any.whl
    Algorithm Hash digest
    SHA256 b351d2dfde486ede1c708e3e3d6ec480c2c3c32f5661b193c78c2b621a082d75
    MD5 b274491d17dfa9cd8ed5e95856d18509
    BLAKE2b-256 5a36dfb042855c8f15c5116983460e463df8b9e08d4251c6bae84f05a729b583

    See more details on using hashes here.

    Supported by

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