Trusted decentralized applications based on distributed ledger technologies provide many potential opportunities to 5G applications and verticals, as well as in fifth generation mobile network (5G) enabling technologies, systems, and services. Apart from the tamper-proof exchange of transactions, distributed ledgers can provide a software environment for the trusted execution of smart contracts. In this paper, we explore the security aspects of decentralized applications and, in particular, the security of smart contracts. Distributed ledger characteristics impose distinct requirements on smart contract design, implementation, deployment, and management. We briefly present the approach to the development of secure smart contracts, and highlight key smart contract vulnerabilities and the developer tools supporting smart contract security. We developed a secure, upgradeable modular multi-contract platform. It combines per-contract Smart Contract Tunnels and per-user-based access control to minimize vulnerabilities. The smart contract platform is comprised of service-agnostic, auxiliary, and service-specific smart contracts. It can be therefore easily adapted to different 5G application verticals. For illustration and evaluation, we elaborated on the proposed solution on a case of smart electric charging. During the design and development, state-of-the-art code analysis was applied. Finally, we propose an architecture for the integration of the secure multi-contract platform into a 5G architecture. The integration proposal utilizes hybrid private-public blockchain networks for possible security, scalability, performance, and transaction cost optimization.