I have used Ganache to compile and deploy my contract successfully. Now I would like to do the same on the Ropsten network using my Metamask account. I don't want the Metamask plugin to pop up every time, therefore I'm using it in the background.

Here is my code:

from web3 import Web3, HTTPProvider

w3 = Web3(HTTPProvider('https://ropsten.infura.io/v3/ce8e130db56748dba7af3ebd7fbe4430'))

w3.eth.defaultAddress = <metamask address>

I'm receiving the following error when I try to deploy:

Traceback (most recent call last):
  File "walkthrough.py", line 29, in <module>
    greeter_interface = ContractInterface(w3, 'Contract', contract_dir)
  File "D:\blockchain\bpoc\scripts\interface.py", line 23, in __init__
    self.web3.eth.defaultAccount = web3.eth.coinbase
  File "D:\blockchain\venv\lib\site-packages\web3\eth.py", line 82, in coinbase
    return self.web3.manager.request_blocking("eth_coinbase", [])
  File "D:\blockchain\venv\lib\site-packages\web3\manager.py", line 112, in request_blocking
    raise ValueError(response["error"])
ValueError: {'code': -32601, 'message': 'The method eth_coinbase does not exist/is not available'}

1 Answer 1


This is your line of code:

self.web3.eth.defaultAccount = web3.eth.coinbase

However Infura doesn't have a coinbase address, because Infura does not act as a wallet service, which is a very important difference with Ganache. Basically, in Ganache you have ten pre-filled and pre-unlocked accounts, but those accounts are not available in Infura, and they simply can't be "transferred" there because the service doesn't allow you. So you have to handle by yourself your own accounts locally when using Infura, and you can't use many methods like eth_sendTransaction or eth_coinbase.

The reason is that in order to have this API available Infura would have to know your private keys, which is of course not an option. So, rather than the previous line, use the following:

w3.eth.defaultAddress = "0x........."  # metamask address, but hardcoded

With this you will be able to deploy the contract.

I dont want metamask plugin to pop up everytime therefore usingit in background.

So, switching from python to javascript: Metamask is a web3 provider fully oriented to the user, and its rules are simple: every time you spend money from the user's account you need his explicit authorization via popup. If you don't like that do not use Metamask, because there's no way around it.

That being said, imagine you'd deal with a library that allows any app to spend any desired amount of ether/tokens from your account without the user even noticing. Nobody would use it, because funds could be very easily stolen by malicious webapps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.