How to deal with dealing damage in netcode

Hi i have a simple multiplayer game prototoype with netcode . My Problem is how to deal damage and send information to the clients . In my game both player and objects will take damage. Here is my Approach , it is working but im not sure its the best way to do it . I am open the suggestions
(GetNetworkObjectId simply returns network object id of the gameobject , the reason i put it there i couldnt took the networkid from just IDamagable interface)

if (raycastHit.transform.TryGetComponent<IDamagable>(out IDamagable damagable))
{
    ulong NetworkObjectId = damagable.getNetworkObjectId();
    HitServerRpc(NetworkObjectId, gunData.damage);
}