Integrating new assets
Last updated
Last updated
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.
Familiarity with JavaScript and ES6 class syntax
Understanding of the WalletPay
base class and its methods
Knowledge of XYZ Coin's blockchain specifics (e.g., address format, transaction structure)
Access to XYZ Coin's blockchain API or node
Create a new directory for your XYZ Coin implementation:
Initialize a new npm project and install necessary dependencies:
Create a new file xyz.currency.js
to define the XYZCoin class:
Create a new file wallet-pay-xyz.js
to extend the WalletPay class:
Wallet components are modular by design. There are other components you can either integrate, develop or your own.
you should be splitting up your data provider into a separate class.
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!
Implement the following core methods in your WalletPayXYZ
class:
getNewAddress()
: Generate a new XYZ Coin address
getTransactions(opts, fn)
: Retrieve transaction history
getBalance(opts, addr)
: Get balance for the entire wallet or a specific address
syncTransactions(opts)
: Sync transactions with the blockchain
sendTransaction(opts, outgoing)
: Send XYZ Coins
isValidAddress(address)
: Validate XYZ Coin addresses
Example implementation of getNewAddress()
:
Create a test file test-wallet-pay-xyz.js
:
Run the test:
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.
It's important to create new addresses using a this will allow the wallet to be recreated with just a seed phrase and also makes the wallet compatible with other wallets.