@epicchain/bs-electron
v1.0.0
Published
`@epicchain/bs-electron` is a specialized package aimed at optimizing communication between the **main** and **renderer** processes within **Electron** applications. It provides a robust and flexible set of **APIs** that allow seamless integration of **bl
Readme
@epicchain/bs-electron
Overview
@epicchain/bs-electron is a specialized package aimed at optimizing communication between the main and renderer processes within Electron applications. It provides a robust and flexible set of APIs that allow seamless integration of blockchain services into desktop apps. The package is specifically tailored for developers looking to embed blockchain interactions into their Electron-based desktop applications while delivering a native-like experience. This allows developers to create decentralized desktop applications that interact with blockchain networks in a secure, optimized, and user-friendly manner.
The package ensures that the performance and responsiveness of blockchain operations within the Electron app are top-notch, without compromising the core features and functionality of the underlying blockchain technology. The integration of blockchain services into desktop apps has never been easier, enabling real-time blockchain interactions like transactions, smart contract calls, token transfers, and much more within the native desktop environment.
Key Features
Efficient Communication Between Main and Renderer Process: Seamlessly connects the Electron main process with the renderer process, ensuring smooth inter-process communication (IPC). This facilitates real-time blockchain operations within the renderer process without interrupting the main application flow.
Blockchain Integration: Simplifies the integration of blockchain services such as smart contract interactions, wallet management, transaction processing, and decentralized application (dApp) functionalities. This can be extended to support any blockchain platform that requires integration into Electron apps.
Native-Like Experience: Embeds blockchain interactions into Electron apps with native-like performance. The user interface (UI) and overall app behavior resemble the behavior of native desktop applications, making it intuitive and accessible for users.
Optimized for Performance: Handles the communication between processes in an optimized manner, ensuring low-latency communication, efficient data transfer, and fast response times for blockchain actions.
Comprehensive Blockchain Actions: Offers a set of predefined actions that cover common blockchain functionalities such as transaction sending, token transfers, balance checking, smart contract execution, and more.
Easy-to-Use API: The API is designed to be as simple as possible to use, reducing the complexity of integrating blockchain features into Electron apps. Developers can focus on building their application while leveraging blockchain capabilities effortlessly.
Cross-Platform Support: The package supports both Windows and macOS platforms, ensuring that blockchain-powered desktop applications can be used by a wider audience without compatibility issues.
Security: Designed with a security-first mindset, ensuring that all blockchain interactions are conducted in a secure environment, minimizing the risks involved with blockchain transactions.
Real-Time Interaction: Leverages real-time interaction for blockchain operations, making it ideal for applications that require instant feedback, such as decentralized finance (DeFi) platforms, NFT marketplaces, and more.
Installation
You can easily install @epicchain/bs-electron into your Electron project using npm or yarn.
Using npm
npm install @epicchain/bs-electronUsing yarn
yarn add @epicchain/bs-electronOnce installed, you can start using the features and APIs that come with this package.
Basic Usage
The package integrates easily into your Electron project by enhancing the communication between the main and renderer processes and providing blockchain functionalities. Below is an example to help you get started.
Setting Up Blockchain Integration
Main Process (main.js)
The main process is responsible for controlling the lifecycle of your Electron app, initializing the blockchain service, and communicating with the renderer process. In this example, we set up a simple Blockchain service instance.
const { app, BrowserWindow } = require('electron');
const { BlockchainService } = require('@epicchain/bs-electron');
let mainWindow;
app.on('ready', () => {
// Create an instance of the BlockchainService
const blockchainService = new BlockchainService();
// Initialize the blockchain service
blockchainService.initialize()
.then(() => {
console.log('Blockchain Service Initialized');
})
.catch((error) => {
console.error('Error initializing Blockchain Service', error);
});
// Create the Electron browser window
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
// Load the HTML file for the renderer process
mainWindow.loadURL('index.html');
});Renderer Process (renderer.js)
The renderer process is responsible for interacting with the user and handling all the user interface elements. In this case, it will communicate with the main process to request blockchain actions and handle the results.
const { ipcRenderer } = require('electron');
const { BlockchainService } = require('@epicchain/bs-electron');
// Handle blockchain action requests
ipcRenderer.on('blockchainAction', (event, actionData) => {
const blockchainService = new BlockchainService();
// Execute the blockchain action (e.g., sending a transaction)
blockchainService.executeAction(actionData).then(result => {
// Send the result back to the main process
event.sender.send('blockchainActionResult', result);
}).catch((error) => {
console.error('Error executing blockchain action', error);
event.sender.send('blockchainActionResult', { error: 'Error executing action' });
});
});Renderer-to-Main Communication
The renderer process can send a request to the main process for performing blockchain-related tasks, such as sending a transaction, querying blockchain data, or calling a smart contract.
// Sending a blockchain action to the main process
ipcRenderer.send('blockchainAction', {
action: 'sendTransaction',
data: {
from: 'address1',
to: 'address2',
amount: 100,
token: 'XPR'
}
});Main-to-Renderer Communication
The result of the blockchain action is then sent back from the main process to the renderer process for further use, such as updating the UI.
ipcRenderer.on('blockchainActionResult', (event, result) => {
if (result.error) {
console.error('Blockchain Action Failed', result.error);
} else {
console.log('Blockchain Action Result:', result);
}
});API Documentation
BlockchainService
The core class provided by @epicchain/bs-electron for interacting with blockchain services.
Methods
initialize(): Initializes the blockchain service and prepares it for interaction.Returns:
Promise<void>executeAction(data): Executes a blockchain action, such as sending a transaction or interacting with a smart contract.Parameters:
data(Object): An object containing the necessary data for the blockchain action (e.g., transaction details, smart contract interaction data).
Returns:
Promise<Object>- The result of the blockchain action.
BlockchainAction Events
blockchainAction: Event triggered by the renderer process to request a blockchain action.blockchainActionResult: Event sent back from the main process to the renderer process with the result of the blockchain action.
Example Projects
We encourage you to explore the following example projects where this package has been used to build blockchain-powered Electron applications:
- DeFi Desktop App - A decentralized finance app allowing users to manage their assets and perform blockchain transactions.
- NFT Marketplace - A desktop marketplace for buying and selling NFTs with integrated blockchain transactions.
- Blockchain Wallet - A secure desktop wallet for storing and sending cryptocurrencies and tokens.
Contributing
We welcome contributions from the community! If you'd like to contribute to the development of @epicchain/bs-electron, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes with a descriptive message.
- Submit a pull request with a clear explanation of what you’ve changed.
We encourage you to write tests and ensure that your changes don't break any existing functionality. Contributions that improve documentation, performance, or usability are highly appreciated.
License
@epicchain/bs-electron is licensed under the MIT License. You are free to use, modify, and distribute the package as per the terms of the MIT License.
Contact
For support, inquiries, or feedback, feel free to contact us at:
- Email: [email protected]
- Website: https://epic-chain.org
