my code
from web3 import Web3, HTTPProvider
web3 = Web3(HTTPProvider('https://kovan.infura.io/Ug2W9nZzjwN4lITvvLT0'))
Error:
Mds-MacBook-Pro:api sadafnoor$ python3 test.py
Traceback (most recent call last):
File "test.py", line 27, in <module>
client = Client(privkey, web3=web3)
File "/usr/local/lib/python3.6/site-packages/rmp_server-0.0.0-py3.6.egg/microraiden/client/client.py", line 47, in __init__
self.context = Context(private_key, web3, channel_manager_address)
File "/usr/local/lib/python3.6/site-packages/rmp_server-0.0.0-py3.6.egg/microraiden/client/context.py", line 23, in __init__
token_address = self.channel_manager.call().token()
File "/usr/local/lib/python3.6/site-packages/web3/contract.py", line 772, in call_contract_function
return_data = contract.web3.eth.call(call_transaction)
File "/usr/local/lib/python3.6/site-packages/web3/eth.py", line 266, in call
formatted_transaction = formatters.input_transaction_formatter(self, transaction)
File "/usr/local/lib/python3.6/site-packages/eth_utils/string.py", line 71, in inner
return fn(*text_args, **text_kwargs)
File "/usr/local/lib/python3.6/site-packages/eth_utils/string.py", line 85, in inner
return force_obj_to_text(fn(*args, **kwargs))
File "/usr/local/lib/python3.6/site-packages/web3/formatters.py", line 125, in input_transaction_formatter
'from': eth.coinbase,
File "/usr/local/lib/python3.6/site-packages/eth_utils/string.py", line 85, in inner
return force_obj_to_text(fn(*args, **kwargs))
File "/usr/local/lib/python3.6/site-packages/web3/eth.py", line 70, in coinbase
return self.web3._requestManager.request_blocking("eth_coinbase", [])
File "/usr/local/lib/python3.6/site-packages/web3/providers/manager.py", line 27, in request_blocking
response_raw = self.provider.make_request(method, params)
File "/usr/local/lib/python3.6/site-packages/web3/providers/rpc.py", line 52, in make_request
**self.get_request_kwargs()
File "/usr/local/lib/python3.6/site-packages/web3/utils/compat/compat_requests.py", line 22, in make_post_request
response.raise_for_status()
File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 405 Client Error: Method Not Allowed for url: https://kovan.infura.io/Ug2W9nZzjwN4lITvvLT0
Infura does not allow you to run all JSON-RPC methods that you normally could if you ran your own node. I think they do this for your own safety as some methods require your private key. You need to send raw transactions to Infura to interact with contracts. This is not an issue with web3.py. You should also not share your Infura token.
Does this repo has any connection to web3 java version https://github.com/web3j/web3j? They can interact with infura (i.e. call contract function). I'm wondering if they achieve it by sending raw transactions and exposing high level api?
@hbprotoss you can call contract functions with web3.py, you just can't do so by sending transactions without extra configuration (see work in progress here https://github.com/ethereum/web3.py/pull/649)
@pipermerriam Thank you for your patience :)
I'm getting this when I try to run w3.personal.newAccount(password). Is it possible to create an account on the ropsten infura test network?
Hi @r0fls The personal module is to be used when you're running a local node, or say if someone supports it as an RPC, you'd potentially be creating a private key on a hosted node!!!
Technically, you don't need to be connected to the internet to create an account. You just need to know the ingredients to make a private key and generate an address.
You can use eth_account to create a convenience account object that can be used to sign raw transactions or use w3.eth.account which returns an instance of eth_account.
If you don't want to go through all this hassle then start a local node and use the personal module.
Thank you @voith. I'm fine with going through the hassle if it's going to work on the actual ethereum network once we're finished testing. Will both methods work on the real ethereum network?
Yes, It will work on the main network. However, make sure that once you create an account using
account = w3.eth.account.create(), store the privateKey(account.privateKey) somewhere safe. Else you'll end up creating a new account with a new privateKey every time.
Once you have a privateKey you can use privateKeyToAccount to regenerate an account object with the same address as before.
Additionally, you'll need to plug a middleware being built in #649. Its still WIP but you can always write your own looking at it. The purpose of this middleware is to generate the same behavior as w3.personal.unlockAccount('your_account_address', 'your_account_passphrase').
I just added my public key to my whitelist in the Infura settings - might help someone else
Most helpful comment
Infura does not allow you to run all JSON-RPC methods that you normally could if you ran your own node. I think they do this for your own safety as some methods require your private key. You need to send raw transactions to Infura to interact with contracts. This is not an issue with web3.py. You should also not share your Infura token.