With the exponentially growth in the number of Internet of Things (IoT) devices, the cloud-centric computing paradigm can hardly meet the increasingly high requirements for low-latency, high-bandwidth, easily available and more intelligent services. Therefore, a distributed and decentralized computing architecture is imperative, where edge-centric computing, such as fog computing and mist computing, is recently proposed. Edge-centric computing resources can be managed locally and personally rather than being administered by a remote centralized third-party. However, security and privacy issues are the main challenges due to the absence of trust between the IoT devices and edge computing nodes. A blockchain, as a decentralized, trustless and immutable public ledger, can well solve the trust-absence issue. In this paper, we first elaborate on the security and privacy issues of edge computing-enabled IoT, and then present the key characteristics of blockchains, which make blockchains well-suited for the edge-centric IoT scenarios. Furthermore, we propose a general framework for blockchain-based edge computing-enable IoT scenarios that specifies the step-by-step procedure of a single transaction between an IoT end and an edge computing node. In addition, we design a smart contract within a private blockchain network that exploits the-state-of-the-art machine learning algorithm, Asynchronous Advantage Actor-Critic (A3C), to allocate the edge computing resources, which exemplifies how artificial intelligence (AI) can be combined with blockchains. We further discuss the benefits of the convergence of AI and blockchains. Finally, simulation results are presented.