Twain's versatility and verbal skill as a narrator are on display throughout Tom Sawyer. Take a look at this passage from the end of the whitewashing scene in Chapter 2:
He had had a nice, good, idle time all the while – plenty of company – and the fence had three coats of whitewash on it! If he hadn't run out of whitewash he would have bankrupted every boy in the village.
Tom said to himself that it was not such a hollow world, after all. He had discovered a great law of human action, without knowing it – namely, that in order to make a man or a boy covet a thing, it is only necessary to make the thing difficult to attain. If he had been a great and wise philosopher, like the writer of this book, he would now have comprehended that Work consists of whatever a body is obliged to do, and that Play consists of whatever a body is not obliged to do. And this would help him to understand why constructing artificial flowers or performing on a tread-mill is work, while rolling ten-pins or climbing Mont Blanc is only amusement. (2.45-46)
Twain begins by giving us a look at Tom's thoughts; he is privy to them and to those of all his other creations. In this case, his words have a boyish energy to them, and that last, brash dreamy statement – oh, if only I'd had a little more whitewash – is, for lack of a better term, pure Tom. As a narrator, Twain cannot only see what his characters are seeing and thinking, but he is able to channel their personalities.
From there, Twain extrapolates, deriving a grand and humorous "law of human action" from Tom's thoughts and actions. Twain lets us know that he is the man behind the curtain. He, "the writer of this book," reveals himself in order to make a joke, but he is only half joking when he compliments himself. For when he takes the opportunity to really be the Narrator with a capital "N," to let us know what the action really means, he's spot on.