The judge asks the student to take a few coins. But instead of paying tangible coins for intangible smell, he asked for the coins to be put in a handkerchief and shook hard. And the payment to be made with the sound the coins made.
(I had heard this story as an Indian story - not a Japanese story. And Ooka Tadasuke was replaced by Birbal - the prime minister of the Mughal Emperor Akbar. "Akbar Birbal" stories are full of such awesomeness.)