@makkii/app-eth
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

@makkii/app-eth

Ethereum application client.

This library uses some third-party service:

  • Web3 JsonRPC - you can pass in jsonrpc in EthApiClient Constructor
  • Explorer Api - To get transaction history, token history, we have two solutions:
    • http://api.ethplorer.io
    • http://api.etherscan.io/api
  • Transaction Explorer - To show transaction detail page:
    • https://www.etherchain.org/tx/<txHash>
    • https://api.etherscan.io/tx/<txHash>
  • Remote Api - we setup our own server to provide token list and icons.

Installation

$ npm install @makkii/app-eth

Usage

import { EthApiClient, EthKeystoreClient, EthLocalSigner } from '@makkii/app-eth';

const api_client = new EthApiClient({
    network: 'mainnet',
    jsonrpc: '***'
});
api_client.getBalance('0x...')
    .then(console.log)
    .catch(error=>console.log(error));
const keystore_client = new EthKeystoreClient();
api_client.buildTransaction(
    '0x...', // from address
    '0x...', // to address
    0, // amount
    {
        gasPrice: 10,
        gasLimit: 21000,
        isTokenTransfer: false
    }
).then(function(unsignedTx) {
    keystore_client.signTransaction(unsignedTx, new EthLocalSigner(), {
        private_key: '***'
    }).then(function(signedTx) {
        console.log(signedTx);
    });
});

API

Table of Contents

EthLocalSinger

Ethereum's signer using private key, implements IkeystoreSigner.

signTransaction

Sign transaction

Parameters
  • transaction EthUnsignedTx
  • params {private_key: string} parameters object, example: { private_key: '' }}
  • tx EthUnsignedTx transaction object to sign.

Returns Promise<string> transaction hash string

IEthConfig

Ethereum configuration interface

network

Network name

Type: ("mainnet" | "ropsten")

jsonrpc

JsonRPC endpoint

Type: string

explorer_api

api endpoint that used to query transaction information

Type: {provider: string, url: string, key: string}

explorer

Transaction explorer page

Type: {provider: string, url: string}

remote_api

app server endpoint that provides token, icons, etc.

Type: string

EthKeystoreClient

Ethereum keystore client that implements IsingleKeystoreClient

validatePrivateKey

throws not implemented error

Parameters

getAccountFromMnemonic

Get account from mnemonic

Parameters
  • address_index number index in hd wallet
  • mnemonic string mnemonic phrase

Returns any account object: { private_key: '', public_key: '', address: '', index: '' }

EthUnsignedTx

Ethereum unsigned transaction

  • to: string;
  • from: string;
  • nonce: string;
  • value: BigNumber;
  • gasPrice: number;
  • gasLimit: number;
  • data?: any;
  • network: string;

EthPendingTx

Ethereum pending transaction

  • hash: string;
  • status: "PENDING";
  • to: string;
  • from: string;
  • value: BigNumber;
  • tknTo?: string;
  • tknValue: BigNumber;
  • gasPrice: number;
  • gasLimit: number;

EthApiClient

Ethereum api client that implements IsingleApiFullClient

Parameters

getNetwork

Get network name: mainnet, amity.

getBlockByNumber

Get block by number, block information doesn't contains transaction details

Parameters
  • blockNumber string block number's hex string

Returns any eth_getBlockNumber response's result

getBlockNumber

Get latest block number

Returns any eth_getBlockNumber response's result

getTransactionStatus

Get transaction status.

Parameters
  • hash string transaction hash

Returns Promise<any> if eth_getTransactionReceipt is null, returns null; else return object { status: true/false, blockNumber: intger, gasUsed: integer }

getTransactionsByAddress

Get transactions by the given address

Parameters
  • address string account address
  • page number page number
  • size number page size
  • timestamp number? earlier than this timestamp

Returns any array of object structure which contains:
- hash: string, with prefix 0x

  • timestamp: milli-seconds from 1970
  • from: sender
  • to: receiver
  • value: transfer amount
  • status: 'CONFIRMED' or 'FAILED'
  • blockNumber: hex string
  • fee: integer

sendTransaction

Send transaction

Parameters
  • unsignedTx EthUnsignedTx unsigned transaction build by buildTransaction
  • signer T localSigner or hardware
  • signerParams any localSigner: {private_key} hardware:{derivationIndex}

Returns Promise<EthPendingTx>

getTopTokens

Get top tokens

Parameters

Returns Promise<Array<Token>>

Readme

Keywords

none

Package Sidebar

Install

npm i @makkii/app-eth

Weekly Downloads

1

Version

0.1.2

License

ISC

Unpacked Size

95.7 kB

Total Files

56

Last publish

Collaborators

  • makkii-dev
  • rleor