尝试将eth从一个合同转移到另一个合同,但总是抱怨错误

问题描述

这是要调用函数

function hackContract(address payable account) public {
    //crowdsaleAddr = account;
    uint256 totalReceived = address(this).balance;
    account.transfer(totalReceived);
    emit PaymentReleased(account,totalReceived);
}

这就是我在python中称呼它们的原因

def SendETHToCrowdSale(amount):
    w3.eth.defaultAccount = accounts[1]
    amount_in_wei = w3.toWei(amount,'ether');
    print("amount_in_wei:",amount_in_wei)
    tx_hash = hack_contract.functions.hackContract(crowdsale_contract_address)
    tx_hash = tx_hash.transact()
    # Wait for transaction to be mined...
    w3.eth.waitForTransactionReceipt(tx_hash)

它总是抱怨:

c:\users\hchen\appdata\local\programs\python\python36-32\lib\site-packages\web3\manager.py in request_blocking(self,method,params)
110 
111         if "error" in response:
--> 112             raise ValueError(response["error"])
113 
114         return response['result']

ValueError: {'message': 'VM Exception while processing transaction: revert','code': -32000,'data': {'0xbf82fa5542895624ea4017633ee36983a494d959a46e69d7bea4120e02d3a246': {'error': 'revert','program_counter': 562,'return': '0x'},'stack': 'Error\n    at Function.RuntimeError.fromresults (C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\lib\\utils\\runtimeerror.js:89:13)\n    at C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\lib\\blockchain_double.js:611:28\n    at C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async\\internal\\once.js:12:16\n    at replenish (C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async\\internal\\eachOfLimit.js:61:25)\n    at C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async\\internal\\eachOfLimit.js:71:9\n    at eachLimit (C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async\\eachLimit.js:43:36)\n    at C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async\\internal\\doLimit.js:9:16\n    at VM.AsyncEventEmitter.emit (C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async-eventemitter\\lib\\AsyncEventEmitter.js:42:3)\n    at afterBlock (C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\ethereumjs-vm\\dist\\runBlock.js:75:10)\n    at C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\ethereumjs-vm\\dist\\runBlock.js:252:9\n    at C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\ethereumjs-vm\\dist\\stateManager.js:387:5\n    at C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async\\dist\\async.js:969:16\n    at next (C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async\\dist\\async.js:5225:18)\n    at C:\\Program Files\\WindowsApps\\Ganache_2.0.3.0_x64__zh355ej5cj694\\app\\resources\\app.asar\\node_modules\\ganache-core\\node_modules\\async\\dist\\async.js:119:16\n    at _combinedTickCallback (internal/process/next_tick.js:131:7)\n    at process._tickCallback (internal/process/next_tick.js:180:9)','name': 'RuntimeError'}}

我已将足够的eth转移到此合同中,以确保它有足够的钱。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)