Roast the masala ingredients in a dry skillet until lightly brown and fragrant. Fry the coconut last and keep a close eye on it because it can burn in an instant. Cool, powder in a spice grinder, and reserve.
Heat the oil in a saucepan.
Add the onions and sugar and saute until browned at the edges, about 5 minutes.
Add the garlic and stir for a minute.
Add the tomato, the powdered masala, and chili and turmeric powders.
Let this cook, stirring a few times, until the tomatoes start to express the oil.
Add the potatoes and stir in.
Add the matki beans, about 3 cups of water, and half the coconut milk.
Cover and simmer on a medium heat about 20-30 minutes, until the matki beans have cooked and are tender but not mushy.
Add the remaining coconut milk, garnish with coriander and some raw onions and lemon, if desired.
Serve piping hot.