Ethereum and ERC20
Last updated
Last updated
Ethereum and ERC20 payment method for the wallet library. Using lib-wallet-indexer-eth and Web3 backend.
π 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
This module requires an indexer server. See
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()
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)
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)
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)
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)
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)
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()
Description: Pauses the synchronization process.
Return Value: A Promise that resolves when synchronization is paused.
Example usage:
resumeSync()
Description: Resumes the synchronization process.
Return Value: A Promise that resolves when synchronization is resumed.
Example usage:
Initialize storage engine
Generate or use existing seed
Set up ERC20 tokens (if needed)
Connect to provider
Create and initialize EthereumPay instance
Clone the repository:
Install dependencies:
Run tests:
This package includes extensive integration tests.
Integration tests require an Ethereum node connected to a testnet or local network.
To run tests, check package.json
for the various test scripts. You can run them using:
We use for testing.
To set up the testing environment, see: