DEV Community

Cover image for # `@xchainjs/xchain-ethereum`
Fabricio Viskor
Fabricio Viskor

Posted on

# `@xchainjs/xchain-ethereum`

@xchainjs/xchain-ethereum is the official Ethereum client for the XChainJS ecosystem — a modular, TypeScript-first SDK for building cross-chain wallets, crypto applications, and DeFi tooling using a unified API.

This package provides:

  • an Ethereum (EVM) client implementation
  • address generation and validation
  • balance and transaction history lookup
  • transaction creation, signing, and broadcasting
  • gas and fee estimation helpers

Source package: https://github.com/xchainjs/xchainjs-lib/tree/master/packages/xchain-ethereum

Official docs: https://docs.xchainjs.org/xchain-client/xchain-ethereum/


Features

  • ✅ TypeScript-first Ethereum SDK
  • ✅ EVM-compatible chain support
  • ✅ Address derivation from mnemonic
  • ✅ Address validation
  • ✅ Balance and transaction history
  • ✅ ETH and ERC-20 transfers
  • ✅ Gas price and fee estimation
  • ✅ Unified API aligned with other XChainJS clients

How It Works

  • Built on top of ethers.js for Ethereum RPC interaction
  • Uses shared XChainJS abstractions and types
  • Designed to behave consistently with other chain clients (BTC, LTC, THORChain, etc.)

Core dependencies:

  • ethers
  • @xchainjs/xchain-client
  • @xchainjs/xchain-util

Docs:


Installation

Install the package

npm install @xchainjs/xchain-ethereum
Enter fullscreen mode Exit fullscreen mode

Peer dependencies

npm install @xchainjs/xchain-client @xchainjs/xchain-util ethers
Enter fullscreen mode Exit fullscreen mode

Basic Usage Examples

Create an Ethereum Client

import { Client } from '@xchainjs/xchain-ethereum'
import { Network } from '@xchainjs/xchain-client'

const phrase = 'your mnemonic phrase here'

const ethClient = new Client({
  phrase,
  network: Network.Mainnet,
})
Enter fullscreen mode Exit fullscreen mode

Get Address and Validate It

const address = ethClient.getAddress()
console.log('Address:', address)

const isValid = ethClient.validateAddress(address)
console.log('Valid:', isValid)
Enter fullscreen mode Exit fullscreen mode

Get Balance

const balances = await ethClient.getBalance(address)
console.log(balances)
Enter fullscreen mode Exit fullscreen mode

Balances are returned in base units and can be converted using utilities from
@xchainjs/xchain-util.


Transfer ETH

import { assetAmount, assetToBase } from '@xchainjs/xchain-util'

const recipient = '0xRecipientAddressHere'
const amount = assetToBase(assetAmount(0.01))

const txHash = await ethClient.transfer({
  recipient,
  amount,
  memo: 'ETH transfer',
})

console.log('TX hash:', txHash)
console.log('Explorer:', ethClient.getExplorerTxUrl(txHash))
Enter fullscreen mode Exit fullscreen mode

Transfer ERC-20 Tokens

const tokenAddress = '0xTokenContractAddress'
const txHash = await ethClient.transfer({
  recipient,
  amount,
  asset: {
    chain: 'ETH',
    symbol: `USDT-${tokenAddress}`,
    ticker: 'USDT',
  },
})
Enter fullscreen mode Exit fullscreen mode

Get Transaction Data

const txHash = '0xTransactionHash'
const txData = await ethClient.getTransactionData(txHash)
console.log(txData)
Enter fullscreen mode Exit fullscreen mode

When to Use This Package

Use @xchainjs/xchain-ethereum if you are:

  • building a crypto wallet
  • interacting with Ethereum or EVM chains
  • handling ETH and ERC-20 transfers
  • building DeFi frontends or backends
  • using XChainJS for multi-chain applications

Useful Links


Summary

@xchainjs/xchain-ethereum provides a clean, consistent, and production-ready
Ethereum client for the XChainJS ecosystem.

It allows developers to interact with Ethereum using the same abstractions as
other blockchains, making it easier to build cross-chain applications.

Top comments (0)