ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.97k stars 1.7k forks source link

TypeError: Blob data is not supported for legacy transactions. #3342

Closed Nanoforcrypto closed 5 months ago

Nanoforcrypto commented 5 months ago

What happened?

I got this error.

TypeError: Blob data is not supported for legacy transactions.

Code that produced the error

def TransferToMainWallet(MainWalletAddress, File_name, ChainID, Scan_url):
    # wallets = ReadWalletData(File_name)[:16]
    wallets = ReadWalletData(File_name)[:2]
    print(wallets)
    i = 0
    while i < len(wallets):
        WalletAddress = wallets[i][0]
        print(WalletAddress)
        WalletPrivateKey = wallets[i][1]
        # print(WalletPrivateKey)
        account = Account.from_key(WalletPrivateKey)
        # balance_bsc = GetWalletBalance(WalletAddress)
        balance_bsc = GetWalletBalance(WalletAddress) / 10 ** 18
        balance_bsc_float = float(Decimal(balance_bsc).quantize(Decimal("0.00000000")))
        balance_bsc_wei = web3.to_wei(balance_bsc_float, 'ether')
        # balance_bsc_wei = web3.toWei(0.001, 'ether')
        nonce = web3.eth.get_transaction_count(WalletAddress) + i + 30 # 获取nonce
        print(f'nonce {nonce}')
        print(f'balance_bsc_wei {balance_bsc_wei},type{type(balance_bsc_wei)}')
        if balance_bsc_wei != 0:

            gas_price = web3.to_wei('1', 'gwei')  # gas price
            gas_limit = 21000  # gas limit
            print(f'gas {gas_limit * gas_price}')
            send_value = balance_bsc_wei - gas_limit * gas_price
            print(f'send_value {send_value}')

            if send_value > gas_limit * gas_price:
                # 创建交易
                txn = {
                    'chainId': ChainID,
                    # 'chainId': 56,
                    'nonce': nonce,
                    'to': MainWalletAddress,
                    'value': send_value,
                    'gas': gas_limit,
                    'gasPrice': gas_price,
                }
                # 签名交易
                signed_txn = account.sign_transaction(txn, WalletPrivateKey)
                # print(signed_txn)
                # 发送交易
                txn_hash = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
                print(Scan_url + txn_hash.hex())
        i += 1

Full error output

Traceback (most recent call last):
  File "C:\Users\Administrator\PycharmProjects\pythonProject\Tugou_Trading_Ctrl\BSC_ERC314_Tools\main_ctrl.py", line 37, in <module>
    TransferToMainWallet(MainWalletAddress, File_name, ChainID, Scan_url)
  File "C:\Users\Administrator\PycharmProjects\pythonProject\Tugou_Trading_Ctrl\BSC_ERC314_Tools\Each_function\Transfer_1_BNBToWallets.py", line 156, in TransferToMainWallet
    signed_txn = account.sign_transaction(txn, WalletPrivateKey)
  File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\eth_account\signers\local.py", line 84, in sign_transaction
    return self._publicapi.sign_transaction(transaction_dict, self.key, blobs=blobs)
  File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\eth_utils\decorators.py", line 31, in _wrapper
    return self.method(objtype, *args, **kwargs)
  File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\eth_account\account.py", line 794, in sign_transaction
    ) = sign_transaction_dict(account._key_obj, sanitized_transaction, blobs=blobs)
  File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\eth_account\_utils\signing.py", line 32, in sign_transaction_dict
    unsigned_transaction = serializable_unsigned_transaction_from_dict(
  File "C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\eth_account\_utils\legacy_transactions.py", line 46, in serializable_unsigned_transaction_from_dict
    raise TypeError("Blob data is not supported for legacy transactions.")
TypeError: Blob data is not supported for legacy transactions.

Fill this section in if you know how this could or should be fixed

No response

web3 Version

6.15.0

Python Version

3.9

Operating System

win 10

Output from pip freeze

2captcha-python==1.2.2
absl-py==1.3.0
aiohttp==3.8.1
aiosignal==1.2.0
altgraph==0.17.2
annotated-types==0.6.0
APScheduler==3.6.3
astunparse==1.6.3
async-generator==1.10
async-timeout==4.0.2
attrs==23.2.0
autobahn==22.7.1
Automat==22.10.0
base58==2.1.1
beautifulsoup4==4.11.1
binance-connector==1.2.0
binance-connector-python==0.6.0
bitarray==2.6.0
blinker==1.7.0
Brotli==1.1.0
cachetools==4.2.2
capsolver==1.0.7
certifi==2022.9.14
cffi==1.15.1
charset-normalizer==2.0.12
chromedriver-autoinstaller==0.6.4
ckzg==1.0.0
click==8.1.3
cloudscraper==1.2.71
colorama==0.4.6
constantly==15.1.0
contourpy==1.0.6
cryptography==42.0.4
curl-cffi==0.5.7
cycler==0.11.0
Cython==0.29.32
cytoolz==0.12.0
decouple==0.0.7
dnspython==2.3.0
ecdsa==0.18.0
et-xmlfile==1.1.0
eth-account==0.11.2
eth-hash==0.7.0
eth-keyfile==0.8.0
eth-keys==0.5.0
eth-rlp==1.0.1
eth-typing==4.1.0
eth-utils==4.1.0
eth_abi==5.1.0
eventlet==0.33.3
exceptiongroup==1.0.0rc9
Flask==2.2.2
flatbuffers==22.10.26
fonttools==4.38.0
frozenlist==1.3.1
func-timeout==4.3.5
future==0.18.2
gast==0.4.0
google-auth==2.14.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
greenlet==2.0.2
grpcio==1.50.0
h11==0.14.0
h2==4.1.0
h5py==3.7.0
hexbytes==0.3.0
hpack==4.0.0
html5lib==1.1
hyperframe==6.0.1
hyperlink==21.0.0
idna==3.4
importlib-metadata==5.0.0
incremental==22.10.0
ipfshttpclient==0.8.0a2
itsdangerous==2.1.2
Jinja2==3.1.2
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
kaitaistruct==0.10
keras==2.10.0
keras-nightly==2.12.0.dev2022110607
Keras-Preprocessing==1.1.2
kiwisolver==1.4.4
libclang==14.0.6
lru-dict==1.1.8
lxml==4.9.1
Markdown==3.4.1
MarkupSafe==2.1.1
matplotlib==3.6.2
multiaddr==0.0.9
multidict==6.0.2
netaddr==0.8.0
numpy==1.20.0
oauthlib==3.2.2
opencv-python==4.6.0.66
openpyxl==3.1.1
opt-einsum==3.3.0
outcome==1.2.0
packaging==23.2
pandas==1.1.5
parsimonious==0.10.0
pefile==2022.5.30
Pillow==9.3.0
protobuf==5.26.1
pyaes==1.6.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pycryptodome==3.15.0
pydantic==2.6.4
pydantic_core==2.16.3
pyDes==2.0.1
pydivert==2.1.0
pygame==2.5.2
pyhttpx==2.10.12
pyinstaller==6.4.0
pyinstaller-hooks-contrib==2024.2
PyMouse==1.0
PyMySQL==1.0.2
pyOpenSSL==24.0.0
pyparsing==3.0.9
pyperclip==1.8.2
PyQt5==5.15.4
pyqt5-plugins==5.15.4.2.2
PyQt5-Qt5==5.15.2
PyQt5-sip==12.11.0
PyQt5-stubs==5.15.6.0
pyqt5-tools==5.15.4.3.2
pyqtgraph==0.13.1
pyrsistent==0.18.1
pysha3==1.0.2
PySide6==6.4.0
PySide6-Addons==6.4.0
PySide6-Essentials==6.4.0
PySocks==1.7.1
python-dateutil==2.8.2
python-dotenv==0.21.0
python-socks==2.0.3
python-telegram-bot==13.15
pytz==2022.2.1
pytz-deprecation-shim==0.1.0.post0
pyunormalize==15.1.0
pywin32==304
pywin32-ctypes==0.2.2
QDarkStyle==3.1
qt-material==2.12
qt5-applications==5.15.2.2.2
qt5-tools==5.15.2.1.2
QtPy==2.2.1
referencing==0.34.0
regex==2023.12.25
requests==2.27.1
requests-oauthlib==1.3.1
requests-toolbelt==1.0.0
rlp==4.0.0
rpds-py==0.18.0
rsa==4.8
scipy==1.9.3
selenium==4.18.1
selenium-wire==5.1.0
service-identity==21.1.0
shiboken6==6.4.0
six==1.16.0
sniffio==1.3.0
sortedcontainers==2.4.0
soupsieve==2.3.2.post1
tb-nightly==2.11.0a20221105
Telethon==1.25.2
tensorboard==2.10.1
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==2.10.0
tensorflow-estimator==2.10.0
tensorflow-gpu==2.10.0
tensorflow-io-gcs-filesystem==0.27.0
termcolor==2.1.0
tf-estimator-nightly==2.12.0.dev2022110608
tf-nightly==2.12.0.dev20221105
tf_nightly_intel==2.12.0.dev20221105
toolz==0.12.0
torch==1.13.0+cu117
torchvision==0.14.0
tornado==6.1
trio==0.22.0
trio-websocket==0.9.2
Twisted==22.10.0
twisted-iocpsupport==1.0.2
txaio==22.2.1
wordlists==1.0.0
wrapt==1.14.1
wsproto==1.2.0
yarl==1.8.1
zipp==3.10.0
zope.interface==5.5.2
zstandard==0.22.0
fselmo commented 5 months ago

account.sign_transaction() doesn't take a private key since the account object has the private key. You just need to pass in the transaction.

account.sign_transaction(txn)