Application guide

Create a simple application interface

In our application guide we will cover the following:

  • Installation

  • Setup

  • Initialization of the IntentClient class

  • The creation and submission of an intent

  • Fetching intentpool state to be displayed on the frontend

1. Installation

To install the fabriq-sdk in your project, ensure you have Node.js and yarn installed in your environment and run the following command:

yarn add fabriq-sdk

2. Setup

Import fabriq-sdk into your project to start:

import { IntentClient, intentPoolURL } from 'fabriq-sdk';
import { Hex, Address, maxUint256, createPublicClient, WalletClient, PublicClient} from 'viem';

3. Initializing the IntentClient class

To create an instance of the IntentClient class, one has to create a wallet client first with the desired network and account(this example is using an embedded browser account). There is a possibility to add a specific intentPoolUrl to submit the intents to.

const walletClient = createWalletClient({ 
   chain: hardhat, 
   transport: custom(window.ethereum) 
});

const intentClient = new intentClient(walletClient, intentPoolURL);

4. Creating and submitting an Intent

To submit an intent to the intent pool, you need to specify the details of the intent you want to create. This involves defining the source and destination chain IDs , the asset amount to be transferred, the inputAddress which is the asset address on the source chain and the output address which is the asset address on the destination chain.

intentClient.approvePermit2(tokenAddress: Address)

intentClient.submitIntent(
    inputAddress: Address,
    outputAddress: Address,
    amount: bigint,
    srcChainId: number,
    dstChainId: number
);

5. Getting intent pool statistics data

The following functions will help get the intentpool data for an enhanced user experience on the application level.

 /**
   * Fetches the balance of a specific token for the current account.
*/
async getBalance(token: Address) {}

/**
 * Fetches details about a specific intent using its hash.
 */
async getIntent(intentHash: Hex) {}

/**
 * Retrieves all intents originating from a specific chain.
 */
async getAllIntentsWithOrigin(chainId: Number) {}

/**
 * Retrieves all intents targeting a specific destination chain.
 */
async getAllIntentsWithDestination(chainId: Number) {}

/**
 * Fetches a specified number of solved intents.
 */
async getSolvedIntents(numberOfIntents: Number) {}

/**
 * Fetches a specified number of pending intents.
 */
async getPendingIntents(numberOfIntents: Number) {}

Last updated