3

I am trying to call a contract function deployed in Ganache. I am pretty sure the contract is deployed because I can transact() and work with other functions. But when I call() it, I get this error:

Could not transact with/call contract function, is contract deployed correctly and chain synced?

this is my function call:

 updated_card = magic_ideas.functions.get_card('731759').call()

Previously, I have to "deploy an exam" with this code and it works correctly:

 t_hash1 = magic_ideas.functions.new_card('title', 'example_text', 'www.card.com', '731759').transact()

I get a t_hash1. Then when I try to get_card using .call() I get the error. What am I missing?

EDIT

This is the contract declaration:

magic_ideas = w3.eth.contract(address="0x246eCb1dA50199FD7FcC20Ad08C617C52e34b128", abi=abi)

The abi is a copy & paste from remix.

5
  • 1
    I am also having the same issue.
    – Njabulo
    Commented Mar 2, 2020 at 10:47
  • 1
    Would help to answer your question if one would know the full source code needed to understand the problem and then the error message 🙌 Commented Aug 15, 2020 at 9:50
  • @MikkoOhtamaa What part of the code do you think is missing? the connection is pretty straightforward ` w3 = Web3(Web3.HTTPProvider('127.0.0.1:7545'))` . I'll add the contract declaration, if I need to add something else, let me know and I'll add it. Commented Aug 15, 2020 at 16:45
  • 3
    Suggest replicating the problem in a small code base so you can post the complete source code and people can get to the bottom of it. Commented Aug 16, 2020 at 2:04
  • 2
    Please post a compelte source code for a repeatable problem, so we do not need to guess what goes to variables and such. Then we can help you. Commented Aug 16, 2020 at 20:42

2 Answers 2

1

use:

updated_card = magic_ideas.functions.get_card('731759').transact()

instead of

updated_card = magic_ideas.functions.get_card('731759').call()

1

I found that calling the contract function first works. This is supposed to clone the contract function (NOT the contract) and return a copy, but it also corrects the args field. I believe this only works if there are zero arguments, however.

Example:

updated_card = magic_ideas.functions.get_card('731759')().call()

Note the extra set of parenthesis before .call().

1
  • Thank you. This helped me and worked for me. Without the extra set of parentheses, this was not working. Commented May 29, 2022 at 22:57

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.