Swap with V2

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:

      const signer = new ethers.Wallet(privateKey, provider);
      const provider = new ethers.providers.JsonRpcProvider("https://api.hyperliquid-testnet.xyz/evm");
      const amountOutMin = ethers.utils.parseUnits("100", 6);
      const to = walletAddress; // Replace with your wallet address
      const ethAmount = "0.1"; // Amount of ETH to swap
      await swapETHForUSDC(provider, signer, amountOutMin, to, ethAmount);

3. Run the script:

node index.js

Last updated