HyperSwap Docs
  • 🔎| HyperSwap
  • 🔗| Official Links
  • ❓| How to Start ?
    • Create a Wallet
    • How to Bridge on HyperEVM ?
  • PROTOCOL CONCEPTS
    • 🌐| Overview
    • 🏊Liquidity Pool
      • AMM Standard Liquidity Position
      • Concentrated Liquidity Position
      • ⚡Single Asset ZAP
    • 📐| Constant Factor AMM
    • 💲| Dynamic Fees
    • ✉️| Partner Referral
  • Points
    • 💎| Point Program
  • Token Design
    • ⛏️| Liquidity Mining
    • 🔄| Conversion and Redemption
    • 🤝| Revenues Sharing Model
    • 💰| Protocol Earnings
    • 🔥| Deflationary mechanisms
  • TOKENS
    • 🪙| $SWAP
    • 🔓| $xSWAP
  • Contracts
    • 📜| Hyper EVM
      • V2
      • V3
      • 🧰Tools
    • 📜| Testnet
      • V2
      • V3
    • 🖨️| Integrations
      • ⏯️Templates & Use Cases
      • 🏃Quick Start
        • V2
          • Swap with V2
          • Add liquidity with V2
          • Functions
        • V3
          • Swap with V3
        • Single Asset ZAP
          • Provide Liquidity With V2
          • Provide Liquidity With V3
          • Functions
  • REFERENCES
    • | Audits
    • 📖| Glossary
    • 🎨| Media Kit
Powered by GitBook
On this page
  1. Contracts
  2. | Integrations
  3. Quick Start
  4. V3

Swap with V3

Be sure to respect all the necessary requirements present in V3

Swapping Tokens

Use the provided swapTokens function to swap ETH for USDC:

1. Open the index.js file in your editor.

2. Replace the placeholder values in the main() function:

async function main() {
  try {
    console.log('Initializing wallet...');

    // Swap example
    const swapParams = {
      tokenIn: process.env.IN_ADDRESS,
      tokenOut: process.env.OUT_ADDRESS,
      recipient: wallet.address,
      
      amountOutMinimum: ethers.utils.parseUnits("0", 8), // Minimum USDC expected,
    };

    console.log('Swapping tokens...');
    const receipt = await exactInputSingleSwap(provider, wallet, swapParams.amountIn, swapParams.recipient, swapParams.amountOutMinimum, swapParams.tokenIn, swapParams.tokenOut);
    console.log('Swap completed! Transaction hash:', receipt.transactionHash);
  } catch (error) {
    console.error('An error occurred:', error);
  }
}

Note that in order to execute the swap correctly, you need to provide the decimals of each token you wish to swap

3. Run the script:

node index.js
PreviousV3NextSingle Asset ZAP

Last updated 3 months ago

🖨️
🏃