I have come across a strange problem. My contract is on the Polygon network, but for example, when I connect to Metamask with the Binance network and run a function of my contract, it is done successfully. while it should throw error or a warning, should it? I should Handle this in the client ?
Yep, the client should make sure it's connected to the right network. The reason calling a function from your contract on another network doesnt throw is because theres no contract deployed on the other network, and when you send a transaction to an EOA, the calldata is simply ignored. You could deploy an empty contract at the same address (the deployment address of a contract is a function of the deployer address and the nonce, so you can perfectly deploy a contract at the same address on 2 different networks) to prevent this from happening