Usually it is safe to leave the gas estimation for the wallet itself and not to try to do it yourself. In the case wallets cannot estimate the gas, which sometimes happens for complex transactions, you can do test transactions on testnet and figure out how many gas units the transactions spend and then use that as a hardcoded limit.

Only top voted, non community-wiki answers of a minimum length are eligible