Step-by-step examples to help developers get started with IPDW, from installation to data synchronization.
This section provides practical examples for developers looking to integrate IPDW into their applications. It covers the installation process, interface instantiation, and key-value data management within the IPDW. The examples also demonstrate how data can be synchronized automatically between devices using P2P communication, providing a hands-on guide to leveraging IPDW's full capabilities.
To get started with IPDW, you will need to follow these steps:
Install the package:
$npminstallipdw
Instantiate ipdw with this interface:
public static async Create(privateKey: string, storageProvider: StorageProvider, salt?: Buffer): PromiseThen access to "data", which is a sharded map where you can get and set in a key-value style.
The full example with auto synchronization between devices:
import {IPDW, MemoryStorageProvider} from"ipdw";// On device 1(asyncfunction () {constprivateKey='0xb577c4367d79f1a7a0c8353f7937d601758d92c35df958781d72d70f9177e52f';constprovider=awaitIPDWStorageProvider.Init(privateKey,newMemoryStorageProvider());constdataWallet=awaitDataWallet.Create(privateKey, provider);awaitdataWallet.set('test1','hello');constvalue1=awaitdataWallet.get('test1');console.log('test1 value:', value1);// test1 value: hello// Run "device 2" and if reachable it will be discovered and syncedconstvalue2=awaitdataWallet.get('test2');console.log('test2 value:', value2);// test2 value: world})();// On device 2(asyncfunction () {constprivateKey='0xb577c4367d79f1a7a0c8353f7937d601758d92c35df958781d72d70f9177e52f';constprovider=awaitIPDWStorageProvider.Init(privateKey,newMemoryStorageProvider());constdataWallet=awaitDataWallet.Create(privateKey, provider);awaitipdw.data.set('test2','world');})();