I have a contract with a function in which only if a certain condition is true, it changes the state of the blockchain otherwise it emits an event and returns:

address[] public global_state;
function test() public payable returns (bool) {
    if (condition on global_state) {
        emit Event();
        return false;
    // change the state
    return true

If I understand it correctly, I don't need a transaction if the condition is true and a simple call will do the job.

But when I call the function from web3py I don't know the state of the condition. I was wondering if there is a way to understand it before and make the correct call with web3py because for the transaction I need to wait but for the call, I don't.

1 Answer 1


Emitting an event is also modifying operation, because events are recorded in blocks. Though, if you don't need event to be visible to others, you may do the following:

  1. Invoke function locally via call
  2. Check returned value
  3. In case returned value is true, invoke function in transaction via send

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.