Application guide

Create a simple applicaton interface

In our applicaton guide we will cover the following:

  • Creation of an intent

  • Signing and submission of the intent

  • Fetching intentpool state

  • Display intent outcome on the frontend

1. Installation

To include 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.js into your project to begin defining intents:

import { IntentBuilder, PROJECTS, CHAINS, toBigInt, Asset, Stake } from 'fabriq-sdk';
import {  } from 'viem';

Usage

1. Initializing the SDK

Create an instance of the IntentBuilder:

const intentBuilder = await IntentBuilder.createInstance(BUNDLER_URL);

2. Creating and Executing an Intent

To create and execute an intent with the intents.js SDK, you need to specify the details of the transaction you want to perform. This involves defining the source (from) and destination (to) assets, including their types, addresses, and amounts.

Here's an example of creating and executing a swap intent:

import { IntentBuilder, PROJECTS, CHAINS, Asset, Stake, toBigInt, Account, amountToBigInt } from './src';
import { ethers } from 'ethers';
import { ChainConfigs } from './src/types';

const signer = new ethers.Wallet('private key');

const amount = 0.1;
const ethAddress = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
const ethDecimals = 18;

const from = new Asset({
  address: ethAddress,
  amount: amountToBigInt(amount, ethDecimals),
  chainId: toBigInt(CHAINS.Ethereum),
});

const to = new Stake({
  amount: amountToBigInt(amount, ethDecimals),
  address: PROJECTS.Lido,
  chainId: toBigInt(CHAINS.Ethereum),
});

async function executeIntent() {
  const chainConfigs: ChainConfigs = {
    888: {
      rpcUrl: 'https://virtual.mainnet.rpc.tenderly.co/13d45a24-2474-431e-8f19-31f251f6cd2a',
      bundlerUrl: 'https://eth.bundler.dev.balloondogs.network',
    },
    890: {
      rpcUrl: 'https://virtual.binance.rpc.tenderly.co/4e9d15b6-3c42-43b7-a254-359a7893e8e6',
      bundlerUrl: 'https://bsc.bundler.dev.balloondogs.network',
    },
  };

  const account = await Account.createInstance(signer, chainConfigs);
  const intentBuilder = await IntentBuilder.createInstance(chainConfigs);

  try {
    await intentBuilder.execute(from, to, account, 888);
    console.log('Intent executed successfully.');
  } catch (error) {
    console.error('Error executing intent:', error);
  }
}

executeIntent();

Last updated