# `@xchainjs/xchain-ethereum`
Source: Dev.to
Package Highlights
- Ethereum (EVM) client implementation
- Address generation and validation
- Balance and transaction‑history lookup
- Transaction creation, signing, and broadcasting
- Gas and fee estimation helpers
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
Documentation
- How it works:
- How to use:
Installation
Install the package
npm install @xchainjs/xchain-ethereum
Peer dependencies
npm install @xchainjs/xchain-client @xchainjs/xchain-util ethers
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,
})
Get Address and Validate It
const address = ethClient.getAddress()
console.log('Address:', address)
const isValid = ethClient.validateAddress(address)
console.log('Valid:', isValid)
Get Balance
const balances = await ethClient.getBalance(address)
console.log(balances)
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))
Transfer ERC‑20 Tokens
const tokenAddress = '0xTokenContractAddress'
const txHash = await ethClient.transfer({
recipient,
amount,
asset: {
chain: 'ETH',
symbol: `USDT-${tokenAddress}`,
ticker: 'USDT',
},
})
Get Transaction Data
const txHash = '0xTransactionHash'
const txData = await ethClient.getTransactionData(txHash)
console.log(txData)
When to Use This Package
Use @xchainjs/xchain-ethereum if you are:
- Building a crypto wallet
- Interacting with Ethereum or other EVM‑compatible chains
- Handling ETH and ERC‑20 transfers
- Building DeFi front‑ends or back‑ends
- Using XChainJS for multi‑chain applications
Summary
@xchainjs/xchain-ethereum provides a clean, consistent, and production‑ready Ethereum client for the XChainJS ecosystem. It lets developers interact with Ethereum using the same abstractions as other blockchains, simplifying the creation of cross‑chain applications.