The Master Key: An Electrical Fairy Tale, Founded Upon the Mysteries of Electricity and the Optimism of Its Devotees is a 1901 novel by L. Frank Baum, author of The Wonderful Wizard of Oz.
The protagonist is a boy named Rob Joslyn. His age is not specified. Baum dedicated the book "To My Son, Robert Stanton Baum," who was born in 1886 and would thus have been about fifteen at the time it was published.
Rob is an electrical experimenter whose father encourages him and sees that he "never lacked batteries, motors or supplies of any sort." A "net-work[sic] of wires soon ran throughout the house". He loses track of the elaborately interconnected wires, and trying to get a cardboard house to light up, he "experimented in a rather haphazard fashion, connecting this and that wire blindly and by guesswork, in the hope that he would strike the right combination." There is a bright flash, and a being who calls himself the Demon of Electricity appears. He tells Rob that he has accidentally "touched the Master Key of Electricity" and is entitled to "to demand from me three gifts each week for three successive weeks." Rob protests that he does not know what to ask for, and the Demon agrees to select the gifts himself.