Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'ConstantinopleState' object has no attribute 'execute_transaction' #1434

Closed
EthdAppNet opened this issue Aug 26, 2019 · 4 comments

Comments

@EthdAppNet
Copy link

  • Version: x.x.x
  • Python: 3.6.8
  • Ubuntu 16
  • pip freeze output
apturl==0.5.2
attrdict==2.0.1
base58==1.0.3
beautifulsoup4==4.4.1
blinker==1.3
Brlapi==0.6.4
cached-property==1.5.1
certifi==2019.6.16
chardet==3.0.4
checkbox-support==0.22
Click==7.0
command-not-found==0.3
cryptography==1.2.3
cytoolz==0.10.0
defer==1.0.6
eth-abi==2.0.0
eth-account==0.4.0
eth-bloom==1.0.3
eth-hash==0.2.0
eth-keyfile==0.5.1
eth-keys==0.2.4
eth-rlp==0.1.2
eth-tester==0.1.0b39
eth-tester-rpc==0.4.0b1
eth-typing==2.1.0
eth-utils==1.6.4
feedparser==5.1.3
guacamole==0.9.2
hexbytes==0.2.0
html5lib==0.999
httplib2==0.9.1
idna==2.8
ipfshttpclient==0.4.12
Jinja2==2.8
json-rpc==1.12.1
jsonschema==2.6.0
language-selector==0.1
louis==2.6.4
lru-dict==1.1.6
lxml==3.5.0
Mako==1.0.3
MarkupSafe==0.23
multiaddr==0.0.8
mypy-extensions==0.4.1
netaddr==0.7.19
oauthlib==1.0.3
onboard==1.2.0
padme==1.1.1
parsimonious==0.8.1
pexpect==4.0.1
Pillow==3.1.2
plainbox==0.25
protobuf==3.9.1
ptyprocess==0.5
py-ecc==1.7.1
py-evm==0.3.0a5
py-solc==3.2.0
pyasn1==0.1.9
pycryptodome==3.8.2
pycups==1.9.73
pycurl==7.43.0
pyethash==0.1.27
pygobject==3.20.0
PyJWT==1.3.0
pyparsing==2.0.3
pysha3==1.0.2
python-apt==1.1.0b1+ubuntu0.16.4.2
python-debian==0.1.27
python-systemd==231
pyxdg==0.25
reportlab==3.3.0
requests==2.22.0
rlp==1.1.0
semantic-version==2.6.0
sessioninstaller==0.0.0
six==1.10.0
system-service==0.3
toolz==0.10.0
trie==1.4.0
ubuntu-drivers-common==0.0.0
ufw==0.35
unattended-upgrades==0.1
unity-scope-calculator==0.1
unity-scope-chromiumbookmarks==0.1
unity-scope-colourlovers==0.1
unity-scope-devhelp==0.1
unity-scope-firefoxbookmarks==0.1
unity-scope-gdrive==0.7
unity-scope-manpages==0.1
unity-scope-openclipart==0.1
unity-scope-texdoc==0.1
unity-scope-tomboy==0.1
unity-scope-virtualbox==0.1
unity-scope-yelp==0.1
unity-scope-zotero==0.1
urllib3==1.25.3
usb-creator==0.3.0
varint==1.0.2
web3==5.0.2
websockets==7.0
Werkzeug==0.15.5
xdiagnose==3.8.4.1
xkit==0.0.0
XlsxWriter==0.7.3

I am trying to deploy smartcontract on python. Everything goes nice except when I call the getter function of smart contract, it throws an error. It replaced the main.py in py-eth already and it solved all initial errors.

import json
from web3 import Web3, HTTPProvider
from solc import compile_standard
w3 = Web3(Web3.HTTPProvider("http://localhost:8545"))
print(w3.eth.blockNumber)

compiled_sol = compile_standard({
"language": "Solidity",

"sources": {
    "Greeter.sol": {
        "content": '''
            pragma solidity ^0.5.11;

            contract Greeter {
              string public greeting;

              constructor() public {
                  greeting = 'Hello';
              }

              function setGreeting(string memory _greeting) public {
                  greeting = _greeting;
              }

              function greet() view public returns (string memory) {
                   return greeting;
               }
             }
           '''
    }
},
"settings":
    {
        "outputSelection": {
            "*": {
                "*": [
                    "metadata", "evm.bytecode"
                    , "evm.bytecode.sourceMap"
                ]
            }
        }
    }

}, "evm_version"='homestead')

w3 = Web3(Web3.EthereumTesterProvider())

bytecode = compiled_sol['contracts']['Greeter.sol']['Greeter']['evm']['bytecode']['object']

abi = json.loads(compiled_sol['contracts']['Greeter.sol']['Greeter']['metadata'])['output']['abi']

Greeter = w3.eth.contract(abi=abi, bytecode=bytecode)

tx_hash = Greeter.constructor().transact()

tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash)

greeter = w3.eth.contract(
address=tx_receipt.contractAddress,
abi=abi
)

greeter.functions.greet().call() //////when I execute this command it throws an error below.

AttributeError: 'ConstantinopleState' object has no attribute 'execute_transaction'

///////output

File "/usr/local/lib/python3.6/dist-packages/web3/contract.py", line 842, in call
**self.kwargs
File "/usr/local/lib/python3.6/dist-packages/web3/contract.py", line 1346, in call_contract_function
return_data = web3.eth.call(call_transaction, block_identifier=block_id)
File "/usr/local/lib/python3.6/dist-packages/eth_utils/functional.py", line 45, in inner
return callback(fn(*args, **kwargs))
File "/usr/local/lib/python3.6/dist-packages/web3/eth.py", line 347, in call
[transaction, block_identifier],
File "/usr/local/lib/python3.6/dist-packages/web3/manager.py", line 94, in request_blocking
response = self._make_request(method, params)
File "/usr/local/lib/python3.6/dist-packages/web3/manager.py", line 81, in _make_request
return request_func(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 50, in apply_formatters
response = make_request(method, params)
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/gas_price_strategy.py", line 18, in middleware
return make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/attrdict.py", line 18, in middleware
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/normalize_errors.py", line 9, in middleware
result = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/usr/local/lib/python3.6/dist-packages/web3/providers/eth_tester/middleware.py", line 300, in middleware
return make_request(method, [filled_transaction] + params[1:])
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/usr/local/lib/python3.6/dist-packages/web3/providers/eth_tester/main.py", line 68, in make_request
response = delegator(self.ethereum_tester, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/providers/eth_tester/defaults.py", line 36, in call_eth_tester
return getattr(eth_tester, fn_name)(*fn_args, **fn_kwargs)
File "/usr/local/lib/python3.6/dist-packages/eth_tester/main.py", line 426, in call
raw_result = self.backend.call(raw_transaction, raw_block_number)
File "/usr/local/lib/python3.6/dist-packages/eth_tester/backends/pyevm/main.py", line 495, in call
block_number,
File "/usr/local/lib/python3.6/dist-packages/eth_tester/backends/pyevm/main.py", line 236, in _execute_and_revert_transaction
computation = state.execute_transaction(transaction)
AttributeError: 'ConstantinopleState' object has no attribute 'execute_transaction'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/init.py", line 5, in
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in
import apt
File "/usr/lib/python3/dist-packages/apt/init.py", line 23, in
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/dist-packages/web3/contract.py", line 842, in call
**self.kwargs
File "/usr/local/lib/python3.6/dist-packages/web3/contract.py", line 1346, in call_contract_function
return_data = web3.eth.call(call_transaction, block_identifier=block_id)
File "/usr/local/lib/python3.6/dist-packages/eth_utils/functional.py", line 45, in inner
return callback(fn(*args, **kwargs))
File "/usr/local/lib/python3.6/dist-packages/web3/eth.py", line 347, in call
[transaction, block_identifier],
File "/usr/local/lib/python3.6/dist-packages/web3/manager.py", line 94, in request_blocking
response = self._make_request(method, params)
File "/usr/local/lib/python3.6/dist-packages/web3/manager.py", line 81, in _make_request
return request_func(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 50, in apply_formatters
response = make_request(method, params)
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/gas_price_strategy.py", line 18, in middleware
return make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/attrdict.py", line 18, in middleware
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/normalize_errors.py", line 9, in middleware
result = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/usr/local/lib/python3.6/dist-packages/web3/providers/eth_tester/middleware.py", line 300, in middleware
return make_request(method, [filled_transaction] + params[1:])
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/usr/local/lib/python3.6/dist-packages/web3/providers/eth_tester/main.py", line 68, in make_request
response = delegator(self.ethereum_tester, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/usr/local/lib/python3.6/dist-packages/web3/providers/eth_tester/defaults.py", line 36, in call_eth_tester
return getattr(eth_tester, fn_name)(*fn_args, **fn_kwargs)
File "/usr/local/lib/python3.6/dist-packages/eth_tester/main.py", line 426, in call
raw_result = self.backend.call(raw_transaction, raw_block_number)
File "/usr/local/lib/python3.6/dist-packages/eth_tester/backends/pyevm/main.py", line 495, in call
block_number,
File "/usr/local/lib/python3.6/dist-packages/eth_tester/backends/pyevm/main.py", line 236, in _execute_and_revert_transaction
computation = state.execute_transaction(transaction)
AttributeError: 'ConstantinopleState' object has no attribute 'execute_transaction'

@kclowes
Copy link
Collaborator

kclowes commented Aug 26, 2019

@MunimShabir I'm not able to reproduce the error you're seeing. I do notice some syntax errors, however. You declare the w3 variable twice (which shouldn't matter in this context, just an observation), and I don't think that evm_version is a valid key in the compile_standard JSON. Feel free to update the code snippet and I can help with troubleshooting if you still need it.

@arjunaskykok
Copy link

@kclowes This is how you can reproduce the issue. I am not sure this is an issue with web3 v5 or eth-tester.

ethereum/eth-tester#167

@arjunaskykok
Copy link

I found the thing that caused this issue. The execute_transaction is removed in a commit in py-evm project: ethereum/py-evm@1992368#diff-2d5d99f4dd8df9b29c7486b27678f9fb

The replacement is apply_transaction method. Fixing this issue is easy. Creating test is a little bit confusing.

By the way, the issue is in eth_tester project, not web3.py project. So I think this issue can be closed.

@kclowes
Copy link
Collaborator

kclowes commented Sep 30, 2019

Thanks for digging into this @arjunaskykok! Closing in favor of ethereum/eth-tester#167

@kclowes kclowes closed this as completed Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants