Initialize

The ParabolAccount class is the primary interface for direct blockchain interactions in the Parabol protocol. There are multiple ways to create and initialize a ParabolAccount instance, depending on your specific needs.

Creating a ParabolAccount

1. Using the constructor

You can create a ParabolAccount instance directly using a private key account from the viem library:

import { privateKeyToAccount } from "viem/accounts";
import { ParabolAccount, SupportedChainIds } from "@parabolfi/core";
 
const privateKey = "0x..."; // Your private key
const Account = privateKeyToAccount(privateKey);
const chainId = SupportedChainIds.ZKSYNC;
 
const account = new ParabolAccount(Account, chainId);

2. Using fromPrivateKey Static Method

Alternatively, you can use the fromPrivateKey static method, which creates the account for you:

import { ParabolAccount, SupportedChainIds } from "@parabolfi/core";
 
const privateKey = "0x..."; // Your private key
const chainId = SupportedChainIds.ZKSYNC;
 
const account = await ParabolAccount.fromPrivateKey({
  privateKey,
  chainId,
});

Initializing with Parabol Data (Required for Lending)

To use the core lending functionality, you need to initialize the ParabolAccount with Parabol data:

import { ParabolAccount, SupportedChainIds } from "@parabolfi/core";
import { ParabolServer } from "@parabolfi/server";
 
const parabolServer = new ParabolServer({
  apiKey,
});
 
const chainId = SupportedChainIds.ZKSYNC;
 
// Fetch Parabol data
const parabolData = await parabolServer.fetchLendParameters(chainId);
 
const privateKey = "0x..."; // Your private key
const chainId = SupportedChainIds.ZKSYNC;
 
// Initialize ParabolAccount with Parabol data
const account = await ParabolAccount.fromPrivateKey({
  privateKey,
  chainId,
  parabolData,
});

or just use setParabolData:

account.setParabolData(parabolData);

Adding Partner Configuration (Optional)

If you’re a partner or know the partner information, you can also include partner configuration during initialization:

đź’ˇ

There are two ways of fetching partner data: Using ParabolServer or ParabolAccount

1. Using the ParabolServer class

import { ParabolServer } from "@parabolfi/server";
 
const parabolServer = new ParabolServer({
  apiKey,
});
 
const response = await parabolServer.fetchPartnerConfig(walletAddress, [
  chainId,
]);
 
const partnerConfig = response[chainId];
 
const account = new ParabolAccount(Account, chainId);
 
account.setPartnerConfig(partnerConfig);

2. Using the ParabolAccount class

import { ParabolAccount } from "@parabolfi/core";
 
const account = ParabolAccount.fromPrivateKey({
  privateKey,
  chainId,
});
 
const partnerConfig = await account.getPartnerConfigByOwner(
  account.account.address
);
 
account.setPartnerConfig(partnerConfig);
đź’ˇ

Remember, initializing with parabolData is only required if you plan to use the lend functionality. For other operations, you can create a ParabolAccount instance without this step.

In addition to the above, you can also set the chainId after initializing the account. (See Supported Networks)

account.setChainId(chainId);
🌍

You can find and set the supported networks from @parabolfi/core package’s SupportedChainIds enum.

import { SupportedChainIds } from "@parabolfi/core";
 
account.setChainId(SupportedChainIds.ZKSYNC); // for ZKSYNC
account.setChainId(SupportedChainIds.BASE_SEPOLIA); // for BASE_SEPOLIA