Smart contracts are becoming increasingly popular for managing transactions or activities in fog computing environments. However, the use of smart contracts for registration and resource access granting is vulnerable to various types of attacks that can compromise their security. Detecting these attacks can be challenging, as attackers can use sophisticated techniques to evade detection. This research uses a machine learning-based approach for detecting different attacks on smart contracts used for registration and resource access granting in fog computing. Data is collected from online Ethereum's official site "etherscan.io". Different feature extraction methods and machine learning models are tested. Using accuracy, precision, recall, F1 score, cross-validation, and computational time, the performance of models is evaluated. Results indicate that extreme gradient boosting (XGB) and random forest (RF) provide the highest accuracy of 80% using the term frequency-inverse document frequency (TF-IDF) approach. The light gradient boost classifier provides the highest accuracy of 81% with the Bag of Word (BoW) approach. Similarly, the extra tree provides the highest accuracy of 83% using the N-gram technique. Furthermore, performance using TF-IDF is slightly poorer than BoW and N-gram, however, it has less computational complexity.