The truffle crab in "Stardew Valley" is a special kind of animal in the game. If you want to fight the truffle crab, you can first wait for the truffle crab to move. If the truffle crab does not move, you will not be able to damage it. For any damage, just get close to it and it will move, then attack.
How to fight truffle crab in Stardew Valley
When defeating the Truffle Crab, please note that the Truffle Crab will not take damage when stationary. However, as you get closer to it, it starts to move, which is when it becomes vulnerable.
You can attack it simply by getting close (with its legs extended) and swinging any melee weapon.