If you still go through with it, have an attorney create/review any agreement to prevent tax and legal problems for you, stock grants can be taxable immediately to you, and restricted stock will likely never be worth anything to you. The "best" way to do this is not to take ownership (unless you are going to be a founder or paid employee and you get grants), and instead to invoice the company and hold the debt contractually for invoiced services. You can finance your work for them this way but the moment you take stock things become a pain in the ass, and your chances of getting paid will be even less then doing invoice debt. Also, the stock they grant you will be so diluted and after preferences etc you'll never see a dime, unless you force non-diluting and take a preference yourself but then investors might be hard on the founder for raising money which again, means you won't get paid. Also, don't forget you will have to wait years for the stock to have a private or public market, or you will need provisions for the founders to be forced to buy you out at a minimum price by a specific date etc, it is a mess.
So again, the "best" way is to finance the work for them contractually and you still may want to file a UCC lien to indicate you hold a lien on their software asset until they pay. This way when investors or creditors go through due-diligence they will see the company owes you money for the product and so they will force the founder to pay you. To be fair, some investors get turned off by liens, but the reality is most IME don't care as long as the founder doesn't try to hide it and is up front.
I can share plenty of stories about doing these types of deals when I was younger and getting hosed by people who I felt would always be stand up.