FORDEFI

Fordefi is an institutional MPC wallet and security platform built for decentralized finance (DeFi), offering MPC key management, self-serve DeFi policy controls, time-of-transaction smart contract insights, transaction simulation and risk alerts. To use FORDEFI with expand.network SDK, follow these steps:-

Step 1: Installation

User needs to install the expand.network SDK using the following command:

npm i expand-network

Step 2: Wallet Initialisation

const { WalletFordefi , prepareTransaction } = require('expand-network');
async function initialiseFordefiWallet(){
    const options = {
      accessToken: 'YOUR_ACCESS_TOKEN',  //Replace this with your bearer token
      xApiKey: 'YOUR_API_KEY',           //Replace this with your API key
      privateKeyFile: 'YOUR_PRIVATE_KEY', // Necessarily a .pem file
      vault_id: 'VAULT_ID'
    }
    const wallet  = new WalletFordefi(options);
    return wallet;
}

const wallet = await initialiseFordefiWallet();  //Initialise the wallet

Step 3: Prepare Transaction

// Preparing the approve transaction from expand.network
const preparedTx = await prepareTransaction("https://api.expand.network/fungibletoken/approve", {
        "from": "OWNER_WALLET_ADDRESS",
        "tokenAddress": "TOKEN_CONTRACT_ADDRESS",
        "to": "SPENDER_WALLET_ADDRESS",
        "amount": "100000",
        "gas": "25000",
         "chainId": "1",
        "xApiKey": "YOUR_API_KEY"     // Replace this with your API Key
    });
    preparedTx.chainId = '1';        // Replace with other chainId to toggle between chains

Step 4: Sign Transaction

// Sign the transaction locally using sdk client
const signedTx = await wallet.signTransaction(preparedTx);
console.log(signedTx);

Step 5: Send Transaction

// Send the signed transaction
const tx = await wallet.sendTransaction(signedTx);
console.log(tx);

Sample code to approve a fungible token using Fordefi:

const { WalletFordefi , prepareTransaction } = require('expand-network');
const xApiKey = 'YOUR_API_KEY';
const dotenv = require('dotenv');
async function initialiseFordefiWallet(){
    const options = {
      accessToken: 'YOUR_ACCESS_TOKEN',
      xApiKey:'YOUR_API_KEY',
      privateKeyFile: 'YOUR_PRIVATE_KEY_FILE',
      vault_id: 'VAULT_ID'
    }
    const wallet  = new WalletFordefi(options);
    return wallet;
}
async function main() {
    dotenv.config();
    const wallet = await initialiseFordefiWallet();
    const preparedTx = await prepareTransaction("https://api.expand.network/fungibletoken/approve", {
        "from": "OWNER_WALLET_ADDRESS",
        "tokenAddress":"TOKEN_CONTRACT_ADDRESS",
        "amount": "1000000000",
        "to": "SPENDER_WALLET_ADDRESS",
        "gas": "100000",
        "chainId": "1",
        "xApiKey": "YOUR_API_KEY"         
    });
    preparedTx.chainId = '1';
    const signedTx = await wallet.signTransaction(preparedTx);
    console.log(signedTx);
    const tx = await wallet.sendTransaction(signedTx);
    console.log(tx);
}
main();

Last updated