> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polynode.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Integration Guide

> Connect to polynode RPC from any Ethereum library or wallet

## Endpoint

```
https://rpc.polynode.dev
```

All requests require a valid API key via `x-api-key` header or `Authorization: Bearer` header.

## Integration Examples

<Tabs>
  <Tab title="viem">
    ```typescript theme={null}
    import { createPublicClient, createWalletClient, http } from 'viem'
    import { polygon } from 'viem/chains'
    import { privateKeyToAccount } from 'viem/accounts'

    const transport = http('https://rpc.polynode.dev', {
      fetchOptions: {
        headers: { 'x-api-key': 'YOUR_API_KEY' }
      }
    })

    // Read contract state
    const publicClient = createPublicClient({
      chain: polygon,
      transport
    })

    const blockNumber = await publicClient.getBlockNumber()
    const balance = await publicClient.getBalance({
      address: '0xYOUR_ADDRESS'
    })

    // Send transactions with priority routing
    const account = privateKeyToAccount('0xYOUR_PRIVATE_KEY')
    const walletClient = createWalletClient({
      account,
      chain: polygon,
      transport
    })

    const hash = await walletClient.sendTransaction({
      to: '0xRECIPIENT',
      value: parseEther('1.0')
    })
    ```
  </Tab>

  <Tab title="ethers.js">
    ```javascript theme={null}
    import { ethers } from 'ethers'

    const provider = new ethers.JsonRpcProvider(
      'https://rpc.polynode.dev',
      137,
      { staticNetwork: true }
    )

    // Add auth to every request
    const originalSend = provider.send.bind(provider)
    provider.send = async (method, params) => {
      const resp = await fetch('https://rpc.polynode.dev', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'x-api-key': 'YOUR_API_KEY'
        },
        body: JSON.stringify({ jsonrpc: '2.0', method, params, id: 1 })
      })
      const { result, error } = await resp.json()
      if (error) throw new Error(error.message)
      return result
    }

    const blockNumber = await provider.getBlockNumber()
    const balance = await provider.getBalance('0xYOUR_ADDRESS')

    // Send a transaction
    const wallet = new ethers.Wallet('YOUR_PRIVATE_KEY', provider)
    const tx = await wallet.sendTransaction({
      to: '0xRECIPIENT',
      value: ethers.parseEther('1.0')
    })
    ```
  </Tab>

  <Tab title="web3.py">
    ```python theme={null}
    from web3 import Web3

    w3 = Web3(Web3.HTTPProvider(
        'https://rpc.polynode.dev',
        request_kwargs={
            'headers': {'x-api-key': 'YOUR_API_KEY'}
        }
    ))

    # Read state
    block = w3.eth.block_number
    balance = w3.eth.get_balance('0xYOUR_ADDRESS')

    # Check token balance (USDC)
    usdc = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'
    data = '0x70a08231' + '0xYOUR_ADDRESS'[2:].lower().zfill(64)
    result = w3.eth.call({'to': usdc, 'data': data})
    usdc_balance = int(result.hex(), 16) / 1e6

    # Send a transaction
    account = w3.eth.account.from_key('YOUR_PRIVATE_KEY')
    tx = {
        'nonce': w3.eth.get_transaction_count(account.address),
        'to': '0xRECIPIENT',
        'value': w3.to_wei(1, 'ether'),
        'gas': 21000,
        'gasPrice': w3.eth.gas_price,
        'chainId': 137,
    }
    signed = account.sign_transaction(tx)
    tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
    ```
  </Tab>

  <Tab title="curl">
    ```bash theme={null}
    # Check block number
    curl -X POST https://rpc.polynode.dev \
      -H "Content-Type: application/json" \
      -H "x-api-key: YOUR_API_KEY" \
      -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

    # Check MATIC balance
    curl -X POST https://rpc.polynode.dev \
      -H "Content-Type: application/json" \
      -H "x-api-key: YOUR_API_KEY" \
      -d '{
        "jsonrpc":"2.0",
        "method":"eth_getBalance",
        "params":["0xYOUR_ADDRESS","latest"],
        "id":1
      }'

    # Send a signed transaction
    curl -X POST https://rpc.polynode.dev \
      -H "Content-Type: application/json" \
      -H "x-api-key: YOUR_API_KEY" \
      -d '{
        "jsonrpc":"2.0",
        "method":"eth_sendRawTransaction",
        "params":["0xSIGNED_TX_HEX"],
        "id":1
      }'
    ```
  </Tab>
</Tabs>

## Hardhat / Foundry

<Tabs>
  <Tab title="Hardhat">
    ```javascript theme={null}
    // hardhat.config.js
    module.exports = {
      networks: {
        polygon: {
          url: 'https://rpc.polynode.dev',
          accounts: [process.env.PRIVATE_KEY],
          chainId: 137,
          httpHeaders: {
            'x-api-key': process.env.POLYNODE_API_KEY
          }
        }
      }
    }
    ```
  </Tab>

  <Tab title="Foundry">
    ```bash theme={null}
    # Set auth via header
    export ETH_RPC_URL=https://rpc.polynode.dev

    # Deploy
    forge script script/Deploy.s.sol \
      --rpc-url $ETH_RPC_URL \
      --broadcast \
      --private-key $PRIVATE_KEY

    # Read state
    cast call 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359 \
      "totalSupply()" \
      --rpc-url $ETH_RPC_URL
    ```
  </Tab>
</Tabs>

## Response Format

Standard Ethereum JSON-RPC responses:

```json theme={null}
// Success
{"jsonrpc": "2.0", "id": 1, "result": "0x..."}

// Error
{"jsonrpc": "2.0", "id": 1, "error": {"code": -32000, "message": "..."}}
```
