In general, when block codes are defined, the used alphabet is not binary. It is used an alphabet with n elements, $$n\ge 2,$$ n ≥ 2 , identified usually with the set $$ A_{n}=\{0,1,2,\ldots ,n-1\}$$ A n = { 0 , 1 , 2 , … , n - 1 } . Recently, some papers were devoted to the study of the connections between binary block codes and BCK-algebras. These codes are called n-ary block codes. In this paper, we try to generalize these results to n-ary block codes, providing an algorithm which allows us to construct a BCK-algebra from a given n-ary block code. For this purpose, we will prove that to each n-ary block code V we can associate a BCK-algebra X, such that the n-ary block code generated by $$X,V_{X},$$ X , V X , contains the code V as a subset and we will find in what circumstances the converse is also true.