Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uniswap/v2-core

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniswap/v2-core

🎛 Core contracts for the UniswapV2 protocol

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is @uniswap/v2-core?

@uniswap/v2-core is a core smart contract library for the Uniswap V2 decentralized exchange protocol. It provides the essential building blocks for creating and managing liquidity pools, executing swaps, and handling token pairs on the Ethereum blockchain.

What are @uniswap/v2-core's main functionalities?

Liquidity Pool Creation

This feature allows users to create a new liquidity pool for a pair of ERC-20 tokens. The code sample demonstrates how to interact with the Uniswap V2 Factory contract to create a new token pair.

const { ethers } = require('ethers');
const UniswapV2Factory = require('@uniswap/v2-core/build/UniswapV2Factory.json');

async function createPair(factoryAddress, tokenA, tokenB) {
  const provider = new ethers.providers.JsonRpcProvider();
  const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
  const factory = new ethers.Contract(factoryAddress, UniswapV2Factory.abi, wallet);
  const tx = await factory.createPair(tokenA, tokenB);
  await tx.wait();
  console.log('Pair created:', await factory.getPair(tokenA, tokenB));
}

Swapping Tokens

This feature enables token swapping through the Uniswap V2 protocol. The code sample shows how to use the Uniswap V2 Router to swap a specific amount of input tokens for a minimum amount of output tokens along a specified path.

const { ethers } = require('ethers');
const UniswapV2Router02 = require('@uniswap/v2-periphery/build/UniswapV2Router02.json');

async function swapTokens(routerAddress, amountIn, amountOutMin, path, to, deadline) {
  const provider = new ethers.providers.JsonRpcProvider();
  const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider);
  const router = new ethers.Contract(routerAddress, UniswapV2Router02.abi, wallet);
  const tx = await router.swapExactTokensForTokens(amountIn, amountOutMin, path, to, deadline);
  await tx.wait();
  console.log('Swap executed');
}

Retrieving Pair Information

This feature allows users to retrieve information about a specific liquidity pair, such as the current reserves of the two tokens. The code sample demonstrates how to access the reserves of a Uniswap V2 pair contract.

const { ethers } = require('ethers');
const UniswapV2Pair = require('@uniswap/v2-core/build/UniswapV2Pair.json');

async function getReserves(pairAddress) {
  const provider = new ethers.providers.JsonRpcProvider();
  const pair = new ethers.Contract(pairAddress, UniswapV2Pair.abi, provider);
  const reserves = await pair.getReserves();
  console.log('Reserves:', reserves);
}

Other packages similar to @uniswap/v2-core

Keywords

FAQs

Package last updated on 18 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc