ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.98k stars 1.7k forks source link

TypeError: sign_transaction() takes 2 positional arguments but 3 were given #2030

Closed jjhesk closed 3 years ago

jjhesk commented 3 years ago
0x-contract-addresses==3.0.0
0x-contract-artifacts==3.0.0
0x-contract-wrappers==2.0.0
0x-json-schemas==2.1.0
0x-order-utils==4.0.0
abi.tools.uigenerator==0.2.0
Adafruit-GPIO==1.0.3
Adafruit-PureIO==1.1.8
aiohttp==3.7.4.post0
altgraph==0.17
aniso8601==9.0.1
apipkg==1.5
appdirs==1.4.4
asttokens==2.0.4
async-timeout==3.0.1
attrdict==2.0.1
attrs==21.2.0
AutoChromedriver==2.2.1
autoflake==1.4
b64==0.4
base58==2.1.0
bcrypt==3.2.0
beautifulsoup4==4.9.3
bitarray==1.2.2
black==21.6b0
bleach==3.2.1
boto==2.49.0
boto3==1.15.2
browser-cookie3==0.11.2
bs4==0.0.1
cached-properties==0.7.4
cachetools==4.1.1
cbox==0.5.0
certifi==2020.6.20
cffi==1.14.3
chardet==3.0.4
click==8.0.1
colorama==0.4.3
colorclass==2.2.0
configparser==5.0.1
coverage==5.5
cryptography==3.1.1
cryptowatch==0.0.11
cx-Freeze==6.6
cytoolz==0.11.0
Deprecated==1.2.10
desert==2020.11.18
distlib==0.3.2
docutils==0.16
easygui==0.98.2
ecdsa==0.16.1
et-xmlfile==1.0.1
eth-abi==2.1.1
eth-account==0.5.4
eth-brownie==1.14.5
eth-event==1.2.3
eth-hash==0.3.1
eth-keyfile==0.5.1
eth-keys==0.3.3
eth-rlp==0.2.1
eth-typing==2.2.2
eth-utils==1.10.0
execnet==1.8.1
fabric==2.5.0
filelock==3.0.12
flake8==3.9.2
Flask==1.1.2
flask-restplus==0.13.0
funcsigs==1.0.2
future==0.18.2
githubrelease==1.5.8
google-api-core==1.23.0
google-api-python-client==1.12.5
google-auth==1.23.0
google-auth-httplib2==0.0.4
google-auth-oauthlib==0.4.1
googleapis-common-protos==1.52.0
googlesheettranslate==2.11.27
gspread==3.6.0
hexbytes==0.2.1
htmlmin==0.1.12
httplib2==0.18.1
hypothesis==5.41.3
idna==2.10
importlib-metadata==3.10.0
importlib-resources==5.1.2
inflection==0.5.0
iniconfig==1.1.1
install==1.3.4
invoke==1.4.1
ipfshttpclient==0.7.0
itsdangerous==1.1.0
Jinja2==2.11.3
jmespath==0.10.0
jsonschema==3.2.0
keyring==21.4.0
keyrings.alt==4.0.2
LinkHeader==0.4.3
logger==1.4
lru-dict==1.1.7
lxml==4.5.2
lz4==3.1.0
macholib==1.14
Mako==1.1.3
Markdown==3.2.2
MarkupSafe==1.1.1
marshmallow==3.11.1
mccabe==0.6.1
mnemonic==0.19
mock==4.0.3
modulegraph==0.18
more-itertools==8.7.0
multiaddr==0.0.9
multidict==5.1.0
mypy-extensions==0.4.3
mythx-cli==0.6.22
mythx-models==1.9.1
netaddr==0.8.0
numpy==1.20.2
oauth2client==4.1.3
oauthlib==3.1.0
openpyxl==3.0.7
packaging==20.4
pandas==1.2.3
paramiko==2.7.2
parsimonious==0.8.1
pathspec==0.8.1
pbkdf2==1.3
pdoc3==0.9.1
pefile==2021.5.13
pendulum==2.1.2
pep8==1.7.1
pkginfo==1.5.0.1
plotmanx==0.4.24
pluggy==0.13.1
prometheus-client==0.10.1
prompt-toolkit==3.0.8
protobuf==3.17.1
psutil==5.8.0
pure-interface==4.0.2
py==1.10.0
py-solc-ast==1.2.8
py-solc-x==1.1.0
py2app==0.24
py2exe==0.9.2.2
pyaes==1.6.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pybars3==0.9.7
pycodestyle==2.7.0
pycoin==0.90.20190728
pycparser==2.20
pycryptodome==3.10.1
pyfakefs==4.4.0
pyflakes==2.3.1
pygame==2.0.1
Pygments==2.7.1
pygments-lexer-solidity==0.5.1
PyInstaller==3.3.1
PyJWT==1.7.1
PyMeta3==0.5.1
PyMySQL==0.10.1
PyNaCl==1.4.0
pyngrok==5.0.3
pyparsing==2.4.7
PyQt5==5.15.3
PyQt5-Qt==5.15.2
PyQt5-sip==12.8.1
PyQtWebEngine==5.15.3
PyQtWebEngine-Qt==5.15.2
pyrsistent==0.17.3
PySide2==5.15.1
PySocks==1.7.1
pytest==6.2.4
pytest-asyncio==0.15.1
pytest-cache==1.0
pytest-cov==2.12.0
pytest-forked==1.3.0
pytest-mock==3.6.0
pytest-pep8==1.0.6
pytest-xdist==1.34.0
python-coveralls==2.9.3
python-dateutil==2.8.1
python-dotenv==0.16.0
python-gnupg==0.4.6
python-parsetime==2.0.7
pythx==1.6.1
pytz==2021.1
pytzdata==2020.1
PyYAML==5.4.1
readme-renderer==26.0
regex==2021.4.4
requests==2.25.1
requests-mock==1.9.3
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
rfc3986==1.4.0
rlp==2.0.1
rsa==4.6
rusty-rlp==0.1.15
s3transfer==0.3.3
selenium==3.141.0
semantic-version==2.8.5
setuptools-scm==6.0.1
shiboken2==5.15.1
shutils==0.1.0
six==1.16.0
smart-open==2.1.1
socks==0
solc==0.0.0a0
solc-select==0.2.0
sortedcontainers==2.3.0
soupsieve==2.2.1
stringcase==1.2.0
sultan==0.9.1
tabulate==0.8.7
terminaltables==3.1.0
texttable==1.6.3
tiktok-scraper==1.0.3
toml==0.10.2
toolz==0.11.1
tornado==6.1
tox==3.23.1
tqdm==4.49.0
troncli==1.0.6
tronpytool==3.6.54
trx-utils==1.0.4
twine==3.2.0
typed-ast==1.4.2
typing==3.7.4.3
typing-extensions==3.10.0.0
typing-inspect==0.6.0
ujson==4.0.2
uritemplate==3.0.1
urllib3==1.26.5
varint==1.0.2
virtualenv==20.4.7
vvm==0.1.0
vyper==0.2.12
wcwidth==0.2.5
web3==5.12.1
webencodings==0.5.1
websocket-client==0.58.0
websockets==9.1
Werkzeug==1.0.1
wrapt==1.12.1
xlrd==2.0.1
XlsxWriter==1.4.3
yarl==1.6.3
youtube-dl==2020.9.20
zipp==3.4.1

trying to run the sample code from deploy a contract but it gives me an error

   nr = self.w3.eth.contract(abi=solc.abi, bytecode=solc.bin)
        print("===popop===")
        # key = '0xmykey'
        # self.w3.eth.sendRawTransaction(signed.rawTransaction)
        _transaction = nr.constructor().buildTransaction()
        _transaction['nonce'] = self.w3.eth.getTransactionCount(self.accountAddr)
        _transaction['to'] = None
        # Get correct transaction nonce for sender from the node
        print(_transaction)
        print(self._key)
        signed = self.w3.eth.account.sign_transaction(_transaction, self._key)
        txHash = self.w3.eth.sendRawTransaction(signed.rawTransaction)
        # print(f"Contract '{class_name}' deployed; Waiting to transaction receipt")
        tx_receipt = self.w3.eth.waitForTransactionReceipt(txHash)

What was wrong?

TypeError: sign_transaction() takes 2 positional arguments but 3 were given

Output:

Traceback (most recent call last): File "/Users/hesdx/Documents/b95/dao/testdem.py", line 13, in meta.deploy("ERC20") File "/Users/hesdx/Documents/b95/dao/MetaWrap.py", line 297, in deploy signed = self.w3.eth.account.sign_transaction(_transaction, self._key) TypeError: sign_transaction() takes 2 positional arguments but 3 were given {'value': 0, 'gas': 508151, 'gasPrice': 10000000000, 'chainId': 97, 'data': '0x608060405261083b806100136000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c806370a082311161005b57806370a0823114610149578063a457c2d71461016f578063a9059cbb1461019b578063dd62ed3e146101c757610088565b8063095ea7b31461008d57806318160ddd146100cd57806323b872dd146100e7578063395093511461011d575b600080fd5b6100b9600480360360408110156100a357600080fd5b506001600160a01b0381351690602001356101f5565b604080519115158252519081900360200190f35b6100d5610212565b60408051918252519081900360200190f35b6100b9600480360360608110156100fd57600080fd5b506001600160a01b03813581169160208101359091169060400135610218565b6100b96004803603604081101561013357600080fd5b506001600160a01b0381351690602001356102a5565b6100d56004803603602081101561015f57600080fd5b50356001600160a01b03166102f9565b6100b96004803603604081101561018557600080fd5b506001600160a01b038135169060200135610314565b6100b9600480360360408110156101b157600080fd5b506001600160a01b038135169060200135610382565b6100d5600480360360408110156101dd57600080fd5b506001600160a01b0381358116916020013516610396565b60006102096102026103c1565b84846103c5565b50600192915050565b60025490565b60006102258484846104b1565b61029b846102316103c1565b61029685604051806060016040528060288152602001610771602891396001600160a01b038a1660009081526001602052604081209061026f6103c1565b6001600160a01b03168152602081019190915260400160002054919063ffffffff61060d16565b6103c5565b5060019392505050565b60006102096102b26103c1565b8461029685600160006102c36103c1565b6001600160a01b03908116825260208083019390935260409182016000908120918c16815292529020549063ffffffff6106a416565b6001600160a01b031660009081526020819052604090205490565b60006102096103216103c1565b84610296856040518060600160405280602581526020016107e2602591396001600061034b6103c1565b6001600160a01b03908116825260208083019390935260409182016000908120918d1681529252902054919063ffffffff61060d16565b600061020961038f6103c1565b84846104b1565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b3390565b6001600160a01b03831661040a5760405162461bcd60e51b81526004018080602001828103825260248152602001806107be6024913960400191505060405180910390fd5b6001600160a01b03821661044f5760405162461bcd60e51b81526004018080602001828103825260228152602001806107296022913960400191505060405180910390fd5b6001600160a01b03808416600081815260016020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b0383166104f65760405162461bcd60e51b81526004018080602001828103825260258152602001806107996025913960400191505060405180910390fd5b6001600160a01b03821661053b5760405162461bcd60e51b81526004018080602001828103825260238152602001806107066023913960400191505060405180910390fd5b61057e8160405180606001604052806026815260200161074b602691396001600160a01b038616600090815260208190526040902054919063ffffffff61060d16565b6001600160a01b0380851660009081526020819052604080822093909355908416815220546105b3908263ffffffff6106a416565b6001600160a01b038084166000818152602081815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b6000818484111561069c5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015610661578181015183820152602001610649565b50505050905090810190601f16801561068e5780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b6000828201838110156106fe576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b939250505056fe45524332303a207472616e7366657220746f20746865207a65726f206164647265737345524332303a20617070726f766520746f20746865207a65726f206164647265737345524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a207472616e736665722066726f6d20746865207a65726f206164647265737345524332303a20617070726f76652066726f6d20746865207a65726f206164647265737345524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa265627a7a723158208d87f41af91b455fd29e2d7e743aad9a38560403f42535ed59e51a49265c2f9764736f6c634300050f0032', 'to': None, 'nonce': 0} 9e7c571d4cdce0589fbe06310e96080a8ced874efae38eefb69ed748c6c20f6a

How can it be fixed?

Fill this section in if you know how this could or should be fixed.

fselmo commented 3 years ago

Hi @jjhesk. I tried to reproduce this today in a few different ways and I was not able to. I'm assuming this is in a method within a class since you have self references to the object. Have you tried breaking this down into a simpler form and interacting with the library directly first before making an OOP abstraction? It might help to debug your situation without knowing any more of the inner workings of your class.

I would maybe suggest using a fresh python virtual environment with a fresh install of web3 and interacting with your contract in a bit simpler way and abstracting from there if that works.

The following can be used as a guide to test while running geth in dev mode, thus connecting to http://127.0.0.1:8545.

run geth in dev mode from a new terminal window:

$ geth --http --dev

Get your abi and bytecode from your compiled solidity the way you currently are (using solc). It doesn't look like you are having issues within this part. Put your working code for extracting those values below and test this:

from web3 import Web3

# Get your compiled solidity however you are getting it, extracting `abi` and `bytecode`...
# This part seems to be working for you.

w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))

your_contract = w3.eth.contract(abi={abi}, bytecode={bin})

_transaction = your_contract.constructor().buildTransaction()

acct = w3.eth.account.create()

_transaction['nonce'] = w3.eth.getTransactionCount(acct.address)
_transaction['to'] = None
_transaction['from'] = acct.address

signed = w3.eth.account.sign_transaction(_transaction, acct.key)
txHash = w3.eth.send_raw_transaction(signed.rawTransaction)

tx_receipt = w3.eth.waitForTransactionReceipt(txHash)

The only issue you will see with this example is that you will not have funds to send_raw_transaction() (which is the preferred method over sendRawTransaction(). The latter is deprecated. You may want to update that on your sample you sent over). You can use an account address that has funds if you'd like to test further but if you get here you will have gotten past the sign_transaction() issue you reported.

I have tested all the way through this with a funded account in a few different ways and was not able to reproduce what you are seeing so I am closing this ticket. If you are still having issues, please reopen. I do hope this helps you troubleshoot.