Skip to main content
Step 3 of 4

Multichain development

Build applications that seamlessly work across multiple blockchains using CinaCoin's unified multichain infrastructure.

Why multichain?

The blockchain ecosystem is multi-chain by nature. Users hold assets on Ethereum, Polygon, BSC, Arbitrum, and dozens of other chains. Your application should meet users where they are — not force them onto a single network.

CinaCoin provides a unified API that abstracts away chain-specific differences, letting you write code once and deploy everywhere.

Configure supported chains

Define which chains your application supports. CinaCoin handles RPC management, chain switching, and fallback providers automatically.

src/config/chains.ts
import { Chain, defineChain } from '@cinacoin/sdk';

export const ethereum = defineChain({
  id: 1,
  name: 'Ethereum',
  network: 'ethereum',
  nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://eth.rpc.cinacoin.com'] },
  },
  blockExplorers: {
    default: { name: 'Etherscan', url: 'https://etherscan.io' },
  },
});

export const polygon = defineChain({
  id: 137,
  name: 'Polygon',
  network: 'polygon',
  nativeCurrency: { name: 'MATIC', symbol: 'MATIC', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://polygon.rpc.cinacoin.com'] },
  },
  blockExplorers: {
    default: { name: 'Polygonscan', url: 'https://polygonscan.io' },
  },
});

export const bsc = defineChain({
  id: 56,
  name: 'BNB Smart Chain',
  network: 'bsc',
  nativeCurrency: { name: 'BNB', symbol: 'BNB', decimals: 18 },
  rpcUrls: {
    default: { http: ['https://bsc.rpc.cinacoin.com'] },
  },
  blockExplorers: {
    default: { name: 'BscScan', url: 'https://bscscan.com' },
  },
});

export const supportedChains = [ethereum, polygon, bsc];

Chain-agnostic interactions.

Use the same API regardless of which chain you're interacting with. The SDK automatically routes requests to the correct chain.

Chain-agnostic operations.
import { cinacoin } from '@/lib/cinacoin';

// Get balance on any chain — same API
async function getBalance(address: string, chainId: number) {
  const balance = await cinacoin.getBalance({
    address,
    chainId,
  });
  return balance; // Formatted with correct decimals
}

// Read from a contract on any chain
async function readContract(chainId: number, contractAddress: string) {
  const result = await cinacoin.readContract({
    chainId,
    address: contractAddress,
    abi: ERC20_ABI,
    functionName: 'balanceOf',
    args: ['0x742d35Cc6634C0532925a3b844Bc9e7595f...'],
  });
  return result;
}

// Works the same on Ethereum, Polygon, BSC, etc.
const ethBalance = await getBalance(address, 1);
const polyBalance = await getBalance(address, 137);
const bscBalance = await getBalance(address, 56);

Cross-chain state.

Track user state across chains with CinaCoin's unified state management. This is essential for dashboards, portfolio trackers, and multichain DeFi apps.

Cross-chain state management.
import { cinacoin } from '@/lib/cinacoin';
import { supportedChains } from '@/config/chains';

// Fetch data from all supported chains in parallel
async function getMultichainPortfolio(address: string) {
  const results = await Promise.all(
    supportedChains.map(async (chain) => {
      const [balance, tokens] = await Promise.all([
        cinacoin.getBalance({ address, chainId: chain.id }),
        cinacoin.getTokenBalances({ address, chainId: chain.id }),
      ]);

      return {
        chain: chain.name,
        chainId: chain.id,
        nativeBalance: balance,
        tokens,
      };
    })
  );

  return results;
}

// Usage in a React component
function Portfolio({ address }: { address: string }) {
  const [portfolio, setPortfolio] = useState([]);

  useEffect(() => {
    getMultichainPortfolio(address).then(setPortfolio);
  }, [address]);

  return (
    <div>
      {portfolio.map(({ chain, nativeBalance, tokens }) => (
        <div key={chain}>
          <h3>{chain}</h3>
          <p>Balance: {nativeBalance.formatted} {nativeBalance.symbol}</p>
          <p>Tokens: {tokens.length}</p>
        </div>
      ))}
    </div>
  );
}

Chain switching.

Let users switch between chains seamlessly. The SDK handles prompting the wallet to add/switch networks and updates your app state automatically.

Chain switching.
import { cinacoin } from '@/lib/cinacoin';
import { polygon } from '@/config/chains';

// Switch to a specific chain
async function switchToPolygon() {
  try {
    await cinacoin.switchChain(polygon.id);
  } catch (error) {
    if (error.code === 4902) {
      // Chain not added to wallet — request to add it
      await cinacoin.addChain(polygon);
    }
  }
}

// Listen for chain changes
cinacoin.on('chainChanged', (chainId) => {
  // Refetch data for the new chain
  refreshData(chainId);
});