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: