We extend the theoretical model of external corporate financing to the case when the
buyers of the borrowing firm may default during the financing period. In our setup there
is an asymmetric information and hence moral hazard between the lender and the borrower
concerning the efforts of the borrower. We define the optimal debt contract in two
cases. In the symmetric case the lender and the borrower has the same information
about the buyer, its probability of default. In the asymmetric case the borrower learns
whether the buyer will pay or not before choosing her level of efforts. We prove that
in the asymmetric case the borrowing capacity and the welfare of the society is weakly
smaller than in the symmetric case. We also show that the nonnegative default risk
of a buyer weakly decreases borrowing capacity compared to the case when the buyer
pays for sure. However, it turns out that having a risky buyer might increase borrowing
capacity and welfare.