Industry 4.0 connects the latest technologies such as cloud computing, Internet of things (IoT), machine learning and artificial intelligence (ML/AI), and blockchain to provide more automation in the industrial process and also bridges the gap between the physical and digital worlds through the cyber-physical system. The inherent feature of IoT devices creates the industry to smart industry (referred to as industrial IoT, i.e., IIoT) through its data-driven decision policies. However, several challenges such as decentralization, security and privacy vulnerability, single point of failure (SPOF), and trust issues exist in the IoT system. Blockchain is one of the promising technologies that can bring about opportunities for addressing the challenges of IoT systems. In this article, we have investigated the integration of IoT with blockchain technology and provided an in-depth study of the blockchain-enabled IoT and IIoT systems. The state-of-the-art research is categorized into data storage and management technique, big data and cloud computing technique (finance and data auditing), and industrial sectors (supply chain, energy, and healthcare sector). The insightful discussion based on the different categories is also presented in the paper. In particular, first, we introduce the IoT and IIoT and then discuss the need for smart contracts in IoT and IIoT systems. Next, we concentrate on the convergence of blockchain and IoT with state-of-the-art research. In addition, this article also provides the open and future research directions towards this era with the highlighted observations.