Your best bet for establishing credit is to get a credit card or two. Use the cards, but pay the balance off each month so that you don't pay finance charges.
I doubt that the loan you could get on a dirt bike without prior credit would have a very attractive interest rate. Often these types of loans will come with pre-payment penalties or a loan structured so that you pay most of the interest in the beginning and don't start paying down the principal until quite a ways into the loan. This could end up being VERY expensive for you, especially if you decide to sell the bike before the loan has been paid off.
For example, you could finance $4000 for four years with a 10% interest rate, making payments of $101.45. Over the life of the loan you would pay $101.45/month x 48 months = $4869.90, which means that you will have paid $869.60 if you keep the loan the entire term. If you received a loan that was based on the "rule of 78" (rather common) and you decided that you wanted to sell the bike after only one year, you would discover that after making 12 paymens for a total of $1217.4 you would still owe 3159.73. Note that the situation only gets worse if the interest rates are higher.
You would be a lot better off to buy a used bike that you could pay cash for instead of financing a bike. If you can't afford to pay cash, then you probably can't afford dirt bike riding. Keep in mind that the bike is the cheap part. To go along with the bike you will need:
Helmet: $140 to $300
Boots: $120
gloves, goggles: $50
chest protector: $50
Gas can: $40
Tie downs: $20
Do you have a truck or trailer to haul the bike around? You can pick up a used trailer for a few hundred $$, or you might need a $100 ramp to get the bike into your truck.
Do you have a set of tools, metric wrenches and sockets?
I don't recommend cheap tools, and a reasonable set can cost several hundred $$
I might normally recommend a two stroke "off road" bike (Such as the TTR-230 you mentioned) in your situation instead of the MX style bike (YZ-anything...). The TT series woudl be a lot cheaper, which would allow you to get into the sport with a newer, more reliable bike. What concerns me is the statement that all your friends ride. If you are goint to be trying to keep up with them, and they have MX bikes, then riding a non MX bike could get you into trouble.
The concern that I have is that the off road bike wouldn't have the suspension to match your friends. If you try to follow them over the same terrain at anywhere near the same speed then you better have a suitable suspension. Power will get you into trouble, but a good suspension can help you ride through it.
I would recommend matching what your friends have, if you can afford it. If you can't afford that right now, then I would recommend starting with something like the TTr-230 that you mentioned. Being a cheaper model of bike you would be able to buy one that wasn't quite as old and therefore in better shape. Use it for a year or two and then you should be able to sell it with little lost value and buy the bike you really want.
Rod