Gandalf’s most important role in The Hobbit is as a tutelary or wisdom figure to Bilbo. He persuades Bilbo to go on the adventurous journey with the dwarves because he knows that Bilbo, without realizing it, is an essential player in the drama that will result in the death of Smaug.
Warm and eager was his spirit (and it was enhanced by the ring Narya), for he was the Enemy of Sauron, opposing the fire that devours and wastes with the fire that kindles, and succours in wanhope and distress; but his joy, and his swift wrath, were veiled in garments grey as ash, so that only those that knew him well glimpsed the flame that was within. Merry he could be, and kindly to the young and simple, yet quick at times to sharp speech and the rebuking of folly; but he was not proud, and sought neither power nor praise… Mostly he journeyed tirelessly on foot, leaning on a staff, and so he was called among Men of the North Gandalf ‘the Elf of the Wand’. For they deemed him (though in error) to be of Elven-kind, since he would at times work wonders among them, loving especially the beauty of fire; and yet such marvels he wrought mostly for mirth and delight, and desired not that any should hold him in awe or take his counsels out of fear. … Yet it is said that in the ending of the task for which he came he suffered greatly, and was slain, and being sent back from death for a brief while was clothed then in white, and became a radiant flame (yet veiled still save in great need)