The story of this classic hymn was best told by the author himself:
One morning it came into my mind as I went to labor, to write an hymn on the ‘Gracious Experience of a Christian.’ As I went up to Holborn, I had the chorus,
‘On Christ the solid Rock I stand,
All other ground is sinking sand.’
In the day I had four first verses complete, and wrote them off. On the Sabbath following, I met brother King as I came out of the Lisle Street Meeting… who informed me that his wife was very ill, and asked me to call and see her. I had an early tea, and called afterwards. He said that it was his usual custom to sing a hymn, read a portion, and engage in prayer, before he went to meeting. He looked for his hymn-book but could find it nowhere. I said, ‘I have some verses in my pocket; if he liked, we would sing them.’ We did, and his wife enjoyed them so much, that after service he asked me, as a favor, to leave a copy of them for his wife. I went home, and by the fireside composed the last two verses, wrote the whole off, and took them to sister King… As these verses so met the dying woman’s case, my attention to them was the more arrested, and I had a thousand printed for distribution. I sent one to the Spiritual Magazine, without my initials, which appeared some time after this. Brother Rees, of Crown Street, Soho, brought out an edition of hymns , and this hymn was in it. David Denham introduced it  with Rees’ name, and others after… Your inserting this brief outline may in future shield me from the charge of stealth, and be a vindication of truthfulness in my connection with the Church of God.
Letter to the Gospel Herald