1

Solidity code

contract Greeter {
string public greeting;

function Greeter() public {
    greeting = 'Hello';
}

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

function greet() view public returns (string) {
    return greeting;
}

I've deployed the contract through remix - 0x5b62B76bE6Ec44724f8832F6f4402e9128C6309a and receive the response from contract.functions.greet().call() as 'Hello'. I've whitelisted the contract address in Infura.

However on calling the function tx_hash = contract.functions.setGreeting('Nihao').transact(), I receive the following error.

Traceback (most recent call last):
File "<input>", line 1, in 
<module>
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/contract.py", line 1151, in transact
**self.kwargs
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/contract.py", line 1454, in transact_with_contract_function
txn_hash = web3.eth.sendTransaction(transact_transaction)
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/eth.py", line 268, in sendTransaction
[transaction],
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/manager.py", line 109, in request_blocking
response = self._make_request(method, params)
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/manager.py", line 92, in _make_request
return request_func(method, params)
File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 50, in apply_formatters
response = make_request(method, params)
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/gas_price_strategy.py", line 18, in middleware
return make_request(method, params)
File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/attrdict.py", line 18, in middleware
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/normalize_errors.py", line 9, in middleware
result = make_request(method, params)
File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 48, in apply_formatters
response = make_request(method, formatted_params)
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/middleware/exception_retry_request.py", line 87, in middleware
return make_request(method, params)
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/providers/rpc.py", line 68, in make_request
**self.get_request_kwargs()
File "/Users/siddharth/venv/lib/python3.6/site-packages/web3/utils/request.py", line 27, in make_post_request
response.raise_for_status()
File "/Users/siddharth/venv/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://ropsten.infura.io/v3/cf37a080c46b470b9c828359ece27ba8

Full code - https://web3py.readthedocs.io/en/stable/contracts.html

Where am I going wrong? Thank you.

  • What's your truffle.js file? It looks like a connection issue – thefett Dec 12 '18 at 1:52
  • All transactions have to be signed with a private key. Infura (thankfully) doesn't know your private key. So if you're going to use Infura to send a transaction, you have to sign it yourself. Without seeing the exact response from the server, I assume it's complaining that you're trying to call an unsupported RPC method (one that requires knowledge of a private key). – smarx Dec 12 '18 at 4:45
  • @smarx Would this suffice? codepad.org/8ZDxXS7J – Siddharth Malhotra Dec 12 '18 at 17:18
  • That looks roughly right. – smarx Dec 12 '18 at 17:21
  • @smarx In that case how do I conduct the transaction? Since this only signs it. How do I verify the value has been updated? bit.ly/2EsAOin Please help. – Siddharth Malhotra Dec 12 '18 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.