How to Use

Installation

yarn add @xchainjs/xchain-ethereum

Peer Dependencies

You can visit the xchain-ethereum package repository to get the updated peer dependencies by looking at the "peerDependencies" object in the "package.json" file.

Testing

yarn install
yarn test

Examples

Connect wallet to new Ethereum client and check address and balances

The network default is Mainnet

// Imports
import fs = require('fs');
import { Client } from "@xchainjs/xchain-ethereum"


//Connect wallet, validate address and check balance 
const connectWallet = async () => {
    let phrase = "phrase"
    const ethClient = new Client({phrase})
    let address = ethClient.getAddress()
    let isValid = ethClient.validateAddress(address)
    console.log(address)
    if(isValid === true){
        try {
            const balance = await ethClient.getBalance(address)
            let assetAmount = (baseToAsset(balance[0].amount)).amount()
            console.log(`Adress: ${address} with balance ${assetAmount}`)
            
        } catch (error) {
            console.log(`Caught: ${error} `)
        }
    } else {
        console.log(`Address: ${address} is invalid`)
    }
}

Transfer Ethereum using Ethereum Client

Create a new Ethereum Client instance Convert amount to transfer to baseAmount. ETH_DECIAL = 18 Build Transaction. Transfer function returns txid as an object promise

Get Transaction Data & Transaction History

Use functions to query ethereum explorer getTransactionData() getTransactions()

Get Transfer Fee Estimations

Retrieve estimated gas prices and gas limits from ethereum client\

Estimate Call & Approve

Create a new Eth Client instance Call the function with the correct parameters

Get Explorer Data

Use helper functions to retrieve explorer interface or explorer data on addresses or txid's

Last updated