@vaimee/desmold-sdk
v1.3.0
Published
Software development kit for the DESMO-LD platform.
Downloads
16
Readme
DESMO-SDK
Overview
DESMO-LD is a distributed oracle for IoT data. This project exposes a practical NodeJS and browser API to interact with DESMO-LD system components.
Features
The Desmo-SDK provides an easy way to interact with the contracts defined in desmo-contracts. The Desmo-SDK provides functions to:
- Sign in your wallet with MetaMask or with a RPC provider
- Interact with the Desmo-Hub and Desmo contracts :
- calling all the public function on the contracts
- retrieve the results with an event based approach
Installation
Starting using the Desmo-SDK is really easy, just use the following command in your Node.js project:
npm i @vaimee/desmold-sdk
Usage Examples
DesmoHub contract
Register your TDD
// Sign in with a RPC provider and a private key
const walletSigner: WalletSignerJsonRpc = new WalletSignerJsonRpc(chainURL);
walletSigner.signInWithPrivateKey(privateKEY);
// Otherwise Sign in with MetaMask
// const walletSigner = new WalletSignerMetamask(window.ethereum);
const desmohub: DesmoHub = new DesmoHub(walletSigner);
// state changing methods work with an event based approach
await desmohub.startListeners();
desmoHub.tddCreated$.subscribe(() => console.log('tdd created'));
await desmoHub.registerTDD(TDDUrl);
Get your TDD
// Sign in with a RPC provider and a private key
const walletSigner: WalletSignerJsonRpc = new WalletSignerJsonRpc(chainURL);
walletSigner.signInWithPrivateKey(privateKEY);
// Otherwise Sign in with MetaMask
// const walletSigner = new WalletSignerMetamask(window.ethereum);
const desmohub: DesmoHub = new DesmoHub(walletSigner);
// no need to listen for events -> not a state changing method
const myTDDObject = await desmohub.getTDD();
Desmo Contract
Buy a query
// Sign in with a RPC provider and a private key
const walletSigner: WalletSignerJsonRpc = new WalletSignerJsonRpc(chainURL);
walletSigner.signInWithPrivateKey(privateKEY);
// Otherwise Sign in with MetaMask
// const walletSigner = new WalletSignerMetamask(window.ethereum);
const desmohub: DesmoHub = new DesmoHub(walletSigner);
const desmoContract = new DesmoContract(walletSigner);
const eventPromise = firstValueFrom(desmoHub.requestID$);
await desmoHub.getNewRequestID();
const event = await eventPromise;
await desmoContract.buyQuery(
event.requestID,
JSON.stringify(query),
iExecDAppAddress,
);
For further usage examples we suggest to go check out our front-end that make use of the Desmo-SDK
Documentation
Our code is well documented, if you have any doubt you can check our documentation page
Acknowledgments
DESMO-SDK is founded by the DESMO-LD project inside the ONTOCHAIN european organization part of the Next Generation Internet fund.