With the intelligent development of terminal devices and the growing applications of device-to-device(D2D)communication technology,terminal devices can share resource through a direct link. To improve the overall service capabilities of the network edge,a blockchain-based D2D-assisted multi-access edge computing architecture(BD-MEC)for resource sharing is proposed. In BD-MEC,considering the factors of the delay,energy consumption,and payment overhead,an offload decision-making based on game theory for multi-user scenario is proposed to meet the needs of different users. Moreover,in view of the malicious behaviors such as denial of service or payment,a smart contract-based resource sharing protocol and dispute handling method are proposed, which uses the blockchain to force the sharing parties to comply with the resource sharing protocol to achieve safe resource sharing. Simulations show that BD-MEC can effectively the reduce delay,energy consumption,and payment of computing tasks.