Fallback functions are executed if a contract is called and no other function matches the specified function identifier, or if no data is supplied
so you can use the following:
send Transaction
to the contract with the msg.value = 0
and it will automatically invoke the fallback function.
OR
call the contract using myContract.methods
and provide the wrong or random function name
or signature
and it will execute the fallback function as it couldn't find the function with the same signature in the contract. (not tested)
Update (Tested on expanse network)
Tested the second option and it didn't work. As using random
name in myContract.methods
will return undefined
because when web3js
tries to find the function
name in abi
it returns empty
. The reason being
other function in the abi
have the name attribute
and fallback
doesn't have one
After that created a raw transaction
with the data
being empty and sent that transaction to the network which invoked the fallback function as expected.
And on trace_transaction
it says reverted
which the fallback
function does in this particular case.