1

I know that the fallback is triggered when sending a transaction to this contract and calling a non-existent function, what I want to understand is: Contract A sends a transaction to Contract B (fallback), the solidity code has run to here The fallback of Contract B is Is it triggered at this time or the fallback is triggered after the transaction sent by A to B has completed the block confirmation!

nopnopttt
  • 11
  • 1

1 Answers1

0

Former is correct. Fallback function triggers while contract B has sent the transaction to contract A.

Why?

Because Let's say contract A records the number of invalid function calls for which the fallback is called.

// Contract A
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

contract FallbackContract {
    uint256 public invalidFunctionCalls;

    constructor () {
        invalidFunctionCalls = 0;
    }

    fallback() external {
        invalidFunctionCalls += 1;
    }
}

Now, for each invalid function call, the variable invalidFunctionCalls should be incremented in the current block to reflect the invalid call thereafter. Which means fallback function is called as soon as the invalid function call is triggered.

NetanMangal
  • 309
  • 1
  • 9