LogoLogo
  • 🏠Getting Started
  • 📖Overview
    • CrossFi Chain Overview
    • Architecture
      • Cosmos and EVM Role
  • Economy Overview
    • Native Coins Overview
    • XFI Coin
    • MPX Coin
      • eMPX Token
    • Get coins
  • Concepts
    • Vision and Mission
    • Use Cases
    • Lore
    • Glossary
    • Roles
    • FAQ
  • Ecosystem
    • XFI Scan
    • XFI Console
      • XFI-MPX Staking
      • Governance (DAO)
      • XDS
    • xApp
      • Swap
      • LP Tokens
      • Staking
      • Escrow/Vesting
    • XFI Bridge
    • EXE Interchain Protocol
  • ⚒️Developers
    • Why Develop on CrossFi Chain?
    • Quickstart
    • EVM
      • Deploying Smart Contracts
    • Connect a Frontend
      • Mainnet Cosmos Part
      • Mainnet EVM Part
      • Testnet Cosmos Part
      • Testnet EVM part
    • Configuring a Wallet
    • Integrating Developer Tools
  • API and Endpoints
    • XFI Scan API
    • API and Available Endpoints
    • Available RPC / API Validators
  • 🏗️Node Operators
    • Join a Network
    • Becoming a Validator
      • Introduction to Validating
      • Creating A Validator
      • Securing A Validator
      • Running a Validator
    • Setting Up the CrossFi Chain Client
      • Upgrading the Chain
      • Sending Transactions
      • Upgrade Your Node
  • ℹ️SEE Also
    • Contact and Media Channels
      • Telegram Channel
      • Telegram Chat
      • Discord
      • Medium
      • X (ex. Twitter)
      • LinkedIn
  • GitHub
  • Cross Finance Ecosystem Website
Powered by GitBook
On this page
  • EthersJS
  • Viem
  1. Developers
  2. Connect a Frontend

Mainnet EVM Part

PreviousMainnet Cosmos PartNextTestnet Cosmos Part

Last updated 6 months ago

EthersJS

is a compact Javascript library used for interacting with the Ethereum blockchain and other EVM compatible chains.

const { ethers } = require("ethers");

// URL of the RPC for the CrossFi Mainnet
const providerUrl = "https://rpc.mainnet.ms/";

// Creating a provider to interact with the blockchain

const provider = new ethers.JsonRpcProvider(providerUrl);
async function main() {
	// Getting the current block number as a test of the connection
	const blockNumber = await provider.getBlockNumber();
	console.log(`Current block number: ${blockNumber}`);
}

main().catch((error) => {
	console.error("Error connecting to the blockchain:", error);
});

Viem

import { defineChain, createPublicClient, http } from 'viem';

export const crossfi = defineChain({
  id: 4158,
  name: 'CrossFi Mainet',
  nativeCurrency: {
    decimals: 18,
    name: 'XFI',
    symbol: 'XFI',
  },
  rpcUrls: {
    default: {
      http: ['https://rpc.mainnet.ms/'],
    },
  },
  blockExplorers: {
    default: { name: 'Explorer', url: 'https://xfiscan.com/' },
  },
});

const client = createPublicClient({
  chain: crossfi,
  transport: http(),
});

const blockNumber = await client.getBlockNumber();

export default `Block number: ${blockNumber}`;

is a TypeScript library that offers type-safe modules for interacting with the Ethereum and other EVM compatible chains.

⚒️
Ethers.js
Viem