Ethereum and ERC20
Ethereum and ERC20 payment method for the wallet library. Using lib-wallet-indexer-eth and Web3 backend.
β¨ Features
π Secure wallet management for Ethereum and ERC20 tokens
π Transaction syncing and balance tracking
π Address generation and validation
πΈ Send and receive transactions
βΈοΈ Pausable sync process
π Transaction history retrieval
ποΈ Indexer
This module requires an indexer server. See lib-wallet-indexer
π Usage
π Methods
π initialize(ctx)
initialize(ctx)
Description: Initializes the wallet, setting up the key manager, HD wallet, and state database.
Return Value: A Promise that resolves when initialization is complete.
Parameters:
ctx
: Context object for initialization (optional).
Example usage:
π getNewAddress()
getNewAddress()
Description: Generates a new Ethereum address for the wallet.
Return Value: A Promise that resolves to an object containing the new address details.
Example usage:
π getTransactions(opts, fn)
getTransactions(opts, fn)
Description: Retrieves the transaction history for the wallet or a specific token.
Return Value: A Promise that resolves when all transactions have been processed.
Parameters:
opts
(optional): An object containing options.token
(optional): Name of the token for token transaction history.
fn
: Callback function to handle each block of transactions.
Example usage:
π° getBalance(opts, addr)
getBalance(opts, addr)
Description: Retrieves the balance of an address or the entire wallet.
Return Value: A Promise that resolves to a Balance object.
Parameters:
opts
(optional): An object containing options.token
(optional): Name of the token to get balance for.
addr
(optional): Specific address to get balance for.
Example usage:
π syncTransactions(opts)
syncTransactions(opts)
Description: Synchronizes transactions for the wallet, updating balances and transaction history.
Return Value: A Promise that resolves when synchronization is complete.
Parameters:
opts
(optional): An object containing options.reset
(optional): If true, resets all state and resyncs.token
(optional): Name of the token to sync transactions for.
Example usage:
π€ sendTransaction(opts, outgoing)
sendTransaction(opts, outgoing)
Description: Sends a transaction from the wallet.
Return Value: A Promise that resolves when the transaction is confirmed.
Parameters:
opts
(optional): An object containing options.token
(optional): Name of the token to send.
outgoing
: An object containing transaction details.amount
: Number of units being sent.unit
: Unit of amount ('main' or 'base').address
: Address of the receiver.sender
(optional): Address of the sender.gasLimit
(optional): ETH gas limit.gasPrice
(optional): ETH gas price.
Example usage:
β
isValidAddress(address)
isValidAddress(address)
Description: Checks if the given address is a valid Ethereum address.
Return Value: A boolean indicating whether the address is valid.
Parameters:
address
: The Ethereum address to validate.
Example usage:
βΈοΈ pauseSync()
pauseSync()
Description: Pauses the synchronization process.
Return Value: A Promise that resolves when synchronization is paused.
Example usage:
βΆοΈ resumeSync()
resumeSync()
Description: Resumes the synchronization process.
Return Value: A Promise that resolves when synchronization is resumed.
Example usage:
π οΈ Setup
Initialize storage engine
Generate or use existing seed
Set up ERC20 tokens (if needed)
Connect to provider
Create and initialize EthereumPay instance
π οΈ Development
Clone the repository:
Install dependencies:
Run tests:
π§ͺ Testing
This package includes extensive integration tests.
We use Brittle for testing.
Integration tests require an Ethereum node connected to a testnet or local network.
To set up the testing environment, see: Test tools repo
To run tests, check package.json
for the various test scripts. You can run them using:
Last updated