Skip to content

Fordefi Integration Guide

Fordefi is a blockchain security company that provides an institutional-grade MPC (Multi-Party Computation) non-custodial wallet specifically built for decentralized finance (DeFi).

Fordefi focuses on enhancing the security and efficiency of transactions in the DeFi space through the innovative use of MPC technology for key management and transaction signing, and by providing a secure and user-friendly interface through various clients:

  1. Fordefi Browser Extension for interaction with dApps.
  2. Fordefi Web Console for securely performing administrative operations such as setting up transaction policy rules and user management, which require approvals by a quorum of administrators.
  3. Fordefi API for developers to interact with the Fordefi infrastructure.

Read more about Fordefi on the site and docs.

Combining Fordefi with Account Kit allows you to get the best of both worlds. You can use Fordefi via the aa-signers package to generate a wallet scoped to your application, and then use aa-alchemy to create smart accounts for your users.

Integration

Install the Fordefi Web3 Provider

Using FordefiSigner in the aa-signers package requires installation of the @fordefi/web3-provider SDK. aa-signers lists it as optional dependency.

bash
npm i -s @fordefi/web3-provider
bash
yarn add @fordefi/web3-provider

Create a SmartAccountSigner

Next, setup the Fordefi Web3 Provider and create a SmartAccountSigner using the aa-signers package:

ts
import { FordefiSigner } from "@alchemy/aa-signers/fordefi";
import { FordefiWeb3Provider } from "@fordefi/web3-provider";

const fordefi = new FordefiWeb3Provider({
  address: "0x1234567890123456789012345678901234567890",
  chainId: 11155111,
  apiUserToken: process.env.FORDEFI_API_USER_TOKEN!,
  apiPayloadSignKey: process.env.FORDEFI_API_PAYLOAD_SIGNING_KEY!,
});

export const createFordefiSigner = async () => {
  const fordefiSigner = new FordefiSigner(fordefi);

  await fordefiSigner.authenticate();

  return fordefiSigner;
};

Use it with Modular Account

Let's see it in action with aa-alchemy:

ts
import { createModularAccountAlchemyClient } from "@alchemy/aa-alchemy";
import { sepolia } from "@alchemy/aa-core";
import { createFordefiSigner } from "./fordefi";

const chain = sepolia;

const signer = await createFordefiSigner();
const provider = await createModularAccountAlchemyClient({
  apiKey: "ALCHEMY_API_KEY",
  chain,
  signer,
});
ts
import { FordefiSigner } from "@alchemy/aa-signers/fordefi";
import { FordefiWeb3Provider } from "@fordefi/web3-provider";

const fordefi = new FordefiWeb3Provider({
  address: "0x1234567890123456789012345678901234567890",
  chainId: 11155111,
  apiUserToken: process.env.FORDEFI_API_USER_TOKEN!,
  apiPayloadSignKey: process.env.FORDEFI_API_PAYLOAD_SIGNING_KEY!,
});

export const createFordefiSigner = async () => {
  const fordefiSigner = new FordefiSigner(fordefi);

  await fordefiSigner.authenticate();

  return fordefiSigner;
};