# Withdrawing via Smart Contracts

## How to Repay Loans and Withdraw Collateral via Smart Contract&#x20;

Follow the steps here:

1. Go to the link below. You should be on the "*Contract*" and "*Write as Proxy*" tabs <https://arbiscan.io/address/0xe534ab76e7bcb2e8559815043491e662d13d43bc#writeProxyContract>

<figure><img src="https://548124530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RFiSnFFNN5tL05uK9pV%2Fuploads%2FVz8XPYfO0TuYqPrnMSr4%2Fsc5.png?alt=media&#x26;token=69a68f86-758c-48b3-ac3f-44c4eaebb0e7" alt=""><figcaption></figcaption></figure>

2. Click on the "*Connect to Web3*" button and connect your wallet.

<figure><img src="https://548124530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RFiSnFFNN5tL05uK9pV%2Fuploads%2FOXJABRuwTBOoLTDeOfFs%2Fsc6.png?alt=media&#x26;token=82ba48e2-e28b-4661-aa4d-175e414ab761" alt=""><figcaption></figcaption></figure>

3. **Repay your XY debt** first by clicking on "*8. repayDebtTokens*." \
   \
   Enter the token contract address of the isolated module in which you borrowed XY from in the "*\_asset (address) field*". For example, enter [0x4bD135524897333bec344e50ddD85126554E58B4 ](https://arbiscan.io/address/0x4bd135524897333bec344e50ddd85126554e58b4)(contract address of USDC/USDM Curve LP token) if you borrowed XY in the USDC/USDM Curve LP isolated module.\
   \
   Next, Enter the XY amount that you wish to repay under the "*\_debtTokenAmount (uint256)*" field. \
   \
   Under the "*\_upperHint (address)*" and "*lowerHint(address)*" fields, enter 0x0000000000000000000000000000000000000000

<figure><img src="https://548124530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RFiSnFFNN5tL05uK9pV%2Fuploads%2FRC8PcJFfmjh7g5zuhbrP%2Fsc3.png?alt=media&#x26;token=b533761f-6111-482c-b4e5-7ee03f03b8b0" alt=""><figcaption></figcaption></figure>

4. Click on the "+" tab next to the "*\_debtTokenAmount (uint256)*" field. Select the *10^18* option.&#x20;

<figure><img src="https://548124530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RFiSnFFNN5tL05uK9pV%2Fuploads%2FgheXUEFhSBx3ZlNrbEEV%2Fsc4.png?alt=media&#x26;token=5cf8c4f2-3492-48d1-b9ac-e651bf16ceeb" alt=""><figcaption></figcaption></figure>

5. You should now see the following page. Click on "*Write"* to confirm the transaction in your wallet.&#x20;

<figure><img src="https://548124530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RFiSnFFNN5tL05uK9pV%2Fuploads%2FmRtBMDvjrbwqq0QmeAmA%2Fsc2.png?alt=media&#x26;token=483d015d-ef97-4d8a-a675-98bea259f8ab" alt=""><figcaption></figcaption></figure>

6. Next, **withdraw your collateral.** Click on "16. withdrawColl"\
   \
   Enter the collateral token amount that you wish to withdraw under the "*\_collWithdrawal (uint256)*" field. For example, if you want to withdraw 5 USDM/Curve LP tokens, enter 5. \
   \
   This is the only difference from steps 3, 4, and 5, so follow the same steps as you did previously. Once you have completed the steps, you should see the following:

<figure><img src="https://548124530-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RFiSnFFNN5tL05uK9pV%2Fuploads%2FK11mi9ty3Uiym8tAARkM%2Fsc1.png?alt=media&#x26;token=4dd4c03c-a765-49e4-8bea-9e51e21e03f6" alt=""><figcaption></figcaption></figure>

7. Click on "*Write"* to confirm the transaction in your wallet. \
   \
   You have now successfully repaid your loan and withdrew your collateral via Tren Finance's smart contracts.
