This package handles CRUD (Create, Read, Updated, and Delete) operations for applications deployed to Skynet.
Here are some things you need to know about a SkyID:
It can have single or multiple applications. For example, a database, backend, and frontend website deployed as three applications under a SkyID with an ID 1535.
You need sUsd tokens to run your SkyID, and you have to deposit them into the SkyID.
The package is modular; this means you can extend and modify it according to your specific use case.
The Skynet package handles:
Contract interactions.
Application encryption and decryption.
Manages uploading and downloading of application payloads to and from decentralized storage platforms.
Perform CRUD operations on your application–Application manager.
Estimates and manages the cost of running an application; this happens through a drip manager.
Prerequisite
To get the best out of this package and the contract calls to perform for specific use cases. You need to:
Have a basic understanding of .
An understanding of .
and npm set up.
A decentralized application project.
To carry out these contract initialization and calls appropriately. You should include the required files for your specific use case in your project’s root directory.
Installation
Run this in your project's root directory:
npm i @decloudlabs/skynet
Initialise Contract Service
It contains the required definitions for contract application deployment to initialize contract service. Implement this code:
import { ethers } from 'ethers';
import SkyBrowserSigner from '@decloudlabs/skynet/lib/services/SkyEtherContractService';
import SkyEtherContractService from '@decloudlabs/skynet/lib/services/SkyEtherContractService';
import SkyMainBrowser from '@decloudlabs/skynet/lib/services/SkyMainBrowser';
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const envConfig: SkyEnvConfigBrowser = {
STORAGE_API: {
IPFS: {
PROJECT_ID: "infurs ipfs project id",
PROJECT_SECRET: "infurs ipfs project secret",
}
},
CACHE: {
TYPE: "CACHE",
},
};
const contractInstance = new SkyEtherContractService(provider, signer, address, 11); // 11 is the chain Id of Skynet
const skyMainBrowser = new SkyMainBrowser(
contractInstance,
address, // connected wallet address
new SkyBrowserSigner(address, signer),
envConfig
);
await skyMainBrowser.init(true);
Explaining the parameters:
provider:Initializes a Web3 provider using the window.ethereum object. The provider here allows the application to read from and send transactions to the Ethereum blockchain.
signer: This allows users to sign transactions and applications to initiate state-changing operations on the blockchain.
contractInstance : it's an SDK library that is used to create an instance of contracts that contains the main contracts deployed in the Skynet chain.
address: The Ethereum address associated with your wallet would be used for performing the transactions. Ensure the signer is authorized to act on behalf of this address.
skyMainBrowser: This initializes an instance of skyMainBrowser while passing contractInstance, address, and a new instance of SkyBrowserSigner.
Mint and Fetch SkyId
To mint and fetch the ID of a SkyID, implement this code: