Smart contracts are essential in implementing and automating transactions in a blockchain network. The translation of existing business rules on transactions to a smart contract is challenging and time consuming. These types of constraints are often re-used among different contracts in a given application area. Automatic generation of smart contracts can reduce the level of expertise required for, along with the time and cost incurred in, specifying them. In this paper, we provide a novel framework for auto-generating smart contracts by enabling seamless translation of constraints encoded in a knowledge representation to blockchain requirements. Our framework uses ontologies and semantic rules to encode domain-specific knowledge and then leverages the structure of abstract syntax trees to incorporate the required constraints. We successfully demonstrate the functionality and effectiveness of our method in two different applications: Translating eligibility criteria for clinical trials and car rentals.