Ethereumjs

交易失敗(Tx 在 Remix 中成功)

  • July 14, 2018

嘗試執行以下契約時交易失敗:

pragma solidity ^0.4.23;
 pragma experimental ABIEncoderV2;
 contract state {    
     uint256 contract_version = 1;
     function set_version(uint256 cv_n) public {
               contract_version = cv_n;
     }
     function get_version() public view returns (uint256) {
               return contract_version;
     }
 }
 contract complicated {
    state st;
    constructor() public {
           address st_address = new state();
           st = state(st_address);
    }
    function set_version(uint256 cv_n) public {
           st.set_version(cv_n);
    }
    function get_version() public view returns (uint256) {
           return st.get_version();
    }
 }

為了使用solidity執行合約,我使用了從範例中派生的以下程式碼:

compiled_sol = compile_source(contract_source_code) # Compiled source code
contract_interface = compiled_sol['<stdin>:complicated']


w3 = Web3(Web3.TestRPCProvider())

w3.eth.defaultAccount = w3.eth.accounts[0]


Greeter = w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])

tx_hash = Greeter.constructor().transact()

tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)

greeter = w3.eth.contract(
   address=tx_receipt.contractAddress,
   abi=contract_interface['abi']
)

tx_hash = greeter.functions.set_version(10).transact()

w3.eth.waitForTransactionReceipt(tx_hash)

print('Updated contract greeting: {}'.format(
   greeter.functions.get_version().call()
))

使用 Web3py 我收到以下錯誤消息:

ValueError: {‘code’: -32000, ‘message’: ‘伺服器錯誤’, ‘data’: {’type’: ‘TransactionFailed’, ‘args’:

$$ $$, ‘資訊’: ‘’}}

當我導入聯繫人以重新混合契約時,它可以完美執行

已編譯溶膠 = 編譯源(契約原始碼)

將上面的程式碼更改為以下內容:

compiled_sol = compile_source(contract_source_code, evm_version='homestead')

0.4.22 之後的 Solidity 版本引入了兩個新的操作碼,這在導致 TransactionFailed 錯誤的 pyethereum 中沒有實現。要了解更多資訊,請閱讀這篇文章

引用自:https://ethereum.stackexchange.com/questions/53367