ApeWorX / ApeWorX/web3.py

A transaction class that can encode and decode from an RPC transaction dict

Open
#3,534 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
5.5k
Forks
1.7k
Avg merge
3d 10h
Merged PRs (30d)
2

Description

### What feature should we add?

There should be an easy way to take a transaction directly as a JSON-RPC dict and put it into an object that can `encode()` and `decode()` the transaction. This would behave much like the `TypedTransaction` class does for typed transactions in *eth-account* - and in fact this class can probably carry a lot of the heavy load here - but it also needs to clean up certain fields based on the type in order for it to even be plugged into the `TypedTransaction` class.

I'm thinking something like:

```py
>>> from web3.utils import Web3Transaction

>>> # from dict
>>> txn = Web3Transaction.from_dict(w3.eth.get_transaction("0x..."))
>>> txn.encode().hex()
02ed01808504a817c8008504a817c800830186a09400000000000000000000000000000000000000008080c0808080...

>>> # from bytes
>>> txn = Web3Transaction.from_bytes(b'\x02\xed\x01\x80\x85\x04\xa8\x17\xc8\x00\x85\x04\xa8\x17\xc8\x00\x83\x01\x86\xa0\x94\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x80\xc0\x80\x80\x80')
>>> txn.as_dict()
{
"chainId": 1,
"maxFeePerGas": 20000000000,
"maxPriorityFeePerGas": 20000000000,
"nonce": 0,
...
}

>>> # fields accessible as properties
>>> txn.max_fee_per_gas
20000000000
```

Or, maybe it's a `HexBytes` as the result of `encode()`. Either way, I think the utility here is fairly clear. Take a transaction straight from a result, put it into a utility class, and be able to manipulate and have useful methods available on the transaction.
```[tasklist]
### Tasks
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.