Getting Started

Set up your development environment, connect to Base chain, and make your first contract call to DegenPrime.

1. RPC Connection

DegenPrime runs on Base chain (chainId 8453). You will need a Base RPC endpoint. Public endpoints work for reads, but a private RPC (Alchemy, QuickNode, etc.) is recommended for transaction submission.

typescript
import { createPublicClient, http } from "viem";
import { base } from "viem/chains";

const client = createPublicClient({
  chain: base,
  transport: http("https://mainnet.base.org"),
  // For production, use a dedicated RPC:
  // transport: http("https://base-mainnet.g.alchemy.com/v2/YOUR_KEY"),
});

2. Install Dependencies

You will need viem for contract interaction and @redstone-finance/evm-connector for wrapping solvency-sensitive transactions with price data.

bash
npm install viem @redstone-finance/evm-connector

3. First Contract Call

Let us read the USDC pool's total supply to verify your setup is working.

typescript
import { createPublicClient, http, parseAbi } from "viem";
import { base } from "viem/chains";

const client = createPublicClient({
  chain: base,
  transport: http("https://mainnet.base.org"),
});

const USDC_POOL = "0x20349D4A3DeE26B68Cb179fEB22A39dBf8523bab";

const totalSupply = await client.readContract({
  address: USDC_POOL,
  abi: parseAbi(["function totalSupply() view returns (uint256)"]),
  functionName: "totalSupply",
});

console.log("USDC Pool Total Supply:", totalSupply);

4. Creating a Loan

To interact with DegenPrime, you first create a Smart Loan via the Factory contract. The factory deploys a new Diamond proxy instance that becomes your isolated trading account.

typescript
import { createWalletClient, http, parseAbi } from "viem";
import { base } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount("0xYOUR_PRIVATE_KEY");

const walletClient = createWalletClient({
  account,
  chain: base,
  transport: http("https://mainnet.base.org"),
});

const FACTORY = "0x5A6a0e2702cF4603a098C3Df01f3F0DF56115456";

const hash = await walletClient.writeContract({
  address: FACTORY,
  abi: parseAbi(["function createLoan() returns (address)"]),
  functionName: "createLoan",
});

console.log("Loan creation tx:", hash);
// The loan address will be in the transaction receipt logs

5. Funding Your Loan

After creating a loan, you deposit collateral using the fund() function. You must approve the token transfer to the loan address first.

typescript
import { encodePacked, keccak256, parseAbi } from "viem";

const USDC = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
const loanAddress = "0xYOUR_LOAN_ADDRESS";
const amount = 1000n * 10n ** 6n; // 1000 USDC

// Step 1: Approve USDC transfer
await walletClient.writeContract({
  address: USDC,
  abi: parseAbi(["function approve(address,uint256)"]),
  functionName: "approve",
  args: [loanAddress, amount],
});

// Step 2: Fund the loan
const tokenId = keccak256(encodePacked(["string"], ["USDC"]));

await walletClient.writeContract({
  address: loanAddress,
  abi: parseAbi(["function fund(bytes32,uint256)"]),
  functionName: "fund",
  args: [tokenId, amount],
});

Next Steps