Polygon Blockchain

by dbillionaer

2 stars
269 downloads
Not rated
GitHub

About

Integrates with the Polygon blockchain network to enable wallet operations, smart contract deployments, L2 bridging, DeFi interactions, and transaction simulations using ethers.js v6 across both Mainnet and Mumbai Testnet environments.

Details

Author
dbillionaer
Repository
Dbillionaer/polygon-mcp
GitHub stars
2
Downloads
269
Categories
Design, Developer Tools, AI, Infrastructure, Frontend, Other

- Wallet operations: get address, list balances, transfer funds
- Smart contract deployment and verification on Polygonscan
- L2 bridge operations: deposit and withdraw ETH/ERC20 tokens
- DeFi interactions: QuickSwap and Uniswap V3 DEX swaps
- Polymarket prediction market betting and position tracking
- Transaction simulation and gas estimation with EIP-1559 support

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Polygon Blockchain
    Command (node, npx, python, etc.) node
    Arguments
    • Argument 1 path/to/polygon-mcp.js
    Environment
    • PRIVATE_KEY your_private_key_here
    • DEFAULT_NETWORK amoy
    • DEFAULT_SLIPPAGE 0.5
    • ETHEREUM_RPC_URL https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
    • POLYGON_AMOY_RPC https://rpc-amoy.polygon.technology
    • POLYGONSCAN_API_KEY YOUR_EXPLORER_API_KEY
    • POLYGON_MAINNET_RPC https://polygon-rpc.com
    • DEFAULT_DEADLINE_MINUTES 20

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

1. Clone the repository or download the source code
2. Install dependencies:

cd polygonmcp
npm install

3. Create a .env file with the following variables:


DEFAULT_SLIPPAGE=0.5
DEFAULT_DEADLINE_MINUTES=20

Start the server:

npm start

For development with auto-restart:

npm run dev

get-address

Retrieve the current wallet address.

get-testnet-pol

Request testnet POL from a faucet (Amoy testnet only).

list-balances

List token balances for the connected wallet.

transfer-funds

Transfer POL or ERC20 tokens to another address. Parameters: to (string), amount (string), token (optional string).

deploy-contract

Deploy a smart contract to Polygon. Parameters: templateId (string), params (object), constructorArgs (optional array).

verify-contract

Verify a deployed contract on Polygonscan. Parameters: address (string), name (string), code (string), constructorArgs (array).

list-contract-templates

List available contract templates.

deposit-eth

Deposit ETH from Ethereum to Polygon. Parameters: amount (string).

withdraw-eth

Withdraw ETH/POL from Polygon to Ethereum. Parameters: amount (string).

deposit-token

Deposit ERC20 from Ethereum to Polygon. Parameters: token (string), amount (string).

withdraw-token

Withdraw ERC20 from Polygon to Ethereum. Parameters: token (string), amount (string).

swap-tokens

Swap tokens using QuickSwap. Parameters: fromToken (string), toToken (string), amount (string).

get-swap-quote

Get a price quote for a token swap. Parameters: fromToken (string), toToken (string), amount (string).

add-liquidity

Add liquidity to a QuickSwap pool. Parameters: tokenA (string), tokenB (string), amountA (string), amountB (string).

uniswapV3SwapSingle

Execute single-hop swaps on Uniswap V3. Parameters: tokenIn (string), tokenOut (string), amount (string), fee (string).

uniswapV3SwapMulti

Execute multi-hop swaps on Uniswap V3. Parameters: path (array), amounts (array).

getUniswapV3QuoteSingle

Get quotes for single-hop swaps on Uniswap V3. Parameters: tokenIn (string), tokenOut (string), amount (string), fee (string).

getUniswapV3QuoteMulti

Get quotes for multi-hop swaps on Uniswap V3. Parameters: path (array), amount (string).

getPolymarketInfo

Get market information. Parameters: marketId (string).

placePolymarketBet

Place bets by buying position tokens. Parameters: marketId (string), outcome (string), amount (string).

getPolymarketPositions

Get user positions for a market. Parameters: marketId (string).

simulate-transaction

Simulate a transaction to preview its effects. Parameters: txParams (object).

estimate-gas

Estimate gas for a transaction. Parameters: txParams (object).

get-gas-price

Get current gas prices on Polygon.

switch-network

Switch between Polygon Mainnet and Amoy Testnet. Parameters: network (string).

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "polygon blockchain": {
            "env": {
                "PRIVATE_KEY": "your_private_key_here",
                "DEFAULT_NETWORK": "amoy",
                "DEFAULT_SLIPPAGE": "0.5",
                "ETHEREUM_RPC_URL": "https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY",
                "POLYGON_AMOY_RPC": "https://rpc-amoy.polygon.technology",
                "POLYGONSCAN_API_KEY": "YOUR_EXPLORER_API_KEY",
                "POLYGON_MAINNET_RPC": "https://polygon-rpc.com",
                "DEFAULT_DEADLINE_MINUTES": "20"
            },
            "args": [
                "path/to/polygon-mcp.js"
            ],
            "command": "node"
        }
    }
}

Linux

{
    "env": {
        "PRIVATE_KEY": "your_private_key_here",
        "DEFAULT_NETWORK": "amoy",
        "DEFAULT_SLIPPAGE": "0.5",
        "ETHEREUM_RPC_URL": "https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY",
        "POLYGON_AMOY_RPC": "https://rpc-amoy.polygon.technology",
        "POLYGONSCAN_API_KEY": "YOUR_EXPLORER_API_KEY",
        "POLYGON_MAINNET_RPC": "https://polygon-rpc.com",
        "DEFAULT_DEADLINE_MINUTES": "20"
    },
    "args": [
        "path/to/polygon-mcp.js"
    ],
    "command": "node"
}

Macos

{
    "env": {
        "PRIVATE_KEY": "your_private_key_here",
        "DEFAULT_NETWORK": "amoy",
        "DEFAULT_SLIPPAGE": "0.5",
        "ETHEREUM_RPC_URL": "https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY",
        "POLYGON_AMOY_RPC": "https://rpc-amoy.polygon.technology",
        "POLYGONSCAN_API_KEY": "YOUR_EXPLORER_API_KEY",
        "POLYGON_MAINNET_RPC": "https://polygon-rpc.com",
        "DEFAULT_DEADLINE_MINUTES": "20"
    },
    "args": [
        "path/to/polygon-mcp.js"
    ],
    "command": "node"
}

Windows

{
    "env": {
        "PRIVATE_KEY": "your_private_key_here",
        "DEFAULT_NETWORK": "amoy",
        "DEFAULT_SLIPPAGE": "0.5",
        "ETHEREUM_RPC_URL": "https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY",
        "POLYGON_AMOY_RPC": "https://rpc-amoy.polygon.technology",
        "POLYGONSCAN_API_KEY": "YOUR_EXPLORER_API_KEY",
        "POLYGON_MAINNET_RPC": "https://polygon-rpc.com",
        "DEFAULT_DEADLINE_MINUTES": "20"
    },
    "args": [
        "/c",
        "node",
        "path/to/polygon-mcp.js"
    ],
    "command": "cmd"
}

Polygon MCP Server

License: MIT
Node.js: v18+

A Model Context Protocol (MCP) server that provides seamless integration with the Polygon blockchain network. This server enables AI assistants to interact with Polygon through a standardized interface, offering comprehensive tools for wallet operations, smart contract deployment, L2 bridging, DeFi interactions, and transaction simulations.

Table of Contents

- Introduction
- Quick Start
- Features
- Architecture
- API Reference
- Advanced Usage
- Troubleshooting
- Contributing
- Security Considerations
- License

Introduction

Polygon is a Layer 2 scaling solution for Ethereum that provides faster and cheaper transactions while maintaining Ethereum's security. This MCP server allows AI assistants to interact with the Polygon network, enabling a wide range of blockchain operations through a simple, standardized interface.

The server acts as a bridge between AI systems and the Polygon blockchain, handling the complexities of blockchain interactions and providing a clean, easy-to-use API for common operations.

┌─────────────┐     ┌───────────────┐     ┌─────────────────┐
│             │     │               │     │                 │
│  AI System  ├─────┤  Polygon MCP  ├─────┤  Polygon Chain  │
│             │     │    Server     │     │                 │
└─────────────┘     └───────────────┘     └─────────────────┘

Quick Start

Prerequisites

- Node.js (v18 or higher)
- npm or yarn
- A Polygon wallet private key (for signing transactions)
- RPC endpoints for Polygon Mainnet and Amoy Testnet

Installation

1. Clone the repository or download the source code
2. Install dependencies:

cd polygonmcp
npm install

3. Create a .env file with the following variables:

# Network RPC endpoints
POLYGON_MAINNET_RPC=https://polygon-rpc.com
POLYGON_AMOY_RPC=https://rpc-amoy.polygon.technology
ETHEREUM_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_ALCHEMY_KEY  # Sepolia for Amoy's L1

API Keys

POLYGONSCAN_API_KEY=YOUR_EXPLORER_API_KEY # Use OKLink API key for Amoy

Wallet (IMPORTANT: Use secure key management in production)

PRIVATE_KEY=your_private_key_here DEFAULT_NETWORK=amoy # Use 'amoy' for testnet

DeFi Configuration (Optional)

DEFAULT_SLIPPAGE=0.5 DEFAULT_DEADLINE_MINUTES=20

Running the Server

Start the server:

npm start

For development with auto-restart:

npm run dev

First Steps

1. Check your wallet balance:

   import { PolygonMCPServer } from './polygon-mcp.js';
const server = new PolygonMCPServer();

async function checkBalance() {
// Wallet is connected automatically on server start if PRIVATE_KEY is in .env
// await server.connectWallet(process.env.PRIVATE_KEY);
const balances = await server.listBalances();
console.log('Wallet balances:', balances);
}

checkBalance().catch(console.error);

2. Get testnet POL (Amoy testnet only):

   async function getTestPol() {
// Wallet is connected automatically on server start if PRIVATE_KEY is in .env
// await server.connectWallet(process.env.PRIVATE_KEY);
const result = await server.getTestnetPol();
console.log('Faucet result:', result);
}

3. Simulate a transaction:

   // Wallet is connected automatically on server start if PRIVATE_KEY is in .env

async function simulateTransaction() {
const result = await server.simulateTransaction({
to: '0x1234...', // Recipient address
value: '0.01', // Amount in MATIC (or native token)
});
console.log('Simulation result:', result);
}

Features

Wallet Operations

| Tool | Description | Example |
|------|-------------|---------|
| get-address | Retrieve the current wallet address | const address = await server.getAddress() |
| get-testnet-pol | Request testnet POL from a faucet (Amoy testnet only) | await server.getTestnetPol() |
| list-balances | List token balances for the connected wallet | const balances = await server.listBalances() |
| transfer-funds | Transfer POL or ERC20 tokens to another address | await server.transferFunds('0x1234...', '0.1', 'MATIC') |

The wallet manager provides:
- Enhanced wallet connection validation
- Support for multiple networks
- Improved error handling with detailed messages
- Secure private key management

Smart Contract Operations

| Tool | Description | Example |
|------|-------------|---------|
| deploy-contract | Deploy a smart contract to Polygon | await server.deployContract(name, code, args) |
| verify-contract | Verify a deployed contract on Polygonscan | await server.verifyContract(address, name, code, args) |
| list-contract-templates | List available contract templates | const templates = await server.listContractTemplates() |

Supported contract types:
- ERC20 tokens
- ERC721 NFT collections
- ERC1155 multi-tokens
- Staking contracts
- Multisig wallets

L2 Bridge Operations

| Tool | Description | Example |
|------|-------------|---------|
| deposit-eth | Deposit ETH from Ethereum to Polygon | await server.mcpServer.callTool('deposit-eth', { amount: '0.1' }) |
| withdraw-eth | Withdraw ETH/POL from Polygon to Ethereum | await server.mcpServer.callTool('withdraw-eth', { amount: '0.1' }) |
| deposit-token | Deposit ERC20 from Ethereum to Polygon | await server.mcpServer.callTool('deposit-token', { token: 'USDC', amount: '100' }) |
| withdraw-token | Withdraw ERC20 from Polygon to Ethereum | await server.mcpServer.callTool('withdraw-token', { token: 'USDC', amount: '100' }) |
| check-bridge-status | Check the status of a bridge transaction (Not yet implemented as tool) | N/A |

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.