gpt4 book ai didi

python - Web3py send_raw_transaction ValueError : {'message' : 'invalid remainder' , 'code' : -32000}

转载 作者:行者123 更新时间:2023-12-05 05:50:36 25 4
gpt4 key购买 nike

我正在尝试开始使用 ethereum platfrom 和 web3py。我想调用智能合约,建立交易,签署并发送。

实体代码:

pragma solidity ^0.5.0;

contract UselessWorker {

int public successfullyExecutedIterations = 0;
bytes32 public hash = '';

function doWork(int _iterations) public {
successfullyExecutedIterations = _iterations;
for (int i = 0; i < _iterations; i++)
{
hash = keccak256("ABC");
}
}

}

还有我的 python 代码:

from web3 import Web3

web3 = Web3(Web3.HTTPProvider('http://127.0.0.1:7545'))

abi = json.loads('''...''')
contract_address = '0xF0af88Da01E12D49d12300487DDa6E9C6b809AA2'

user_address = '0x348C8455A4C87849A6cd5D1E1bF397291378b51C'
private_key = 'bbd61e7e879cfa63bbdd1202bcc8ff25e4a54a08db3848ebffcc36ffbee6cd45'

contract = web3.eth.contract(address=web3.toChecksumAddress(contract_address), abi=abi)
transaction = contract.functions.doWork(555).buildTransaction({
'gas': 200000,
'maxFeePerGas': web3.toWei('100', 'gwei'),
'maxPriorityFeePerGas': web3.toWei('50', 'gwei'),
'nonce': web3.eth.get_transaction_count(user_address),
'from': user_address,
})

signed_txn = web3.eth.account.sign_transaction(transaction, private_key=private_key)
web3.eth.send_raw_transaction(signed_txn.rawTransaction)

每次我尝试运行此代码时都会出现异常。我该如何解决这个问题?

Traceback (most recent call last):
File "D:\Projects\Python\web3\main.py", line 107, in <module>
web3.eth.send_raw_transaction(signed_txn.rawTransaction)
File "D:\Program files\Python 310\lib\site-packages\web3\eth.py", line 722, in send_raw_transaction
return self._send_raw_transaction(transaction)
File "D:\Program files\Python 310\lib\site-packages\web3\module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "D:\Program files\Python 310\lib\site-packages\web3\manager.py", line 198, in request_blocking
return self.formatted_response(response,
File "D:\Program files\Python 310\lib\site-packages\web3\manager.py", line 171, in formatted_response
raise ValueError(response["error"])
ValueError: {'message': 'invalid remainder', 'code': -32000, 'data': {'stack': 'Error: invalid remainder\n at Object.decode (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\rlp\\src\\index.ts:75:11)\n at StateManager.queueRawTransaction (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\statemanager.js:298:29)\n at GethApiDouble.eth_sendRawTransaction (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\geth_api_double.js:338:14)\n at GethApiDouble.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\geth_api_double.js:109:10)\n at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n at GethDefaults.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\gethdefaults.js:15:12)\n at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n at SubscriptionSubprovider.FilterSubprovider.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\subproviders\\filters.js:89:7)\n at SubscriptionSubprovider.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\subproviders\\subscriptions.js:137:49)\n at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n at DelayedBlockFilter.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\delayedblockfilter.js:31:3)\n at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n at RequestFunnel.handleRequest (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\lib\\subproviders\\requestfunnel.js:32:12)\n at next (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:136:18)\n at Web3ProviderEngine._handleAsync (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:123:3)\n at Timeout._onTimeout (C:\\Program Files\\WindowsApps\\GanacheUI_2.5.4.0_x64__5dg5pnz03psnj\\app\\resources\\static\\node\\node_modules\\ganache-core\\node_modules\\web3-provider-engine\\index.js:107:12)', 'name': 'Error'}}

最佳答案

在您的交易中设置“chainId”。我遇到了同样的问题,然后我设置了“chainId”,它起作用了

关于python - Web3py send_raw_transaction ValueError : {'message' : 'invalid remainder' , 'code' : -32000},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70498188/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com