# Loan - Repayment

The following code example is provided to help you understand the business process. For commercial use, you must handle parameter validation and exception handling on your own.

This example is tested on the **Polygon-Amoy** chain. Information used in the example can be retrieved from the **Source** directory.

***

#### **Code Example**

```javascript
javascriptCopy code// Import web3js library
import Web3 from 'web3';
import ApproveTradeABI from '../abi/ApproveTrade.json';

// This example is tested on the Polygon-Amoy chain
const amoy_chainId = 80002;
const amoy_chainName = "AMOY";
const amoy_chainRpcUrl = "https://polygon-amoy.infura.io/v3/4ba314367838400fb88f2a1d0e14d42d";
const amoy_contract_ApproveTrade = "0xF1831ebb3f92A8607E644A1E54Fde4b09F6FE5dE";
const amoy_account = "0xA3932E6Dbf96983Ffdf43974c0BF7edE9fed76DF";

// Initialize web3 instance
// WalletProvider or HttpProvider
const web3 = new Web3("** Wallet **"); // window.ethereum
const Contract = new web3.eth.Contract(ApproveTradeABI, amoy_contract_ApproveTrade);

// 1. Repayment Example Parameters
// Parameters come from the creator's history API.
//  -- `orderHash` can be found in the `f_order_hash` field.
//  -- `redeemAmount` is located in `f_order_info/currency[0]/amountOrID` and includes interest.
// Ensure that the payment token (ERC20) has been approved and that the wallet and approval balance are sufficient.
// If the repayment token is the network native token, you must send it as part of the transaction.

const orderHash = "0x5973f68a96d2b67e9fb647b3f9c916c95ad308dd18cc06a7e70b27c3abcb70aa";
const redeemAmount = "1000000000"; // Amount including interest

// 2. Initiate Repayment Operation
const handleRedeem = Contract.methods.redeem([
    orderHash
]).send({
    from: amoy_account,
    value: redeemAmount // Note: if the repayment asset is a network native token
});

handleRedeem.then(receipt => {
    console.log(receipt);
}).catch(error => {
    console.log(error);
});
```

#### **Key Notes**:

1. **Order Hash**: The `orderHash` must be retrieved from the creator's history API and is found in the `f_order_hash` field.
2. **Redeem Amount**: The redeem amount, including interest, is found in the `f_order_info/currency[0]/amountOrID`. Make sure the amount includes any applicable interest.
3. **Payment Token**: If the repayment token is an ERC20 token, ensure that it has been approved for use with the contract and that there is a sufficient balance. If the repayment token is the network native token (e.g., MATIC), send it directly as part of the transaction using the `value` field in `.send()`.

This code demonstrates how to initiate a repayment transaction on the **Polygon-Amoy** chain. Adjust the parameters as needed based on your specific requirements.

4o


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.paddlefi.com/api-documentation/tutorials/loan-repayment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
