Castle walls contribute to the wall bonus soldiers stationed on the wall have. There are 5 levels of castle wall
All outposts and castles start at level 1 walls and will need to be upgraded.
In order to build higher level towers and gates the castle wall must first be upgraded. However, not all towers must be upgraded to upgrade the wall. For example, in order to build a level 3 tower, the level 3 wall upgrade must first be purchased. However, in order to upgrade your wall to level 4, it is not nessesary that all towers are fully upgraded to level 3.
The moat is the first line of defense. It is unlockable after level 37. Much like the walls, there are additional defensive tools to use on it. The strongest tool is called the fire moat, which increases moat protection by 110%. It is purchaseable from the armorer for 86 rubies.
Moats can be purchased for 12,500 rubies. It gives a 20% extra defensive bonus and can be a bigger bonus if tools are used