At the very beginning of the game, you will get your first coin for completing the tutorial and picking up the coin that is in that level.
Immediately afterwards, as you cross the bridge, talk to the NPC, and he'll give you three coins.
Run 'N Gun levels
The bulk of your coins will be gained from the Run 'N Gun levels. Each Run 'N Gun level has a total of five coins that can be collected. There's six of these levels, totaling 30 coins. For the most part, these coins are easy to find, and the most important thing is to have enough skill to beat the levels.
A gingerbread girl in World 2 will give you a coin if you take the shortcut. In order to take the shortcut, walk behind the birdhouse and behind the mountain all the way around to the dragon tower.
A juggling gingerbread boy in world 2 will reward you with a coin if you get four parries in a row without touching the ground.
There are some easy ways to parry four times, like in this example.
The final four coins are hidden in the open world. There is a single coin for each area in the game.
On Inkwell Isle One the secret coin is placed behind Axe NPC in the trees. He won't move until you beat each boss in this world, so make sure to check this place before leaving.
On Inkwell Isle Two travel to the very center of the map close to the exit of World 2. You'll see a small greenish cabin. Grab the second secret coin behind it.
On Inkwell Isle Three you will find the third secret coin behind the ticket booth that is near Cala Maria Boss.
And finally, the fourth secret coin can be found in the Casino behind the wall on the left-hand side of the door. Now you can take your coins to a Porkrind's Emporium and finish off buying every upgrade in the game.