Blockchain technology has numerous benefits, like decentralization, consistency, anonymity, and audibility. There's a large spectrum of blockchain applications, starting from healthcare, e-voting, education, logistic and supply chain management, financial services, risk management, the web of things (IoT), and public and social services. Although a variety of studies concentrate on using blockchain technology in various application aspects, there's no comprehensive survey on blockchain technology from both technological and application perspectives. To fill this gap, we conducted a comprehensive survey on blockchain technology. In particular, this paper presents the use of blockchain in various sectors, reviews blockchain applications, and discusses technical challenges as well as recent advances in tackling the challenges. Moreover, this paper also points out the long-term directions of blockchain technology.