Skip to main content

Automatic Transaction Machine (ATxM) for Ethereum

Project description

Automatic Tx Machine 🏧

Tests

An async EVM transaction retry machine. Programmatically queue, broadcast, and retrying (speedup) transactions. Transactions are queued and broadcasted in a first-in-first-out (FIFO) order.

The machine is designed to be used in a long-running process, like a server.

Diagram

Installation

pip install atxm

Usage

from eth_account.local import LocalAccount
from web3 import Web3, HTTPProvider
from atxm import AutomaticTxMachine
from twisted.internet import reactor


account = LocalAccount.from_keyfile('path/to/keyfile', 'password')
w3 = Web3(HTTPProvider("http://localhost:8545"))

transaction = {
    'chainId': 80001,
    'to': '0x1234567890123456789012345678901234567890',
    'nonce': 0,
    'value': 0,
    'gas': 21000,
    'maxFeePerGas': '1',
    'maxPriorityFeePerGas': '1',
}

machine = AutomaticTxMachine(w3=w3)
future_tx = machine.queue_transaction(
    signer=account,
    params=transaction,
)

reactor.start()

Features

Futures

The tracker returns a FutureTx instance when a transaction is queued. The FutureTx instance can be used to track the transaction's lifecycle and to retrieve the transaction's receipt when it is finalized.

Retry Strategies

The tracker supports a generic configurable interface for retry strategies (AsynxTxStrategy). These strategies are used to determine when to retry a transaction and how to do so. They can be configured to use any kind of custom context, like gas oracles.

Lifecycle Hooks

Hooks are fired in a dedicated thread for lifecycle events.

  • on_broadcast: When a transaction is broadcasted.
  • on_finalized: When a transaction is finalized.
  • on_fault: When a transaction reverted or another error occurred.
Crash-Tolerance

Internal state is written to a file to help recover from crashes and restarts. Internally caches LocalAccount instances in-memory which in combination with disk i/o is used to recover from async task restarts.

Throttle

There are three rates, work (fast scan), idle (slow scan) and sleep (zero activity). This reduces the use of resources when there are no transactions to track. When a transaction is queued, the machine wakes up and goes to work. When all work is complete it eases into idle mode and eventually goes to sleep.

Event Loop Support

Currently, the machine is designed to work with the Twisted reactor. However, it can be adapted to work with any event loop.

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

atxm-0.3.0.tar.gz (59.6 kB view details)

Uploaded Source

Built Distribution

atxm-0.3.0-py3-none-any.whl (45.4 kB view details)

Uploaded Python 3

File details

Details for the file atxm-0.3.0.tar.gz.

File metadata

  • Download URL: atxm-0.3.0.tar.gz
  • Upload date:
  • Size: 59.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for atxm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d2fbed66045214d85cef1c368fcf20dbc1b48f8f13c398130676f64e6dfa1fe3
MD5 86834ef6c9ba3c0f785184f7fb552f56
BLAKE2b-256 15dae5393af3eff2959c0d0199f61a52b1bb016fc233b2881dbc889fa15011ad

See more details on using hashes here.

File details

Details for the file atxm-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: atxm-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for atxm-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bae5806dd44e77f5aecf41d6b3395654d91453e7e7276382e6ef9158528b2168
MD5 9d10ecadecf8ee9ad4f9fb9aec3e6c7b
BLAKE2b-256 20dcf7d094a75a3d5d8e5591040d082306cc2bfb2a2a0c6405d56c389489769b

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