# 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 [<mark style="color:blue;">**SDK**</mark>](https://github.com/expand-network/sdk-nodejs.git), follow these steps:-

### **Step 1:** Installation

&#x20;User needs to install the expand.network SDK using the following command:&#x20;

```git
npm i expand-network
```

### **Step 2: Wallet Initialisation**

```javascript
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**

```javascript
// 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**

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

### **Step 5: Send Transaction**

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

### Sample code to approve a fungible token using Fordefi:&#x20;

```javascript
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();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.expand.network/integrations/supported-wallets/mpc-wallets/fordefi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
