Integrating new assets
This is a guide for developers looking to extend the WalletPay
base class to integrate a new cryptocurrency, example: XYZ Coin, into the wallet system.
Table of Contents
Prerequisites
Familiarity with JavaScript and ES6 class syntax
Understanding of the
WalletPay
base class and its methodsKnowledge of XYZ Coin's blockchain specifics (e.g., address format, transaction structure)
Access to XYZ Coin's blockchain API or node
Getting Started
Create a new directory for your XYZ Coin implementation:
Initialize a new npm project and install necessary dependencies:
Implementing XYZCoin Class
Create a new file xyz.currency.js
to define the XYZCoin class:
Extending WalletPay
Create a new file wallet-pay-xyz.js
to extend the WalletPay class:
Other Components
Wallet components are modular by design. There are other components you can either integrate, develop or your own.
Block Data Provider
you should be splitting up your data provider into a separate class.
Data Store
Transaction history and wallet state is tracked using a key value store. We provide a key-value data store with WalletStoreHyperBee. You can build your own storage engine too!
Implementing Core Methods
Implement the following core methods in your WalletPayXYZ
class:
getNewAddress()
: Generate a new XYZ Coin addressgetTransactions(opts, fn)
: Retrieve transaction historygetBalance(opts, addr)
: Get balance for the entire wallet or a specific addresssyncTransactions(opts)
: Sync transactions with the blockchainsendTransaction(opts, outgoing)
: Send XYZ CoinsisValidAddress(address)
: Validate XYZ Coin addresses
Example implementation of getNewAddress()
:
It's important to create new addresses using a HD path standard this will allow the wallet to be recreated with just a seed phrase and also makes the wallet compatible with other wallets.
Testing Your Implementation
Create a test file
test-wallet-pay-xyz.js
:
Run the test:
Best Practices
Event Emission: Emit appropriate events (e.g., 'new-tx', 'synced-path') to allow users to react to wallet state changes.
Configurability: Allow users to configure network, API endpoints, and other XYZ Coin-specific parameters.
Security: Ensure proper handling of private keys and sensitive data.
Testing: Implement comprehensive unit tests for your WalletPayXYZ class.
Documentation: Provide clear documentation for any XYZ Coin-specific features or limitations.
By following this guide, you should be able to create a functional WalletPayXYZ implementation that integrates XYZ Coin into the WalletPay system. Remember to thoroughly test your implementation and handle edge cases specific to XYZ Coin's blockchain.
Last updated