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

# Multi-Chain Support

> Using ZKScore across multiple blockchain networks

## Overview

ZKScore supports multiple blockchain networks, allowing users to maintain their reputation and identity across different chains.

## Supported Networks

### Mainnet Networks

* **Ethereum**: Primary network with full feature support
* **Polygon**: Layer 2 scaling solution
* **Arbitrum**: Optimistic rollup
* **Base**: Coinbase Layer 2

### Testnet Networks

* **Goerli**: Ethereum testnet
* **Mumbai**: Polygon testnet
* **Arbitrum Goerli**: Arbitrum testnet

## Cross-Chain Identity

### Identity Portability

ZKScore identities are portable across all supported networks:

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Identity works across all networks
  const identity = await client.getIdentity('alice.zks');
  console.log('ZKS ID:', identity.zksId);
  console.log('Network:', identity.network);
  console.log('Cross-chain enabled:', identity.crossChain);
  ```
</CodeGroup>

### Network-Specific Operations

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Switch networks
  const ethereumClient = new ZKScoreClient({
    apiKey: 'your_api_key',
    network: 'ethereum'
  });

  const polygonClient = new ZKScoreClient({
    apiKey: 'your_api_key',
    network: 'polygon'
  });

  // Get score on specific network
  const ethereumScore = await ethereumClient.getScore('alice.zks');
  const polygonScore = await polygonClient.getScore('alice.zks');
  ```
</CodeGroup>

## Cross-Chain Score Aggregation

### Multi-Chain Scores

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Get aggregated score across all networks
  const aggregatedScore = await client.getAggregatedScore('alice.zks');
  console.log('Aggregated score:', aggregatedScore.total);

  // Get network-specific scores
  const networkScores = await client.getNetworkScores('alice.zks');
  console.log('Ethereum score:', networkScores.ethereum);
  console.log('Polygon score:', networkScores.polygon);
  ```
</CodeGroup>

### Score Synchronization

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Sync scores across networks
  const syncResult = await client.syncScoresAcrossNetworks('alice.zks');
  console.log('Sync result:', syncResult);

  // Check sync status
  const syncStatus = await client.getSyncStatus('alice.zks');
  console.log('Sync status:', syncStatus);
  ```
</CodeGroup>

## Network Configuration

### Client Configuration

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Multi-network client
  const client = new ZKScoreClient({
    apiKey: 'your_api_key',
    networks: {
      ethereum: {
        rpc: 'https://eth-mainnet.alchemyapi.io/v2/YOUR_KEY',
        chainId: 1
      },
      polygon: {
        rpc: 'https://polygon-mainnet.g.alchemy.com/v2/YOUR_KEY',
        chainId: 137
      },
      arbitrum: {
        rpc: 'https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY',
        chainId: 42161
      }
    }
  });
  ```
</CodeGroup>

### Network Switching

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Switch active network
  await client.switchNetwork('polygon');

  // Get current network
  const currentNetwork = client.getCurrentNetwork();
  console.log('Current network:', currentNetwork);

  // Check network support
  const isSupported = client.isNetworkSupported('base');
  console.log('Base supported:', isSupported);
  ```
</CodeGroup>

## Cross-Chain Attestations

### Attestation Portability

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Create attestation on specific network
  const attestation = await client.createAttestation({
    recipient: 'alice.zks',
    schema: 'skill_verification',
    data: { skill: 'Solidity', level: 8 },
    network: 'ethereum'
  });

  // Verify attestation across networks
  const isValid = await client.verifyAttestation(attestation.id, 'polygon');
  console.log('Valid on Polygon:', isValid);
  ```
</CodeGroup>

### Cross-Chain Verification

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Get attestations from all networks
  const allAttestations = await client.getCrossChainAttestations('alice.zks');
  console.log('Total attestations:', allAttestations.length);

  // Filter by network
  const ethereumAttestations = allAttestations.filter(
    att => att.network === 'ethereum'
  );
  ```
</CodeGroup>

## Gas Optimization

### Network Selection

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Get gas prices across networks
  const gasPrices = await client.getGasPrices();
  console.log('Gas prices:', gasPrices);

  // Select optimal network for transaction
  const optimalNetwork = client.selectOptimalNetwork({
    transactionType: 'mint_identity',
    urgency: 'low'
  });
  console.log('Optimal network:', optimalNetwork);
  ```
</CodeGroup>

### Batch Operations

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Batch operations across networks
  const batchResult = await client.batchOperations([
    {
      operation: 'getScore',
      network: 'ethereum',
      params: ['alice.zks']
    },
    {
      operation: 'getScore',
      network: 'polygon',
      params: ['alice.zks']
    }
  ]);
  ```
</CodeGroup>

## React Multi-Chain Integration

### Network Provider

<CodeGroup>
  ```javascript JavaScript theme={null}
  import React, { createContext, useContext, useState } from 'react';
  import { ZKScoreClient } from '@zkscore/sdk';

  const NetworkContext = createContext();

  export const NetworkProvider = ({ children }) => {
    const [currentNetwork, setCurrentNetwork] = useState('ethereum');
    const [client, setClient] = useState(null);
    
    useEffect(() => {
      const zkClient = new ZKScoreClient({
        apiKey: process.env.REACT_APP_ZKSCORE_API_KEY,
        network: currentNetwork
      });
      setClient(zkClient);
    }, [currentNetwork]);
    
    const switchNetwork = (network) => {
      setCurrentNetwork(network);
    };
    
    return (
      <NetworkContext.Provider value={{ 
        currentNetwork, 
        client, 
        switchNetwork 
      }}>
        {children}
      </NetworkContext.Provider>
    );
  };

  export const useNetwork = () => useContext(NetworkContext);
  ```
</CodeGroup>

### Network Selector Component

<CodeGroup>
  ```javascript JavaScript theme={null}
  const NetworkSelector = () => {
    const { currentNetwork, switchNetwork } = useNetwork();
    
    const networks = [
      { id: 'ethereum', name: 'Ethereum', icon: '⟠' },
      { id: 'polygon', name: 'Polygon', icon: '⬟' },
      { id: 'arbitrum', name: 'Arbitrum', icon: '🔷' },
      { id: 'base', name: 'Base', icon: '🔵' }
    ];
    
    return (
      <div className="network-selector">
        <label>Network:</label>
        <select 
          value={currentNetwork} 
          onChange={(e) => switchNetwork(e.target.value)}
        >
          {networks.map(network => (
            <option key={network.id} value={network.id}>
              {network.icon} {network.name}
            </option>
          ))}
        </select>
      </div>
    );
  };
  ```
</CodeGroup>

## Best Practices

### Network Selection

1. **Gas Costs**: Consider gas costs when choosing networks
2. **Speed**: Use faster networks for time-sensitive operations
3. **Security**: Use more secure networks for high-value operations
4. **Compatibility**: Ensure your application supports the chosen network

### Cross-Chain Operations

1. **Synchronization**: Regularly sync data across networks
2. **Consistency**: Maintain consistent data across all networks
3. **Error Handling**: Handle network-specific errors gracefully
4. **Fallbacks**: Provide fallback options for network failures

## Related Documentation

* [Contract Addresses](/contracts/addresses)
* [Network Configuration](/sdk/javascript/getting-started)
* [Cross-Chain Identity](/concepts/identity)
