How to hardcode the unsubscribe /optout URL in a transactional email?
I think the unsubscribe link either needs mailing id or group id. The other option would be to create a profile with groups and opt-out field. And the include the profile as a unsubscribe link 

https://example.com/civicrm/profile/edit?reset=1&amp;gid=2&amp;id={contact.contact_id}&amp;{contact.checksum}


Where gid is a profile id.

Cheers

Pradeep