Buildup of a highly twisted magnetic flux rope during a solar eruption