# LoanSet

[Source](https://github.com/XRPLF/rippled/blob/release/3.4.x/src/libxrpl/tx/transactors/lending/LoanSet.cpp)

Creates a new `Loan` ledger entry, representing a loan agreement between a *Loan Broker* and *Borrower*.

The `LoanSet` transaction is a mutual agreement between the *Loan Broker* and *Borrower*, and must be signed by both parties. The following multi-signature flow can be initiated by either party:

1. The borrower or loan broker creates the transaction with the preagreed terms of the loan. They sign the transaction and set the `SigningPubKey`, `TxnSignature`, `Signers`, `Account`, `Fee`, `Sequence`, and `Counterparty` fields.
2. The counterparty verifies the loan terms and signature before signing and submitting the transaction.


Note
Loans created after the [LendingProtocolV1_1 amendment](/resources/known-amendments#lendingprotocolv1_1) is enabled can only be originated against a closed-ended vault during its *Investment* phase, and only if the loan's final scheduled payment is at least 60 seconds before the vault enters its *Redemption* phase. This means the maximum term of new loans shrinks as the vault approaches its `RedemptionDate`.

_Requires the [LendingProtocol amendment](/resources/known-amendments#lendingprotocol). (Open for Voting: 37.14%)_

_The [LendingProtocolV1_1 amendment](/resources/known-amendments#lendingprotocolv1_1) updates this. (Open for Voting: 0.00%)_

## Example  JSON

```json
{
  "TransactionType": "LoanSet",
  "Account": "rEXAMPLE9AbCdEfGhIjKlMnOpQrStUvWxYz",
  "Fee": "12",
  "Flags": 0,
  "LastLedgerSequence": 7108682,
  "Sequence": 8,
  "Data": "546869732069732061726269747261727920646174612061626F757420746865206C6F616E2E",
  "Counterparty": "rCOUNTER9AbCdEfGhIjKlMnOpQrStUvWxYz",
  "LoanOriginationFee": 100,
  "LoanServiceFee": 10,
  "LatePaymentFee": 5,
  "ClosePaymentFee": 20,
  "OverpaymentFee": 5,
  "InterestRate": 500,
  "LateInterestRate": 1000,
  "CloseInterestRate": 200,
  "OverpaymentInterestRate": 5,
  "PrincipalRequested": 10000,
  "PaymentTotal": 12,
  "PaymentInterval": 2592000,
  "GracePeriod": 604800,
  "SigningPubKey": "03C040CAC1E164B0E385D31E41447FE6B8960E0D202811CFDA08B55BA29E08C6B0",
  "TxnSignature": "30440220549D359F792E155D20B5E8B3423F0F844CCF7C86986EB85BE482908A55A7157D02207B464FFE57E75D9693BAC445540CF078E9E0B6452C917DE4D66F27918D32A170",
  "hash": "831EEFF19C980FC348E984625FE41AEB27301B0B072D4239A980E78B86B2515C"
}
```

##  Fields

In addition to the [common fields](/docs/references/protocol/transactions/common-fields),  transactions use the following fields:

| Field Name | JSON Type | Internal Type | Required? | Description |
|  --- | --- | --- | --- | --- |
| `LoanBrokerID` | String | Hash256 | Yes | The ID of the `LoanBroker` ledger entry. |
| `Data` | String | Blob | No | Arbitrary metadata in hex format (max 256 bytes). |
| `Counterparty` | String | AccountID | No | The address of the counterparty of the loan. |
| `LoanOriginationFee` | String | Number | No | The amount paid to the `LoanBroker` owner when the loan is created. |
| `LoanServiceFee` | String | Number | No | The amount paid to the `LoanBroker` owner with each loan payment. |
| `LatePaymentFee` | String | Number | No | The amount paid to the `LoanBroker` owner for late payments. |
| `ClosePaymentFee` | String | Number | No | The amount paid to the `LoanBroker` owner for early full repayment. |
| `OverpaymentFee` | Number | UInt32 | No | A fee charged on overpayments, in units of 1/10th basis points. Valid values are 0 to 100000 (inclusive), representing 0% to 100%. |
| `InterestRate` | Number | UInt32 | No | The annualized interest rate of the loan, in units of 1/10th basis points. Valid values are 0 to 100000 (inclusive), representing 0% to 100%. |
| `LateInterestRate` | Number | UInt32 | No | A premium added to the interest rate for late payments, in units of 1/10th basis points. Valid values are 0 to 100000 (inclusive), representing 0% to 100%. |
| `CloseInterestRate` | Number | UInt32 | No | A fee charged for repaying the loan early, in units of 1/10th basis points. Valid values are 0 to 100000 (inclusive), representing 0% to 100%. |
| `OverpaymentInterestRate` | Number | UInt32 | No | The interest rate charged on overpayments, in units of 1/10th basis points. Valid values are 0 to 100000 (inclusive), representing 0% to 100%. |
| `PrincipalRequested` | String | Number | Yes | The principal loan amount requested by the borrower. |
| `PaymentTotal` | Number | UInt32 | No | The total number of payments to be made against the loan. |
| `PaymentInterval` | Number | UInt32 | No | The number of seconds between loan payments. |
| `GracePeriod` | Number | UInt32 | No | The number of seconds after the loan's payment due date when it can be defaulted. |
| `SigningPubKey` | String | Blob | Yes | The public key used to verify the validity of the first signer's signature. |
| `TxnSignature` | String | Blob | Yes | The hex encoding of the digital signature for the first signing. |
| `hash` | String | Hash256 | Yes | The unique identifying hash of the partially-signed transaction. |


If the borrower already holds the loan's asset, the transaction succeeds regardless of the issuer's `DefaultRipple` setting since it is only checked when a new trust line needs to be created. If a `LoanOriginationFee` is specified, the broker owner must also hold the asset for this to apply. _The [fixCleanup3_4_0 amendment](/resources/known-amendments#fixcleanup3_4_0) updates this. (Open for Voting: 0.00%)_

### CounterpartySignature Fields

An inner object that contains the signatures of the counterparty of the transaction. The object contains the following fields:

| Field Name | JSON Type | Internal Type | Required? | Description |
|  --- | --- | --- | --- | --- |
| `SigningPubKey` | String | STBlob | No | The public key used to verify the validity of the signature. |
| `TxnSignature` | String | STBlob | No | The signature over all signing fields. Must be generated using role-specific hash prefixes _The [fixCleanup3_4_0 amendment](/resources/known-amendments#fixcleanup3_4_0) updates this. (Open for Voting: 0.00%)_. Standard transaction signatures are rejected. |
| `Signers` | List | STArray | No | An array of transaction signatures from the counterparty. Each signature must be generated using role-specific hash prefixes _The [fixCleanup3_4_0 amendment](/resources/known-amendments#fixcleanup3_4_0) updates this. (Open for Voting: 0.00%)_. Standard transaction signatures are rejected. |


The final transaction must include either:

- Both the `SigningPubKey` and `TxnSignature` fields.
- The `Signers` field.


Note
This field isn't included in the `LoanSet` JSON the first party signs, instead it's added by the counterparty when they sign.

##  Flags

Transactions of the  type support additional values in the [`flags` field], as follows:

| Flag Name | Hex Value | Decimal Value | Description |
|  --- | --- | --- | --- |
| `tfLoanOverpayment` | `0x00010000` | 65536 | Indicates that the loan supports overpayments. |


## Error Cases

Besides errors that can occur for all transactions,  transactions can result in the following [transaction result codes](/docs/references/protocol/transactions/transaction-results):

| Error Code | Description |
|  --- | --- |
| `tecEXPIRED` | The vault is closed-ended and has entered its *Redemption* phase. _Requires the [LendingProtocolV1_1 amendment](/resources/known-amendments#lendingprotocolv1_1). (Open for Voting: 0.00%)_ |
| `tecINSUFFICIENT_FUNDS` | The `Vault` associated with the `LoanBroker` doesn't have enough assets to fund the loan.The `LoanBroker` ledger entry doesn't have enough first-loss capital to meet the minimum coverage requirement for the new total debt. |
| `tecINSUFFICIENT_RESERVE` | The borrower's account doesn't have enough XRP to meet the reserve requirements. |
| `tecKILLED` | The `GracePeriod`, `PaymentInterval`, or `PaymentTotal` (individually or combined) exceeds the latest time the protocol can represent. |
| `tecLIMIT_EXCEEDED` | The requested loan would cause the `LoanBroker` ledger entry to exceed its maximum allowed debt.The vault's `AssetsTotal` already meets or exceeds its `AssetsMaximum`. Doesn't apply to cash-basis vaults.The loan's interest would push the vault's `AssetsTotal` past its `AssetsMaximum`. Doesn't apply to cash-basis vaults. |
| `tecNO_ENTRY` | The `LoanBroker` doesn't exist. |
| `tecNO_PERMISSION` | Neither the transaction sender's `Account` or the `Counterparty` field owns the associated `LoanBroker` ledger entry.The vault is closed-ended and the loan's final scheduled payment is less than 60 seconds before the vault's `RedemptionDate`. _The [LendingProtocolV1_1 amendment](/resources/known-amendments#lendingprotocolv1_1) updates this. (Open for Voting: 0.00%)_ |
| `tecPRECISION_LOSS` | `PrincipalRequested` or one of the fee amounts is more precise than the vault's asset can hold.The amount fits the asset, but is more precise than the loan's `LoanScale`. |
| `tecTOO_SOON` | The vault is closed-ended and still in its *Subscription* phase. _Requires the [LendingProtocolV1_1 amendment](/resources/known-amendments#lendingprotocolv1_1). (Open for Voting: 0.00%)_ |
| `temBAD_SIGNATURE` | The `SigningPubKey` inside the `CounterpartySignature` isn't a valid public key. |
| `temBAD_SIGNER` | The transaction *isn't* part of a `Batch` transaction and is missing a `CounterpartySignature`.`Counterparty` is omitted and `LoanBrokerID` doesn't match an existing `LoanBroker` entry. |
| `temINVALID` | `Data` is present but empty, or longer than 256 bytes.A numeric field is outside its valid range. For example, the `GracePeriod` can't be longer than the `PaymentInterval` or less than `60` seconds.`LoanBrokerID` is zero. |
| `temINVALID_FLAG` | `Flags` contains a value other than `tfLoanOverpayment`.The transaction requests reserve sponsorship, which  doesn't support. _The [Sponsor amendment](/resources/known-amendments#sponsor) updates this. (Open for Voting: 17.14%)_ |