user14387: If I'm remembering right, in a previous life of the Buddha, because dharma teachings were so rare at that time, a being offered to give a teaching, but only if he sacrificed his life to this being.
What is the text and reference for this?

user19614: There are 5 stories that I’ve managed to found which fit your description. Each story follows the same structure: a previous incarnation of the Buddha was privileged or successful, he yearned for the Dharma but was unable to find a great teacher. A celestial being (or enlightened or both) in disguise would appear before the would-be Buddha and require him to sacrifice himself (or what/those he held dear) in order to acquire the teaching. Each incarnation got the teaching and performed the required feat, emerging unscathed afterwards.
Here are the names of each incarnation (Chinese/Vietnamese) and what they have to do:

修樓婆/tu lâu bà, to surrender his wives and children to a yakṣa.
虔闍尼婆梨/kiền xà ni bà lê, to have holes drilled in his body and be burned alive.
毘楞竭梨/tỳ lăng kiệt lê, to be nailed with a thousand nails
曇摩鉗/đàm ma kiềm, to jump into a pit of fire.
欝多羅/uất đa la, to have his skin removed and grinded into pulp, bones chopped to make brushes (writing instruments), blood drained to make ink.

All 5 stories can be found in the Taisho edition of the 賢愚經, roughly translated as Sutta on the Fool and the Wise. The Sutta, although sharing the same name with the Bālapaṇḍita Sutta, is drastically different from the latter since the Bālapaṇḍita Sutta contains none of the above stories. I’m not a Buddhist scholar and my Chinese is inadequate, so I’m not sure what is the original spellings of these transliterated names. Consequently, I couldn't provide the names in Sanskrit or Pali.
I did ponder whether these stories were fabricated as they seem to be less well-known in Theravada circles. This doesn’t seem to be the case as:

Dilgo Khyentse Rinpoche mentioned the 2nd, 3rd and 4th stories in his book Zurchungpa's Testament.
A PhD thesis “The Jataka Stories in Mogao Caves” by Wu Ming-Kuo briefly summarised the first four stories, along with another one where the incarnation offers his head to the celestial being. This thesis also reveals the exact cave number of each story in the Mogao complex.

This implies that the stories can also be found in Vajrayana traditions, not just Mahayana, and have circulated for millenia. They were supposed to be treated as Jataka stories, but somehow ended up not being so.

Upon more digging, I found out that there exists an English translation from Mongolian of this whole sutra. It's a book called Sutra of the Wise and the Foolish by Stanley Frye. You can preview the book on Google Books. The first chapter (pg. 1-13) contains all of the stories I mentioned above.

14387: <p>If I'm remembering right, in a previous life of the Buddha, because dharma teachings were so rare at that time, a being offered to give a teaching, but only if he sacrificed his life to this being.</p>
<p>What is the text and reference for this?</p>
 19614: <p>There are 5 stories that I’ve managed to found which fit your description. Each story follows the same structure: a previous incarnation of the Buddha was privileged or successful, he yearned for the Dharma but was unable to find a great teacher. A celestial being (or enlightened or both) in disguise would appear before the would-be Buddha and require him to sacrifice himself (or what/those he held dear) in order to acquire the teaching. Each incarnation got the teaching and performed the required feat, emerging unscathed afterwards.
Here are the names of each incarnation (Chinese/Vietnamese) and what they have to do:</p>
<ol>
<li>修樓婆/<em>tu lâu bà</em>, to surrender his wives and children to a yakṣa.</li>
<li>虔闍尼婆梨/<em>kiền xà ni bà lê</em>, to have holes drilled in his body and be burned alive.</li>
<li>毘楞竭梨/<em>tỳ lăng kiệt lê</em>, to be nailed with a thousand nails</li>
<li>曇摩鉗/<em>đàm ma kiềm</em>, to jump into a pit of fire.</li>
<li>欝多羅/<em>uất đa la</em>, to have his skin removed and grinded into pulp, bones chopped to make brushes (writing instruments), blood drained to make ink.</li>
</ol>
<p>All 5 stories can be found in the Taisho edition of the 賢愚經, roughly translated as Sutta on the Fool and the Wise. The Sutta, although sharing the same name with the Bālapaṇḍita Sutta, is drastically different from the latter since the Bālapaṇḍita Sutta contains none of the above stories. I’m not a Buddhist scholar and my Chinese is inadequate, so I’m not sure what is the original spellings of these transliterated names. Consequently, I couldn't provide the names in Sanskrit or Pali.</p>
<p>I did ponder whether these stories were fabricated as they seem to be less well-known in Theravada circles. This doesn’t seem to be the case as:</p>
<ul>
<li>Dilgo Khyentse Rinpoche mentioned the 2nd, 3rd and 4th stories in his book <em>Zurchungpa's Testament</em>.</li>
<li>A PhD thesis “<em>The Jataka Stories in Mogao Caves</em>” by Wu Ming-Kuo briefly summarised the first four stories, along with another one where the incarnation offers his head to the celestial being. This thesis also reveals the exact cave number of each story in the Mogao complex.</li>
</ul>
<p>This implies that the stories can also be found in Vajrayana traditions, not just Mahayana, and have circulated for millenia. They were supposed to be treated as Jataka stories, but somehow ended up not being so.</p>
<hr />
<p>Upon more digging, I found out that there exists an English translation from Mongolian of this whole sutra. It's a book called Sutra of the Wise and the Foolish by Stanley Frye. You can <a href="https://books.google.com/books?id=m44HEAAAQBAJ" rel="nofollow noreferrer">preview the book</a> on Google Books. The first chapter (pg. 1-13) contains all of the stories I mentioned above.</p>
