LogoLogo
  • Overview
  • Getting Started
  • 🔑How do I get my API Key?
  • 📑List of All Endpoints
  • ⚙️SDK
    • Overview
    • Getting Started
  • ⛓️INTEGRATIONS
    • ⚡Blockchains
      • EVM based blockchains
        • Ethereum
        • Binance Smart Chain
        • Avalanche - C
        • Avalanche - P
        • Avalanche - X
        • Polygon
        • Cronos
        • Arbitrum
        • Fantom
        • Optimism
        • Base
        • zkSync Era
        • Mantle
      • Non-EVM based chains
        • Tron
        • Solana
        • Near
        • Algorand
        • Aptos
        • Sui
        • Starknet
        • TON
        • Cosmos Hub
        • Osmosis
        • Stacks
        • Bitcoin
        • Stellar
          • Stellar RWA
        • XRP Ledger
          • XRP Ledger RWA
    • ⚡Bridges
      • Stargate
      • Stargate V2
      • Squid Router
      • Squid Router V2
      • Allbridge Classic
      • Allbridge Core
    • ⚡DEX & DEX Aggregators
      • Uniswap V2
      • Uniswap V3
      • Uniswap X
      • Sushiswap V2
      • PancakeSwap V2
      • PancakeSwap V3
      • Aerodrome
      • Camelot V3
      • Curve V2
      • Balancer V2
      • STON.fi
      • Trader Joe
      • Orca
      • Raydium
      • SDEX
      • Cetus
      • REF Finance
      • Liquidswap
      • Sologenic
      • Alex
      • 0x (Aggregator)
      • 1inch (Aggregator)
      • Kyberswap (Aggregator)
        • Kyberswap ( Limit Order Endpoints )
      • Jupiter (Aggregator)
    • ⚡Derivatives
      • dYdX V4
    • ⚡Fungible Tokens
      • ERC20
      • WETH
    • ⚡Lending Protocols
      • Aave V2
      • Aave V3
      • Compound V2
      • Compound V3
      • Morpho
    • ⚡Yield Aggregators
      • Yearn Finance V2
      • Harvest Finance
      • Pendle
    • ⚡Liquid Staking
      • Chorus One
      • Lido V2
      • Stader
      • Benqi
      • Jito
      • EigenLayer
    • ⚡Non Fungible Tokens
      • ERC721
      • ERC1155
      • Metaplex
    • ⚡Oracles
      • ChainLink
      • WinkLink
      • Pyth Network
      • RedStone
    • ⚡Stablecoins
      • EVM
    • ⚡Synthetics
      • Synthetix
    • ⚡Supported Wallets
      • MPC Wallets
        • DFNS
        • FORDEFI
        • FIREBLOCKS
        • CIRCLE
      • HD Wallets
        • PHANTOM
        • COINBASE
        • TON Wallet
      • Wallet Connect v2
  • How To
    • Execute a Local Swap
    • Execute a Cross Chain Swap
    • Use Limit Orders
    • Lend and Borrow
    • Provision Liquidity
      • Adding Liquidity
      • Removing liquidity
    • Yield Farm
    • Use Our Transaction Decoder
    • Submit an RFQ
    • Subscribe to Events
    • Stream Data (WebSocket)
      • Stream Transaction
      • Stream Trade
      • Stream Gas
      • Stream Ticker Price
    • Source Pricing
    • Track Memecoins
    • Manage Token Approvals
  • Use Cases
    • Trade Reconciliation
    • Portfolio Management
    • Trading Features
    • On-Chain Data: DEX Liquidity Pool Forensics
    • Transaction and Pool Analysis
  • Account Abstraction
    • Overview
      • User Endpoints
      • Paymaster Endpoint
      • Bundler Endpoint
    • ⚙️SDK - Overview
  • Additional Info
    • Error Messages
    • Client-Side Security Essentials
    • Compute Unit Costs
    • API Metadata
    • Audit Certificate
    • Brand Assets
    • FAQs
    • Quicknode Marketplace
      • DEX
      • Lending Protocols
  • ID's
    • Chain IDs
    • Bridge IDs
      • Internal Chain IDs for Bridges
    • DEX IDs
    • Lending Protocol IDs
    • Yield Aggregator ID
    • Liquid Staking IDs
    • Oracle IDs
    • Stablecoin IDs
    • Derivatives IDs
    • Synthetics IDs
  • Mapping
    • Blockchains
    • DEXs
      • Uniswap V2
      • Uniswap V3
      • Sushiswap
      • PancakeSwap
      • Curve
      • Balancer
    • Lending Protocols
      • Aave
      • Compound
  • Protocol Spender
    • Spender list
Powered by GitBook
On this page
  • Step 1: Installation
  • Step 2: Wallet Initialisation
  • Step 3: Prepare Transaction
  • Step 4: Sign Transaction
  • Step 5: Send Transaction
  • Sample code to perform a swap using DFNS:
  1. INTEGRATIONS
  2. Supported Wallets
  3. MPC Wallets

DFNS

PreviousMPC WalletsNextFORDEFI

Last updated 5 months ago

Dfns is a cybersecurity company providing crypto wallet infrastructure. The company develops a wallet-as-a-service infrastructure in Web3. To use DFNS with expand.network , 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 { WalletDFNS , prepareTransaction } = require('expand-network');
async function initialiseDFNSWallet(){
    const options = {};
    options.privateKey = process.env.DFNS_PRIVATE_KEY;
    options.credId = process.env.DFNS_CRED_ID;
    options.xApiKey = process.env.X_API_KEY;
    options.appId = process.env.DFNS_APP_ID;
    options.authToken = process.env.DFNS_ACCESS_TOKEN;
    options.baseUrl = process.env.DFNS_API_URL;
    options.walletId = process.env.WALLET_ID;
    options.appOrigin = 'http://localhost:3000';
    const wallet  = await new WalletDFNS(options);
    return wallet;
}

const wallet = await initialiseDFNSWallet();    // Initialise the wallet client

Step 3: Prepare Transaction

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

Step 4: Sign Transaction

// Sign the transaction locally using sdk client
const approveSignedTx = await wallet.signTransaction(prepareApproveTx);         
approveSignedTx.chainId = '1';  // Replace with other chainId to toggle between chains

Step 5: Send Transaction

// Send the signed transaction
let txHash = await wallet.sendTransaction(approveSignedTx);         
console.log(`approve transaction: https://etherscan.io/tx/${txHash.TxHash}`);  // Confirmation

Sample code to perform a swap using DFNS:

const { WalletDFNS , prepareTransaction } = require('expand-network');
const dotenv = require('dotenv');
async function initialiseDFNSWallet(){
    const options = {};
    options.privateKey = process.env.DFNS_PRIVATE_KEY;
    options.credId = process.env.DFNS_CRED_ID;
    options.xApiKey = process.env.X_API_KEY;
    options.appId = process.env.DFNS_APP_ID;
    options.authToken = process.env.DFNS_ACCESS_TOKEN
    options.baseUrl = process.env.DFNS_API_URL;
    options.walletId = process.env.WALLET_ID;
    options.appOrigin = 'http://localhost:3000';
    const wallet  = await new WalletDFNS(options);
    return wallet;
}

async function main() {
    dotenv.config();            
    const wallet = await initialiseDFNSWallet();            // Initialise the wallet client
    const xApiKey = process.env.X_API_KEY;      
    const prepareApproveTx = await prepareTransaction('https://api.expand.network/fungibletoken/approve', {       // Prepare the approve transaction from expand.network
        "from": "OWNER_WALLET_ADDRESS",
        "tokenAddress": "TOKEN_CONTRACT_ADDRESS",
        "to": "SPENDER_WALLET_ADDRESS",
        "amount": "100000",
        "gas": "25000",
        "xApiKey": "YOUR_API_KEY"                     // Replace this with your API Key
    });
    prepareApproveTx.chainId = '1';          // Replace with other chainId to toggle between chains

    const approveSignedTx = await wallet.signTransaction(prepareApproveTx);             // Sign the transaction locally using sdk client

    approveSignedTx.chainId = '1';          // Replace with other chainId to toggle between chains
              

    let txHash = await wallet.sendTransaction(approveSignedTx);                 // Send the transaction
    console.log(`approve transaction: https://etherscan.io/tx/${txHash.TxHash}`);          // Confirmation
    
    const swapTransaction = await prepareTransaction('https://api.expand.network/dex/swap',{            // Simlarly build the swap Tx
            "dexId":"1000",  // Replace with other dexId to toggle between dexs
            "amountIn": "100000",
            "amountOutMin": "0",
            "path": ["TOKEN_ADDRESS_TO_SWAP_FROM","TOKEN_ADDRESS_TO_SWAP_TO"],
            "to": "RECEIVER_WALLET_ADDRESS",
            "deadline": "1965990894",
            "from": "SENDER_WALLET_ADDRESS",
            "gas": "173376",
            "xApiKey": "YOUR_API_KEY"               // Replace this with your API Key
    });
    console.log(swapTransaction);
    swapTransaction.chainId = '1';              // Replace with other chainId to toggle between chains

    const swapSignedTx = await wallet.signTransaction(swapTransaction);
    swapSignedTx.chainId = '1'                  // Replace with other chainId to toggle between chains

    const txHash1 = await wallet.sendTransaction(swapSignedTx);
    console.log(`swap transaction: https://etherscan.io/tx/${txHash1.TxHash}`);
}
main();
⛓️
⚡
SDK