i want to implement a clustering algorithm (k-means for example) in a smart contract.

for the traning data (big Data Set) , i want to use IPFS(off-chain) to save my dataset.

is this Idea Correct? How and with what can i start? can i use IDE remix solidity to implement all this. thanks.

  • no it's not you can't implement ai into smart contract. If you think it can try implement numpy library in smart contract and see if you can
    – haxerl
    Jan 4, 2020 at 1:02

1 Answer 1


The smart contract environment is not adequate to implement any machine learning algorithm which could need a non definite number of iterations. This aspect conflicts with the maximum computational power which can be included in a single Ethereum block, where you cannot split the convergency algorithm to use more blocks than one without heavy overheads.

On the other side, the unavailability of any double or float math, more an int/uint math not protected against overflows by default, the absence of the memory pointers and so on, make it to implement gradient landing algorithms a true nightmare.

In general, any smart contract under Ethereum is more adequate to implement finite state machines with some very light computations on it, nothing more.

Trying to implement heavy computational works on it results in a costly run of the same, where it can be implemented.

Probably, the clustering part of the application should be moved on some offline resource based on a state completely defined and stored on the blockchain.

  • hello, thank your for your response
    – Kh Ya
    Jan 7, 2020 at 11:53
  • You are welcome. You should mark the answer as “answered” as well. Simply click the gray sign at the left of the text: if it becomes green the answer is marked as “answered”.
    – Rick Park
    Jan 7, 2020 at 13:21
  • can i use oraclize to implement a clustering algorithm (k-means for example) and bind with a smart contract.
    – Kh Ya
    Jan 7, 2020 at 21:55
  • Yes, this can be done. Using off-chain computational power the problem can be solved easily.
    – Rick Park
    Jan 7, 2020 at 22:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.