The Spheron Protocol SDK provides developers with tools to interact with the Spheron decentralized infrastructure. It includes modules for managing compute leases, deployments, escrow operations, and more.
The Spheron Protocol SDK comprises two main components that work together to provide a seamless experience for interacting with the Spheron decentralized infrastructure:
The Protocol SDK handles all deployment and escrow-specific operations, including:
- Creating Deployment Orders: Initiate new deployments on the network.
- Updating Deployments: Modify existing deployments with new configurations.
- Closing Deployments: Terminate deployments when they are no longer needed.
- Managing Escrow Balances: Track and manage your account balance within the network’s escrow system.
- Financial Transactions: Deposit and withdraw funds securely.
This component manages the blockchain transactions and smart contract interactions required for these operations.
The Provider Proxy Server is essential for interacting with provider-specific functions, such as:
- Fetching Deployment Details: Retrieve information about your deployments.
- Retrieving Exposed Ports: Get details about network ports exposed by your services.
- Getting Service Details: Access information about running services.
- Checking Service Statuses: Monitor the status of your deployed applications.
The Provider Proxy Server acts as an intermediary between your application and the Spheron provider, handling both HTTP and WebSocket requests.
These components work hand in hand, allowing you to interact with the Spheron infrastructure without needing to build additional components:
- Run the Provider Proxy Server: This server communicates with the Spheron provider on your behalf.
- Pass the Provider Proxy Server URL to the Protocol SDK: This allows the SDK to route requests appropriately.
- Use the SDK Functions: Manage deployments and interact with the Spheron infrastructure through the SDK’s API.
By following the guide below and referring to the Node.js SDK README, you'll be able to perform all necessary interactions for deployments on Spheron.
The Node.js SDK offers a comprehensive set of functionalities to interact with the Spheron Protocol via Node.js applications.
Key features include:
- Escrow Module: Manage user balances, deposits, and withdrawals.
- Deployment Module: Create, update, retrieve, and close deployments.
- Lease Module: Manage compute leases, including retrieving lease details and managing active leases.
The Provider Proxy Server acts as an intermediary for fetching data related to deployments from the Spheron Provider. It handles both HTTP and WebSocket requests to communicate with the Spheron provider.
To install the Spheron SDK in your Node.js project, use npm or yarn:
npm install @spheron/protocol-sdk
Or with yarn:
yarn add @spheron/protocol-sdk
To submit manifests to a provider, you need to set up a proxy server. You can run the provider proxy server using Docker or from source code.
Refer to the Provider Proxy Server README for detailed instructions.
Pull and run the Docker image:
docker pull spheronnetwork/provider-proxy-server:latest
docker run -p 3040:3040 spheronnetwork/provider-proxy-server:latest
Clone the repository and run the server:
git clone https://github.com/spheronFdn/protocol-sdk.git
cd protocol-sdk/provider-proxy-server
npm install
npm run start
Make sure to set any necessary environment variables as described in the Provider Proxy Server README.
Import and initialize the SDK in your Node.js application:
const { SpheronSDK } = require("@spheron/protocol-sdk");
const sdk = new SpheronSDK("testnet");
If performing write operations, provide a private key:
const sdk = new SpheronSDK("testnet", "your-private-key");
Note: Never hardcode your private key; use environment variables or secure key management systems.
Refer to the Examples Directory for sample code demonstrating how to use various modules of the SDK.
Example: Creating a Deployment
const { SpheronSDK } = require("@spheron/protocol-sdk");
const sdk = new SpheronSDK("testnet", "your-private-key");
const iclYaml = `
// Your YAML file here
`;
const providerProxyUrl = "http://localhost:3040";
(async () => {
try {
const deploymentTxn = await sdk.deployment.createDeployment(
iclYaml,
providerProxyUrl
);
console.log("Deployment created:", deploymentTxn);
} catch (error) {
console.error("Error creating deployment:", error);
}
})();
- Private Key Management: Store your private key securely using environment variables or secret management services like AWS Secrets Manager, Azure Key Vault, etc.
- Avoid Hardcoding Sensitive Data: Never commit sensitive information like private keys or API keys to version control.
- Fork the Repository: Click the “Fork” button at the top of the repository page.
- Create a Feature Branch: Use a descriptive name, e.g., feature/add-new-module.
- Make Changes: Commit your changes with clear and concise commit messages.
- Run Tests: Ensure all tests pass by running npm test.
- Submit a Pull Request: Open a pull request against the main branch with a detailed description of your changes.
- Code Style: Follow the established coding style in the project.
- Linting: Run
npm run lint
to check for linting errors. - Testing: Include unit tests for new features and ensure existing tests pass.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For any questions or inquiries, please contact us in our Discord.