Невозможно отправить транзакцию с помощью web3.py (метод send_raw_transaction)Python

Программы на Python
Anonymous
Невозможно отправить транзакцию с помощью web3.py (метод send_raw_transaction)

Сообщение Anonymous »

Я тестирую web3.py, пытаясь отправить eth из одной учетной записи в другую, используя метод send_raw_transaction.
Я использую Ganache для целей тестирования.
На самом деле, я просто следую инструкциям шаги описаны в документе web3.
Однако каждый раз получаю ошибку.
Похоже, проблема в методе send_raw_transaction.
Код:

Код: Выделить всё

from web3 import Web3
from web3.middleware import geth_poa_middleware
import json

#   GANACHE. TESTING TRANSACTIONS
ganache_url = "http://127.0.0.1:7545"
w3 = Web3(Web3.HTTPProvider(ganache_url))

#   accs and keys
account_1 = "0x72e94DaE4d186639B9Bb2baA89caa4Da5f931231"
account_2 = "0xaB2fF898c56a43f56845180081A0C467f2640332"
privatekey_1 = "0x5af8420db3d42b3fc14a13f64dd8dd490783746fdea406ac68afc9b3b9e51132"

#   getting eth balance
balance_gwei = w3.eth.get_balance(account_1)
k = 10 ** 18
balance_eth = balance_gwei/k

nonce = w3.eth.get_transaction_count(account_1)

tx = {
"nonce": nonce,
"to":   account_2,
"value":    w3.to_wei(1, "ether"),
"gas":  20000000000,
"gasPrice": w3.to_wei("50", "gwei"),
}

print(balance_eth)
signed_tx = w3.eth.account.sign_transaction(tx, privatekey_1)
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
print(balance_eth)
Итак, вот терминал:

Код: Выделить всё

(venv) PS C:\Users\Kirill\Desktop\PYTHON\CRYPTO_PAYMENTS_PYTHON> python main.py

100.0
Traceback (most recent call last):
File "C:\Users\Kirill\Desktop\PYTHON\CRYPTO_PAYMENTS_PYTHON\main.py", line 34, in 
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Kirill\Desktop\PYTHON\CRYPTO_PAYMENTS_PYTHON\venv\Lib\site-packages\web3\eth\eth.py", line 396, in send_raw_transaction
return self._send_raw_transaction(transaction)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Kirill\Desktop\PYTHON\CRYPTO_PAYMENTS_PYTHON\venv\Lib\site-packages\web3\module.py", line 75, in caller
result = w3.manager.request_blocking(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Kirill\Desktop\PYTHON\CRYPTO_PAYMENTS_PYTHON\venv\Lib\site-packages\web3\manager.py", line 330, in request_blocking
return self.formatted_response(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Kirill\Desktop\PYTHON\CRYPTO_PAYMENTS_PYTHON\venv\Lib\site-packages\web3\manager.py", line 293, in formatted_response
raise ValueError(error)
ValueError: {'message': 'exceeds block gas limit', 'stack': 'Error: exceeds block gas limit\n    at TransactionPool. (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:120454)\n    at TransactionPool.prepareTransaction (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:120796)\n    at TransactionManager.add (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:138284)\n    at Blockchain.queueTransaction (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:70776)\n    at EthereumApi.eth_sendRawTransaction (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:88213)\n    at EthereumApi.n.value (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:238968)\n    at Object.execute (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:165607)\n    at RequestCoordinator. (C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:165421)\n    at C:\\Program Files\\WindowsApps\\GanacheUI_2.7.1.0_x64__rb4352f0jd4m2\\app\\resources\\static\\node\\node_modules\\ganache\\dist\\node\\1.js:2:165687\n    at new Promise ()', 'code': -32000}
d в документе web3.

Подробнее здесь: https://stackoverflow.com/questions/788 ... ion-method

Вернуться в «Python»