Richard Sandison, 51, was a boy when he was given the Belgian revolver from the First World War.
He had played with it and kept it as a memento but it was seized by police after they attended at his home on an unrelated matter.
Sandison faced a jail term after admitting possessing the 125-year-old prohibited weapon without authority.
But at a previous hearing a judge ruled that she did not have to impose that penalty after listening to evidence in the case. Lady Scott told Sandison that she had found there were "exceptional circumstances" in his case.
The judge said she accepted that he did not realise he needed a firearms certificate for the gun.
She ordered him to carry out 150 hours unpaid work under a community payback order.
Sandison, of Uphall Station, West Lothian, told the court that he was given his late grandfather's revolver as a teenager.
"My uncle said the pistol had been deactivated and knew that someone my age would probably enjoy something like that. I played with it as any boy would I suppose – cowboys and indians with my friends," he said. He had owned a shotgun, for which he had a licence, and said: "As far as I was concerned there was no way that pistol could be fired."