Gradec was given a royal charter by King Béla IV in 1242. The royal charter, also called the Golden Bull, was a very important document by which Gradec was declared and proclaimed "a free royal city on Gradec, the hill of Zagreb". This act made Gradec a feudal holding responsible directly to the king. The citizens were given rights of different kinds; among other things they were entitled to elect their own city magistrate (Croatian: gradski sudac) fulfilling the role of mayor. They were also entitled to manage their own affairs.
The citizens engaged in building defensive walls and towers around their settlement, fearing a new Mongol invasion. They completed the defensive system at a time between 1242 and 1261. It could be rightly assumed that by building its fortification walls in the middle of the 13th century, Gradec acquired its outward appearance that can be clearly seen in today's Upper Town (Gornji Grad). The defensive walls enclosed the settlement in the shape of a triangle, its top located near the tower called Popov toranj and its base at the south wall (today's Strossmayer Promenade) and Lotrščak tower, which could be explained by the shape of the hill. In some places, rectangular and semicircular towers fortified the defensive walls.
There were four main gates leading to the town: the west gate in the Mesnička Street, the new north gate, later known as the Opatička Street gate, Dverce in the south and the Kamenita vrata (English: Stone gate) in the east. Kamenita vrata is the only gate still preserved to date.