Prerequisites
Before you begin, ensure that you’ve:- Installed Node.js v22+.
- Created an EVM wallet using a wallet provider such as MetaMask and added Arc Testnet as a network.
- Funded your wallet with testnet cirBTC for collateral and testnet USDC for gas on Arc Testnet from the Circle Faucet.
Step 1. Set up the project
1.1. Create the project and install dependencies
Create a project directory, initialize a Node.js project with an ES module type and run scripts, then install runtime and dev dependencies:Shell
1.2. Configure TypeScript (optional)
This step is optional. It helps prevent missing types in your IDE or editor.
tsconfig.json file configured for ESM and Node:
Shell
1.3. Set environment variables
Create a.env file in the project directory and add it to your .gitignore.
Open .env in your editor and add your wallet’s private key. Replace
YOUR_PRIVATE_KEY with the private key of the wallet you funded with cirBTC:
.env
Step 2. Explore available markets
kit.borrow.exploreMarkets returns the markets available on a blockchain along
with each market’s collateral and loan tokens, borrow APY, LLTV, and liquidity.
Use it to pick a market to borrow from.
2.1. Create the discovery script
Create anexplore-markets.ts file:
explore-markets.ts
2.2. Run the discovery script
In your terminal, run:Shell
marketId, borrowApy, lltv, and
liquidity fields. Copy a marketId for the next step.
To walk every matching market without paging through the results yourself, use
kit.borrow.exploreMarketsIterator. It accepts the same filters as
exploreMarkets and yields one market at a time:
TypeScript
Step 3. Open the loan
Each market allows one open loan per wallet at a time. If a loan is already open
for the wallet in that market, opening a new one raises
BORROW_LOAN_ALREADY_EXISTS
with the existing loanId in the message.3.1. Create the borrow script
Create aborrow.ts file. Replace YOUR_SELECTED_MARKET_ID with the market ID
you copied. This script borrows 1,000 USDC against cirBTC:
borrow.ts
3.2. Run the borrow script
In your terminal, run:Shell
loanId, the amountBorrowed, and
a txHash.
Step 4. Manage the loan
Use the loan’sloanId to keep operating on it over time:
- Add collateral or borrow more against the loan.
- Pay down the loan with a partial repayment, full close, or collateral withdrawal.
- Monitor the loan by reading its position or registering a webhook for health updates.