Let { X n , n ⩾ 1 } be a sequence of i.i.d. random variables taking values in a finite set of integers, and let S n = S n - 1 + X n for n ⩾ 1 and S 0 = 0 be a random walk on Z , the set of integers. By using the zeros, together with their multiplicities, of the rational function f ( x ) = E ( x X ) - 1 , x ∈ C , we characterize the space U of all complex-valued martingales of the form { g ( S n ) , n ⩾ 0 } for some function g : Z → C . As an application we calculate the absorption probabilities of the random walk { S n , n ⩾ 0 } by applying the optional stopping theorem simultaneously to a basis of the martingale space U. The advantage of our method over the classical approach via the Markov chain techniques (cf. Kemeny and Snell [1960. Finite Markov Chains. Van Nostrand, Princeton, NJ.]) is in the size of the matrix that is needed to be inverted. It is much smaller by our method. Some examples are presented.